223 lines
6.3 KiB
TypeScript
223 lines
6.3 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 tasks_insert(behandler : (task : mod_model.mod_task.type_task)=>void) : void
|
|
{
|
|
let tasks_raw_ : lib_errormonade.type_errormonade<Array<any>> = mod_vtm.mod_data.read("tasks");
|
|
if (lib_errormonade.filled(tasks_raw_))
|
|
{
|
|
let tasks_raw : Array<any> = lib_errormonade.read(tasks_raw_);
|
|
let dom_selection : Element = document.querySelector("#task_selection");
|
|
tasks_raw.forEach
|
|
(
|
|
(task_raw, index) =>
|
|
{
|
|
// Aufgabe registrieren
|
|
{
|
|
let task : mod_model.mod_task.type_task = mod_model.mod_task.import_(task_raw);
|
|
mod_model.mod_task.registrieren(task);
|
|
}
|
|
// Option insert
|
|
{
|
|
let praefix : string = (
|
|
{
|
|
"acceptor": lib_translate.get("model.tasks.kinds.acceptor.shortcut"),
|
|
"transductor": lib_translate.get("model.tasks.kinds.transductor.shortcut"),
|
|
}[task_raw["kind"]]
|
|
);
|
|
let titel : string = ("[" + praefix + "]" + " " + task_raw["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_selection.appendChild(dom_option);
|
|
}
|
|
}
|
|
)
|
|
;
|
|
dom_selection.addEventListener
|
|
(
|
|
"change",
|
|
event =>
|
|
{
|
|
let value : string = dom_selection["value"];
|
|
let index : int = parseInt(value);
|
|
let task : mod_model.mod_task.type_task = mod_model.mod_task.get(index);
|
|
behandler(task);
|
|
}
|
|
)
|
|
;
|
|
}
|
|
else
|
|
{
|
|
console.warn("Daten nicht auffindbar");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function main() : void
|
|
{
|
|
// Übersetzungen
|
|
{
|
|
let languages : Array<string> = navigator.languages.map(language => language);
|
|
let language_nativ : string = "de";
|
|
if (! languages[""+"includes"](language_nativ))
|
|
languages.push(language_nativ);
|
|
lib_translate.setup(languages);
|
|
lib_translate.deploy(document);
|
|
}
|
|
// Hilfe
|
|
{
|
|
// Einleitung
|
|
{
|
|
document.querySelector("#help_introduction").innerHTML = (
|
|
lib_translate.get
|
|
(
|
|
"help.introduction",
|
|
{
|
|
"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;
|
|
[
|
|
{
|
|
"model": mod_model.mod_actuator.example("erzeuger"),
|
|
"bereich": document.querySelector("#help_actuators_actuator_erzeuger"),
|
|
},
|
|
{
|
|
"model": mod_model.mod_actuator.example("annehmer"),
|
|
"bereich": document.querySelector("#help_actuators_actuator_annehmer"),
|
|
},
|
|
{
|
|
"model": mod_model.mod_actuator.example("verwerfer"),
|
|
"bereich": document.querySelector("#help_actuators_actuator_verwerfer"),
|
|
},
|
|
{
|
|
"model": mod_model.mod_actuator.example("befoerderer"),
|
|
"bereich": document.querySelector("#help_actuators_actuator_befoerderer"),
|
|
},
|
|
{
|
|
"model": mod_model.mod_actuator.example("schreiber"),
|
|
"bereich": document.querySelector("#help_actuators_actuator_schreiber"),
|
|
},
|
|
{
|
|
"model": mod_model.mod_actuator.example("leser"),
|
|
"bereich": document.querySelector("#help_actuators_actuator_leser"),
|
|
},
|
|
]
|
|
.forEach
|
|
(
|
|
eintrag =>
|
|
{
|
|
let manifestation = (
|
|
mod_manifestation.mod_svg.mod_actuator.create_manifestation
|
|
(
|
|
eintrag.model,
|
|
mod_model.mod_spot.null_()
|
|
)
|
|
);
|
|
let xmlnode : lib_xml.type_node = (
|
|
mod_manifestation.mod_svg.root
|
|
(
|
|
von_x, von_y,
|
|
bis_x, bis_y,
|
|
breite, hoehe,
|
|
[mod_manifestation.view(manifestation)]
|
|
)
|
|
);
|
|
eintrag.bereich.querySelector(".help_actuators_actuator_image").innerHTML = lib_xml.view(xmlnode);
|
|
}
|
|
)
|
|
;
|
|
}
|
|
}
|
|
}
|
|
// Spiel
|
|
{
|
|
let round : mod_model.mod_round.type_round;
|
|
// Aufgaben
|
|
{
|
|
tasks_insert
|
|
(
|
|
function (task : mod_model.mod_task.type_task) : void {mod_model.mod_round.task_set(round, task);}
|
|
)
|
|
;
|
|
}
|
|
// Aufbau
|
|
{
|
|
round = mod_model.mod_round.create(mod_model.mod_task.get(0));
|
|
}
|
|
// Manifestationen
|
|
{
|
|
[
|
|
mod_manifestation.mod_web.mod_round.create_erweitert
|
|
(
|
|
round,
|
|
document.querySelector("#section_mid")
|
|
)
|
|
,
|
|
mod_manifestation.mod_store.mod_round.create_erweitert
|
|
(
|
|
round
|
|
)
|
|
,
|
|
]
|
|
.forEach(mod_manifestation.setup);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function entry_web() : void
|
|
{
|
|
document.addEventListener
|
|
(
|
|
"DOMContentLoaded",
|
|
event => {main();}
|
|
)
|
|
;
|
|
}
|
|
|
|
}
|
|
|