223 lines
6.2 KiB
TypeScript
223 lines
6.2 KiB
TypeScript
/*
|
|
* Verrückte Turing-Maschinen — A turing complete game
|
|
* Copyright (C) 2016-2018 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(handler : (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) =>
|
|
{
|
|
let task : mod_model.mod_task.type_task = mod_model.mod_task.import_(task_raw);
|
|
// Aufgabe registrieren
|
|
{
|
|
mod_model.mod_task.registrieren(task);
|
|
}
|
|
// Option eintragen
|
|
{
|
|
let prefix : string = (
|
|
{
|
|
"acceptor": lib_translate.get("model.tasks.kinds.acceptor.shortcut"),
|
|
"transducer": lib_translate.get("model.tasks.kinds.transducer.shortcut"),
|
|
}[task_raw["kind"]]
|
|
);
|
|
let title : string = ("[" + prefix + "]" + " " + mod_model.mod_task.title(task));
|
|
let value : string = index.toFixed(0);
|
|
let dom_option : Element = document.createElement("option");
|
|
dom_option.setAttribute("value", value);
|
|
dom_option.textContent = title;
|
|
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);
|
|
handler(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 from_x : float = -0.5;
|
|
let from_y : float = -0.5;
|
|
let to_x : float = +0.5;
|
|
let to_y : float = +0.5;
|
|
let width : float = 80;
|
|
let height : float = 80;
|
|
[
|
|
{
|
|
"model": mod_model.mod_actuator.example("generator"),
|
|
"area": document.querySelector("#help_actuators_actuator_generator"),
|
|
},
|
|
{
|
|
"model": mod_model.mod_actuator.example("acceptor"),
|
|
"area": document.querySelector("#help_actuators_actuator_acceptor"),
|
|
},
|
|
{
|
|
"model": mod_model.mod_actuator.example("rejector"),
|
|
"area": document.querySelector("#help_actuators_actuator_rejector"),
|
|
},
|
|
{
|
|
"model": mod_model.mod_actuator.example("conveyer"),
|
|
"area": document.querySelector("#help_actuators_actuator_conveyer"),
|
|
},
|
|
{
|
|
"model": mod_model.mod_actuator.example("writer"),
|
|
"area": document.querySelector("#help_actuators_actuator_writer"),
|
|
},
|
|
{
|
|
"model": mod_model.mod_actuator.example("reader"),
|
|
"area": document.querySelector("#help_actuators_actuator_reader"),
|
|
},
|
|
]
|
|
.forEach
|
|
(
|
|
entry =>
|
|
{
|
|
let manifestation = (
|
|
mod_manifestation.mod_svg.mod_actuator.create_extended
|
|
(
|
|
entry.model,
|
|
mod_model.mod_spot.null_()
|
|
)
|
|
);
|
|
let xmlnode : lib_xml.type_node = (
|
|
lib_svg.root
|
|
(
|
|
from_x, from_y,
|
|
to_x, to_y,
|
|
width, height,
|
|
[mod_manifestation.view(manifestation)]
|
|
)
|
|
);
|
|
entry.area.querySelector(".help_actuators_actuator_image").innerHTML = lib_xml.view(xmlnode);
|
|
}
|
|
)
|
|
;
|
|
}
|
|
}
|
|
}
|
|
// Spiel
|
|
{
|
|
let game : mod_model.mod_game.type_game;
|
|
// Aufgaben
|
|
{
|
|
tasks_insert
|
|
(
|
|
function (task : mod_model.mod_task.type_task) : void {mod_model.mod_game.task_set(game, task);}
|
|
)
|
|
;
|
|
}
|
|
// Aufbau
|
|
{
|
|
game = mod_model.mod_game.create(mod_model.mod_task.get(0));
|
|
}
|
|
// Manifestationen
|
|
{
|
|
[
|
|
mod_manifestation.mod_web.mod_game.create_extended
|
|
(
|
|
game,
|
|
document.querySelector("#section_mid")
|
|
)
|
|
,
|
|
mod_manifestation.mod_store.mod_game.create_extended
|
|
(
|
|
game
|
|
)
|
|
,
|
|
]
|
|
.forEach(mod_manifestation.setup);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function entry_web() : void
|
|
{
|
|
document.addEventListener
|
|
(
|
|
"DOMContentLoaded",
|
|
event => {main();}
|
|
)
|
|
;
|
|
}
|
|
|
|
}
|
|
|