vtm/source/main.ts

223 lines
6.2 KiB
TypeScript
Raw Normal View History

2017-11-09 14:06:35 +01:00
/*
* Verrückte Turing-Maschinen A turing complete game
2018-03-29 22:00:42 +02:00
* Copyright (C) 2016-2018 kcf <vidofnir@folksprak.org>
2017-11-09 14:06:35 +01:00
*
* 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
2018-03-26 14:22:20 +02:00
module mod_vtm
2017-11-08 18:41:56 +01:00
{
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-29 01:13:39 +02:00
function tasks_insert(handler : (task : mod_model.mod_task.type_task)=>void) : void
2017-11-08 18:41:56 +01:00
{
2018-03-28 13:59:29 +02:00
let tasks_raw_ : lib_errormonade.type_errormonade<Array<any>> = mod_vtm.mod_data.read("tasks");
if (lib_errormonade.filled(tasks_raw_))
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
let tasks_raw : Array<any> = lib_errormonade.read(tasks_raw_);
let dom_selection : Element = document.querySelector("#task_selection");
tasks_raw.forEach
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
(task_raw, index) =>
2018-03-26 14:22:20 +02:00
{
2018-03-29 01:13:39 +02:00
let task : mod_model.mod_task.type_task = mod_model.mod_task.import_(task_raw);
2018-03-26 14:22:20 +02:00
// Aufgabe registrieren
2017-11-09 21:57:35 +01:00
{
2018-03-28 13:59:29 +02:00
mod_model.mod_task.registrieren(task);
2018-03-26 14:22:20 +02:00
}
2018-03-30 01:06:13 +02:00
// Option entryen
2018-03-26 14:22:20 +02:00
{
2018-03-29 01:13:39 +02:00
let prefix : string = (
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
"acceptor": lib_translate.get("model.tasks.kinds.acceptor.shortcut"),
2018-03-29 01:13:39 +02:00
"transducer": lib_translate.get("model.tasks.kinds.transducer.shortcut"),
2018-03-28 13:59:29 +02:00
}[task_raw["kind"]]
2018-03-26 14:22:20 +02:00
);
2018-03-29 01:13:39 +02:00
let title : string = ("[" + prefix + "]" + " " + mod_model.mod_task.title(task));
2018-03-26 14:22:20 +02:00
let value : string = index.toFixed(0);
let dom_option : Element = document.createElement("option");
dom_option.setAttribute("value", value);
2018-03-29 01:13:39 +02:00
dom_option.textContent = title;
2018-03-28 13:59:29 +02:00
dom_selection.appendChild(dom_option);
2018-03-26 14:22:20 +02:00
}
}
)
;
2018-03-28 13:59:29 +02:00
dom_selection.addEventListener
2018-03-26 14:22:20 +02:00
(
"change",
event =>
{
2018-03-28 13:59:29 +02:00
let value : string = dom_selection["value"];
2018-03-26 14:22:20 +02:00
let index : int = parseInt(value);
2018-03-28 13:59:29 +02:00
let task : mod_model.mod_task.type_task = mod_model.mod_task.get(index);
2018-03-29 01:13:39 +02:00
handler(task);
2018-03-26 14:22:20 +02:00
}
)
;
}
else
{
console.warn("Daten nicht auffindbar");
}
2017-11-08 18:41:56 +01:00
}
2017-11-09 14:06:35 +01:00
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
function main() : void
2018-03-20 13:30:00 +01:00
{
2018-03-26 14:22:20 +02:00
// Übersetzungen
2018-03-20 13:30:00 +01:00
{
2018-03-30 11:34:41 +02:00
let languages : Array<string> = lib_list.copy<string>(navigator.languages);
2018-03-29 22:00:42 +02:00
let language_native : string = "de";
if (! languages[""+"includes"](language_native))
languages.push(language_native);
2018-03-28 13:59:29 +02:00
lib_translate.setup(languages);
lib_translate.deploy(document);
2018-03-26 14:22:20 +02:00
}
// Hilfe
{
// Einleitung
{
2018-03-28 13:59:29 +02:00
document.querySelector("#help_introduction").innerHTML = (
lib_translate.get
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
"help.introduction",
2018-03-26 14:22:20 +02:00
{
"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
2018-03-20 13:30:00 +01:00
{
2018-03-29 01:13:39 +02:00
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;
2018-03-26 14:22:20 +02:00
[
{
2018-03-29 01:13:39 +02:00
"model": mod_model.mod_actuator.example("generator"),
"area": document.querySelector("#help_actuators_actuator_generator"),
2018-03-26 14:22:20 +02:00
},
2018-03-20 13:30:00 +01:00
{
2018-03-29 01:13:39 +02:00
"model": mod_model.mod_actuator.example("acceptor"),
"area": document.querySelector("#help_actuators_actuator_acceptor"),
2018-03-26 14:22:20 +02:00
},
{
2018-03-29 01:13:39 +02:00
"model": mod_model.mod_actuator.example("rejector"),
"area": document.querySelector("#help_actuators_actuator_rejector"),
2018-03-26 14:22:20 +02:00
},
{
2018-03-29 01:13:39 +02:00
"model": mod_model.mod_actuator.example("conveyer"),
"area": document.querySelector("#help_actuators_actuator_conveyer"),
2018-03-26 14:22:20 +02:00
},
{
2018-03-29 01:13:39 +02:00
"model": mod_model.mod_actuator.example("writer"),
"area": document.querySelector("#help_actuators_actuator_writer"),
2018-03-26 14:22:20 +02:00
},
{
2018-03-29 01:13:39 +02:00
"model": mod_model.mod_actuator.example("reader"),
"area": document.querySelector("#help_actuators_actuator_reader"),
2018-03-26 14:22:20 +02:00
},
]
.forEach
(
2018-03-29 01:13:39 +02:00
entry =>
2018-03-26 14:22:20 +02:00
{
2018-03-26 22:32:10 +02:00
let manifestation = (
2018-03-29 01:13:39 +02:00
mod_manifestation.mod_svg.mod_actuator.create_extended
2018-03-26 14:22:20 +02:00
(
2018-03-29 01:13:39 +02:00
entry.model,
2018-03-28 13:59:29 +02:00
mod_model.mod_spot.null_()
2018-03-26 14:22:20 +02:00
)
);
2018-03-28 13:59:29 +02:00
let xmlnode : lib_xml.type_node = (
2018-03-29 01:13:39 +02:00
lib_svg.root
2018-03-26 14:22:20 +02:00
(
2018-03-29 01:13:39 +02:00
from_x, from_y,
to_x, to_y,
width, height,
2018-03-28 13:59:29 +02:00
[mod_manifestation.view(manifestation)]
2018-03-26 14:22:20 +02:00
)
);
2018-03-29 01:13:39 +02:00
entry.area.querySelector(".help_actuators_actuator_image").innerHTML = lib_xml.view(xmlnode);
2018-03-26 14:22:20 +02:00
}
)
;
}
}
}
// Spiel
{
2018-03-29 01:13:39 +02:00
let game : mod_model.mod_game.type_game;
2018-03-26 14:22:20 +02:00
// Aufgaben
{
2018-03-28 13:59:29 +02:00
tasks_insert
2018-03-26 14:22:20 +02:00
(
2018-03-29 01:13:39 +02:00
function (task : mod_model.mod_task.type_task) : void {mod_model.mod_game.task_set(game, task);}
2018-03-26 14:22:20 +02:00
)
;
2018-03-26 22:32:10 +02:00
}
// Aufbau
{
2018-03-29 01:13:39 +02:00
game = mod_model.mod_game.create(mod_model.mod_task.get(0));
2018-03-26 14:22:20 +02:00
}
2018-03-26 22:32:10 +02:00
// Manifestationen
2018-03-26 14:22:20 +02:00
{
2018-03-26 22:32:10 +02:00
[
2018-03-29 01:13:39 +02:00
mod_manifestation.mod_web.mod_game.create_extended
2018-03-26 22:32:10 +02:00
(
2018-03-29 01:13:39 +02:00
game,
2018-03-28 13:59:29 +02:00
document.querySelector("#section_mid")
2018-03-26 22:32:10 +02:00
)
,
2018-03-29 01:13:39 +02:00
mod_manifestation.mod_store.mod_game.create_extended
2018-03-26 22:32:10 +02:00
(
2018-03-29 01:13:39 +02:00
game
2018-03-26 22:32:10 +02:00
)
,
]
2018-03-28 13:59:29 +02:00
.forEach(mod_manifestation.setup);
2018-03-26 14:22:20 +02:00
}
2018-03-20 13:30:00 +01:00
}
}
2017-11-08 18:41:56 +01:00
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export function entry_web() : void
2018-03-26 14:22:20 +02:00
{
document.addEventListener
(
"DOMContentLoaded",
2018-03-28 13:59:29 +02:00
event => {main();}
2018-03-26 14:22:20 +02:00
)
;
}
2017-11-08 18:41:56 +01:00
}