vtm/quelldatein/haupt.ts

213 lines
6.1 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>
*/
2018-03-26 00:41:10 +02:00
function aufgaben_eintragen(behandler : (aufgabe : mod_vtm_aufbau.typ_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
{
2018-03-26 00:41:10 +02:00
let aufgabe : mod_vtm_aufbau.typ_aufgabe = mod_vtm_aufbau.aufgabe_importieren(aufgabe_roh);
2017-11-09 18:42:09 +01:00
mod_vtm_aufbau.aufgabe_registrieren(aufgabe);
}
// Option eintragen
{
2017-11-09 21:57:35 +01:00
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"),
2017-11-09 21:57:35 +01:00
}[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);
2018-03-26 00:41:10 +02:00
let aufgabe : mod_vtm_aufbau.typ_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
{
// Übersetzungen
2018-03-20 13:30:00 +01:00
{
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
2018-03-20 13:30:00 +01:00
{
// Einleitung
2018-03-20 13:30:00 +01:00
{
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
2018-03-20 13:30:00 +01:00
{
// Arten
2018-03-20 13:30:00 +01:00
{
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;
[
{
2018-03-26 00:41:10 +02:00
"aufbau": mod_vtm_aufbau.aktor_beispiel("erzeuger"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_erzeuger"),
2018-03-20 13:30:00 +01:00
},
{
2018-03-26 00:41:10 +02:00
"aufbau": mod_vtm_aufbau.aktor_beispiel("annehmer"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_annehmer"),
2018-03-20 13:30:00 +01:00
},
{
2018-03-26 00:41:10 +02:00
"aufbau": mod_vtm_aufbau.aktor_beispiel("verwerfer"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_verwerfer"),
2018-03-20 13:30:00 +01:00
},
{
2018-03-26 00:41:10 +02:00
"aufbau": mod_vtm_aufbau.aktor_beispiel("befoerderer"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_befoerderer"),
2018-03-20 13:30:00 +01:00
},
{
2018-03-26 00:41:10 +02:00
"aufbau": mod_vtm_aufbau.aktor_beispiel("schreiber"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_schreiber"),
2018-03-20 13:30:00 +01:00
},
{
2018-03-26 00:41:10 +02:00
"aufbau": mod_vtm_aufbau.aktor_beispiel("leser"),
"bereich": document.querySelector("#hilfe_aktoren_aktor_leser"),
2018-03-20 13:30:00 +01:00
},
]
.forEach
(
eintrag =>
{
2018-03-26 00:41:10 +02:00
let manifestor = (
mod_vtm_manifestation.svg_aktor_erstellen_manifestation
(
eintrag.aufbau,
mod_vtm_aufbau.stelle_null()
)
);
let xmlknoten : mod_vtm_helfer.typ_xmlknoten = (
mod_vtm_manifestation.svg_wurzel
(
von_x, von_y,
bis_x, bis_y,
breite, hoehe,
[mod_vtm_manifestation.manifestation_darstellen(manifestor)]
)
);
eintrag.bereich.querySelector(".hilfe_aktoren_aktor_bild").innerHTML = mod_vtm_helfer.xmlknoten_darstellen(xmlknoten);
2018-03-20 13:30:00 +01:00
}
)
;
}
}
}
// Spiel
2018-03-20 13:30:00 +01:00
{
2018-03-26 00:41:10 +02:00
// let aufbau : mod_vtm_aufbau.typ_partie;
2018-03-20 13:30:00 +01:00
aufgaben_eintragen
(
2018-03-26 00:41:10 +02:00
function (aufgabe : mod_vtm_aufbau.typ_aufgabe) : void {mod_vtm_aufbau.partie_aufgabe_setzen(aufbau, aufgabe);}
2018-03-20 13:30:00 +01:00
)
;
aufbau = mod_vtm_aufbau.partie_erstellen(mod_vtm_aufbau.aufgabe_holen(0));
2018-03-26 00:41:10 +02:00
mod_vtm_manifestation.manifestation_einrichten
(
mod_vtm_manifestation.web_partie_erstellen_erweitert
(
aufbau,
document.querySelector("#bereich_mitte")
)
)
;
mod_vtm_manifestation.manifestation_einrichten
(
mod_vtm_manifestation.speicher_partie_erstellen_erweitert
(
aufbau
)
)
;
2018-03-20 13:30:00 +01:00
}
2017-11-08 18:41:56 +01:00
}
2018-03-26 00:41:10 +02:00
var aufbau : mod_vtm_aufbau.typ_partie = null;
2017-11-08 18:41:56 +01:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
function eingang_web() : void
{
document.addEventListener
(
"DOMContentLoaded",
event => {haupt();}
)
;
}