vtm/quelldatein/haupt.ts

182 lines
5.4 KiB
TypeScript
Raw Normal View History

2017-11-09 14:06:35 +01:00
/*
* 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/>.
*/
2017-11-08 18:41:56 +01:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2017-11-09 18:42:09 +01:00
function aufgaben_eintragen(behandler : (aufgabe : mod_vtm_aufbau.schnittstelle_aufgabe)=>void) : void
2017-11-08 18:41:56 +01:00
{
2017-11-09 14:06:35 +01:00
let aufgaben_roh_ : schnittstelle_fehlermonade<Array<any>> = mod_vtm_daten.lesen("aufgaben");
if (aufgaben_roh_.ist_schlicht())
2017-11-08 18:41:56 +01:00
{
2017-11-09 14:06:35 +01:00
let aufgaben_roh : Array<any> = aufgaben_roh_.lesen();
let dom_auswahl : Element = document.querySelector("#aufgabe_auswahl");
aufgaben_roh.forEach
2017-11-08 18:41:56 +01:00
(
2017-11-09 14:06:35 +01:00
(aufgabe_roh, index) =>
{
2017-11-09 18:42:09 +01:00
// Aufgabe registrieren
{
let aufgabe : mod_vtm_aufbau.schnittstelle_aufgabe = mod_vtm_aufbau.aufgabe_erstellen(aufgabe_roh);
mod_vtm_aufbau.aufgabe_registrieren(aufgabe);
}
// Option eintragen
{
2017-11-09 21:57:35 +01:00
let praefix : string = (
{
"akzeptor": "AKZ",
"transduktor": "TRA",
}[aufgabe_roh["art"]]
);
let titel : string = ("[" + praefix + "]" + " " + aufgabe_roh["parameter"]["titel"]);
2017-11-09 18:42:09 +01:00
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);
}
2017-11-09 14:06:35 +01:00
}
2017-11-08 18:41:56 +01:00
)
;
2017-11-09 14:06:35 +01:00
dom_auswahl.addEventListener
(
"change",
event =>
{
2017-11-09 18:42:09 +01:00
let value : string = dom_auswahl["value"];
let index : int = parseInt(value);
let aufgabe : mod_vtm_aufbau.schnittstelle_aufgabe = mod_vtm_aufbau.aufgabe_holen(index);
2017-11-09 14:06:35 +01:00
behandler(aufgabe);
}
)
;
}
else
{
console.warn("Daten nicht auffindbar");
2017-11-08 18:41:56 +01:00
}
2017-11-09 14:06:35 +01:00
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function haupt() : void
{
2018-03-20 13:30:00 +01:00
// uebersetzungen
{
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_helfer.uebersetzung_einrichten(sprachen);
mod_vtm_helfer.uebersetzung_anwenden(document);
}
// hilfe
{
// einleitung
{
document.querySelector("#hilfe_einleitung").innerHTML = (
mod_vtm_helfer.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": (new mod_vtm_aufbau.klasse_erzeuger()),
"kontext": document.querySelector("#hilfe_aktoren_aktor_erzeuger"),
},
{
"aufbau": (new mod_vtm_aufbau.klasse_annehmer()),
"kontext": document.querySelector("#hilfe_aktoren_aktor_annehmer"),
},
{
"aufbau": (new mod_vtm_aufbau.klasse_verwerfer()),
"kontext": document.querySelector("#hilfe_aktoren_aktor_verwerfer"),
},
{
"aufbau": (new mod_vtm_aufbau.klasse_befoerderer()),
"kontext": document.querySelector("#hilfe_aktoren_aktor_befoerderer"),
},
{
"aufbau": (new mod_vtm_aufbau.klasse_schreiber()),
"kontext": document.querySelector("#hilfe_aktoren_aktor_schreiber"),
},
{
"aufbau": (new mod_vtm_aufbau.klasse_leser()),
"kontext": document.querySelector("#hilfe_aktoren_aktor_leser"),
},
]
.forEach
(
eintrag =>
{
let manifestor = (new mod_vtm_manifestation.klasse_svg_aktor(eintrag.aufbau, mod_vtm_aufbau.stelle_null()));
let xmlknoten : mod_vtm_helfer.schnittstelle_xmlknoten = mod_vtm_manifestation.svg_wurzel(von_x, von_y, bis_x, bis_y, breite, hoehe, [manifestor.darstellen()]);
eintrag.kontext.querySelector(".hilfe_aktoren_aktor_bild").innerHTML = xmlknoten.darstellen();
}
)
;
}
}
}
// spiel
{
let aufbau : mod_vtm_aufbau.klasse_partie;
aufgaben_eintragen
(
function (aufgabe : mod_vtm_aufbau.schnittstelle_aufgabe) : void {aufbau.aufgabe_setzen(aufgabe);}
)
;
aufbau = (new mod_vtm_aufbau.klasse_partie(mod_vtm_aufbau.aufgabe_holen(0)));
(new mod_vtm_manifestation.klasse_web_partie(aufbau, document.querySelector("#bereich_mitte"))).einrichten();
}
2017-11-08 18:41:56 +01:00
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function eingang_web() : void
{
document.addEventListener
(
"DOMContentLoaded",
event => {haupt();}
)
;
}