/* * Verrückte Turing-Maschinen — A turing complete game * Copyright (C) 2016 Christian Fraß * * 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 . */ /** * @author kcf */ function aufgaben_eintragen(behandler : (aufgabe : mod_vtm_aufbau.schnittstelle_aufgabe)=>void) : void { let aufgaben_roh_ : schnittstelle_fehlermonade> = mod_vtm_daten.lesen("aufgaben"); if (aufgaben_roh_.ist_schlicht()) { let aufgaben_roh : Array = aufgaben_roh_.lesen(); let dom_auswahl : Element = document.querySelector("#aufgabe_auswahl"); aufgaben_roh.forEach ( (aufgabe_roh, index) => { // Aufgabe registrieren { let aufgabe : mod_vtm_aufbau.schnittstelle_aufgabe = mod_vtm_aufbau.aufgabe_erstellen(aufgabe_roh); mod_vtm_aufbau.aufgabe_registrieren(aufgabe); } // Option eintragen { let praefix : string = ( { "akzeptor": mod_vtm_helfer.uebersetzung_holen("aufbau.aufgaben.arten.akzeptor.kuerzel"), "transduktor": mod_vtm_helfer.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_vtm_aufbau.schnittstelle_aufgabe = mod_vtm_aufbau.aufgabe_holen(index); behandler(aufgabe); } ) ; } else { console.warn("Daten nicht auffindbar"); } } /** * @author kcf */ function haupt() : void { // Übersetzungen { let sprachen : Array = 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": "Manufacturia", "crazy_machines": "Crazy Machines", "world_of_goo": "World of Goo", } ) ); } // 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_vtm_aufbau.aktor_erstellen("erzeuger"), "bereich": document.querySelector("#hilfe_aktoren_aktor_erzeuger"), }, { "aufbau": mod_vtm_aufbau.aktor_erstellen("annehmer"), "bereich": document.querySelector("#hilfe_aktoren_aktor_annehmer"), }, { "aufbau": mod_vtm_aufbau.aktor_erstellen("verwerfer"), "bereich": document.querySelector("#hilfe_aktoren_aktor_verwerfer"), }, { "aufbau": mod_vtm_aufbau.aktor_erstellen("befoerderer"), "bereich": document.querySelector("#hilfe_aktoren_aktor_befoerderer"), }, { "aufbau": mod_vtm_aufbau.aktor_erstellen("schreiber"), "bereich": document.querySelector("#hilfe_aktoren_aktor_schreiber"), }, { "aufbau": mod_vtm_aufbau.aktor_erstellen("leser"), "bereich": 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.bereich.querySelector(".hilfe_aktoren_aktor_bild").innerHTML = xmlknoten.darstellen(); } ) ; } } } // Spiel { let aufbau : mod_vtm_aufbau.typ_partie; aufgaben_eintragen ( function (aufgabe : mod_vtm_aufbau.schnittstelle_aufgabe) : void {mod_vtm_aufbau.partie_aufgabe_setzen(aufbau, aufgabe);} ) ; aufbau = mod_vtm_aufbau.partie_erstellen(mod_vtm_aufbau.aufgabe_holen(0)); (new mod_vtm_manifestation.klasse_web_partie(aufbau, document.querySelector("#bereich_mitte"))).einrichten(); (new mod_vtm_manifestation.klasse_speicher_partie(aufbau)).einrichten(); } } /** * @author kcf */ function eingang_web() : void { document.addEventListener ( "DOMContentLoaded", event => {haupt();} ) ; }