vtm/quelldatein/haupt.ts
2018-03-26 22:32:10 +02:00

223 lines
6.5 KiB
TypeScript

/*
* Verrückte Turing-Maschinen — A turing complete game
* Copyright (C) 2016 Christian Fraß <vidofnir@folksprak.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
module mod_vtm
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
function aufgaben_eintragen(behandler : (aufgabe : mod_aufbau.mod_aufgabe.typ_aufgabe)=>void) : void
{
let aufgaben_roh_ : schnittstelle_fehlermonade<Array<any>> = mod_vtm_daten.lesen("aufgaben");
if (aufgaben_roh_.ist_schlicht())
{
let aufgaben_roh : Array<any> = aufgaben_roh_.lesen();
let dom_auswahl : Element = document.querySelector("#aufgabe_auswahl");
aufgaben_roh.forEach
(
(aufgabe_roh, index) =>
{
// Aufgabe registrieren
{
let aufgabe : mod_aufbau.mod_aufgabe.typ_aufgabe = mod_aufbau.mod_aufgabe.importieren(aufgabe_roh);
mod_aufbau.mod_aufgabe.registrieren(aufgabe);
}
// Option eintragen
{
let praefix : string = (
{
"akzeptor": mod_vtm.mod_helfer.mod_uebersetzung.holen("aufbau.aufgaben.arten.akzeptor.kuerzel"),
"transduktor": mod_vtm.mod_helfer.mod_uebersetzung.holen("aufbau.aufgaben.arten.transduktor.kuerzel"),
}[aufgabe_roh["art"]]
);
let titel : string = ("[" + praefix + "]" + " " + aufgabe_roh["parameter"]["titel"]);
let value : string = index.toFixed(0);
let dom_option : Element = document.createElement("option");
dom_option.setAttribute("value", value);
dom_option.textContent = titel;
dom_auswahl.appendChild(dom_option);
}
}
)
;
dom_auswahl.addEventListener
(
"change",
event =>
{
let value : string = dom_auswahl["value"];
let index : int = parseInt(value);
let aufgabe : mod_aufbau.mod_aufgabe.typ_aufgabe = mod_aufbau.mod_aufgabe.holen(index);
behandler(aufgabe);
}
)
;
}
else
{
console.warn("Daten nicht auffindbar");
}
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function haupt() : void
{
// Übersetzungen
{
let sprachen : Array<string> = navigator.languages.map(sprache => sprache);
let sprache_nativ : string = "de";
if (! sprachen[""+"includes"](sprache_nativ))
sprachen.push(sprache_nativ);
mod_vtm.mod_helfer.mod_uebersetzung.einrichten(sprachen);
mod_vtm.mod_helfer.mod_uebersetzung.anwenden(document);
}
// Hilfe
{
// Einleitung
{
document.querySelector("#hilfe_einleitung").innerHTML = (
mod_vtm.mod_helfer.mod_uebersetzung.holen
(
"hilfe.einleitung",
{
"manufacturia": "<a href=\"http://www.kongregate.com/games/PleasingFungus/manufactoria\">Manufacturia</a>",
"crazy_machines": "<a href=\"http://www.crazy-machines.com/\">Crazy Machines</a>",
"world_of_goo": "<a href=\"http://worldofgoo.com/\">World of Goo</a>",
}
)
);
}
// Aktoren
{
// Arten
{
let von_x : float = -0.5;
let von_y : float = -0.5;
let bis_x : float = +0.5;
let bis_y : float = +0.5;
let breite : float = 80;
let hoehe : float = 80;
[
{
"aufbau": mod_aufbau.mod_aktor.beispiel("erzeuger"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_erzeuger"),
},
{
"aufbau": mod_aufbau.mod_aktor.beispiel("annehmer"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_annehmer"),
},
{
"aufbau": mod_aufbau.mod_aktor.beispiel("verwerfer"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_verwerfer"),
},
{
"aufbau": mod_aufbau.mod_aktor.beispiel("befoerderer"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_befoerderer"),
},
{
"aufbau": mod_aufbau.mod_aktor.beispiel("schreiber"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_schreiber"),
},
{
"aufbau": mod_aufbau.mod_aktor.beispiel("leser"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_leser"),
},
]
.forEach
(
eintrag =>
{
let manifestation = (
mod_manifestation.mod_svg.mod_aktor.erstellen_manifestation
(
eintrag.aufbau,
mod_aufbau.mod_stelle.null_()
)
);
let xmlknoten : mod_vtm_helfer.typ_xmlknoten = (
mod_manifestation.mod_svg.wurzel
(
von_x, von_y,
bis_x, bis_y,
breite, hoehe,
[mod_manifestation.darstellen(manifestation)]
)
);
eintrag.bereich.querySelector(".hilfe_aktoren_aktor_bild").innerHTML = mod_vtm_helfer.xmlknoten_darstellen(xmlknoten);
}
)
;
}
}
}
// Spiel
{
let partie : mod_aufbau.mod_partie.typ_partie;
// Aufgaben
{
aufgaben_eintragen
(
function (aufgabe : mod_aufbau.mod_aufgabe.typ_aufgabe) : void {mod_aufbau.mod_partie.aufgabe_setzen(partie, aufgabe);}
)
;
}
// Aufbau
{
partie = mod_aufbau.mod_partie.erstellen(mod_aufbau.mod_aufgabe.holen(0));
}
// Manifestationen
{
[
mod_manifestation.mod_web.mod_partie.erstellen_erweitert
(
partie,
document.querySelector("#bereich_mitte")
)
,
mod_manifestation.mod_speicher.mod_partie.erstellen_erweitert
(
partie
)
,
]
.forEach(mod_manifestation.einrichten);
}
}
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function eingang_web() : void
{
document.addEventListener
(
"DOMContentLoaded",
event => {haupt();}
)
;
}
}