vtm/source/manifestation/svg/game.ts
Christian Fraß 95ff0c95b3 restructuring
2018-03-29 01:13:39 +02:00

170 lines
4.8 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
{
export module mod_manifestation
{
export module mod_svg
{
export module mod_game
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
export type type_game =
{
model : mod_vtm.mod_model.mod_game.type_game;
}
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
function create(model : mod_vtm.mod_model.mod_game.type_game) : type_game
{
return {
"model": model
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function create_extended(model : mod_vtm.mod_model.mod_game.type_game) : type_manifestation<mod_vtm.mod_model.mod_game.type_game>
{
return {
"kind": "svg_game",
"data": create(model)
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function view(game : type_game) : lib_xml.type_node
{
let children_game : Array<lib_xml.type_node> = [];
// Welt
{
let children_world : Array<lib_xml.type_node> = [];
// Felder
{
let children_tiles : Array<lib_xml.type_node> = [];
mod_vtm.mod_model.mod_world.tiles_read(mod_vtm.mod_model.mod_game.world_read(game.model)).forEach
(
({"spot": spot, "actuator": actuator}) =>
{
let manifestation_tile : type_manifestation<mod_vtm.mod_model.mod_actuator.type_actuator> = mod_actuator.create_extended(actuator, spot);
let node_tile : lib_xml.type_node = mod_manifestation.view(manifestation_tile);
children_tiles.push(node_tile);
}
)
;
let node_tiles : lib_xml.type_node = (
lib_xml.create_normal
(
"g",
{
"class": "tiles",
},
children_tiles
)
);
children_world.push(node_tiles);
}
let node_world : lib_xml.type_node = (
lib_xml.create_normal
(
"g",
{
"class": "world",
},
children_world
)
);
children_game.push(node_world);
}
// Figur
{
let token_ : lib_errormonade.type_errormonade<mod_vtm.mod_model.mod_token.type_token> = mod_vtm.mod_model.mod_game.token_read(game.model);
if (lib_errormonade.filled(token_))
{
let token : mod_vtm.mod_model.mod_token.type_token = lib_errormonade.read(token_);
let manifestation_token : type_manifestation<mod_vtm.mod_model.mod_token.type_token> = mod_token.create_extended(token);
let node_token : lib_xml.type_node = mod_manifestation.view(manifestation_token);
children_game.push(node_token);
}
else
{
// nothing tun
}
}
let node_game : lib_xml.type_node = (
lib_xml.create_normal
(
"g",
{
"class": "game",
},
children_game
)
);
return node_game;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function bind(game : type_game) : void
{
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
lib_trait.attend<signature_manifestation<mod_vtm.mod_model.mod_game.type_game, lib_xml.type_node>>
(
trait_manifestation,
"svg_game",
{
"view": (manifestation) => view(manifestation.data),
"bind": (manifestation) => bind(manifestation.data),
}
)
;
}
}
}
}