vtm/source/manifestation/svg/game.ts

170 lines
4.8 KiB
TypeScript
Raw Permalink Normal View History

2017-11-09 18:42:09 +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 18:42:09 +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/>.
*/
2025-09-23 12:13:49 +02:00
namespace mod_vtm
2017-11-09 18:42:09 +01:00
{
2025-09-23 12:13:49 +02:00
export namespace mod_manifestation
2017-11-09 18:42:09 +01:00
{
2018-03-26 14:22:20 +02:00
2025-09-23 12:13:49 +02:00
export namespace mod_svg
2017-11-09 18:42:09 +01:00
{
2018-03-26 14:22:20 +02:00
2025-09-23 12:13:49 +02:00
export namespace mod_game
2018-03-26 14:22:20 +02:00
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-29 01:13:39 +02:00
export type type_game =
2018-03-26 14:22:20 +02:00
{
2018-03-29 01:13:39 +02:00
model : mod_vtm.mod_model.mod_game.type_game;
2018-03-26 14:22:20 +02:00
}
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-29 01:13:39 +02:00
function create(model : mod_vtm.mod_model.mod_game.type_game) : type_game
2018-03-26 00:41:10 +02:00
{
2018-03-26 14:22:20 +02:00
return {
2018-03-28 13:59:29 +02:00
"model": model
2018-03-26 14:22:20 +02:00
};
2018-03-26 00:41:10 +02:00
}
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-29 01:13:39 +02:00
export function create_extended(model : mod_vtm.mod_model.mod_game.type_game) : type_manifestation<mod_vtm.mod_model.mod_game.type_game>
2017-11-09 18:42:09 +01:00
{
2018-03-26 14:22:20 +02:00
return {
2018-03-29 01:13:39 +02:00
"kind": "svg_game",
2018-03-28 13:59:29 +02:00
"data": create(model)
2018-03-26 14:22:20 +02:00
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-29 01:13:39 +02:00
function view(game : type_game) : lib_xml.type_node
2018-03-26 14:22:20 +02:00
{
2018-03-29 01:13:39 +02:00
let children_game : Array<lib_xml.type_node> = [];
2018-03-26 14:22:20 +02:00
// Welt
{
2018-03-28 13:59:29 +02:00
let children_world : Array<lib_xml.type_node> = [];
2018-03-26 14:22:20 +02:00
// Felder
{
2018-03-28 13:59:29 +02:00
let children_tiles : Array<lib_xml.type_node> = [];
2018-03-29 01:13:39 +02:00
mod_vtm.mod_model.mod_world.tiles_read(mod_vtm.mod_model.mod_game.world_read(game.model)).forEach
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
({"spot": spot, "actuator": actuator}) =>
2018-03-26 14:22:20 +02:00
{
2018-03-29 01:13:39 +02:00
let manifestation_tile : type_manifestation<mod_vtm.mod_model.mod_actuator.type_actuator> = mod_actuator.create_extended(actuator, spot);
2018-03-28 13:59:29 +02:00
let node_tile : lib_xml.type_node = mod_manifestation.view(manifestation_tile);
children_tiles.push(node_tile);
2018-03-26 14:22:20 +02:00
}
)
;
2018-03-28 13:59:29 +02:00
let node_tiles : lib_xml.type_node = (
lib_xml.create_normal
2018-03-26 14:22:20 +02:00
(
"g",
{
2018-03-28 13:59:29 +02:00
"class": "tiles",
2018-03-26 14:22:20 +02:00
},
2018-03-28 13:59:29 +02:00
children_tiles
2018-03-26 14:22:20 +02:00
)
);
2018-03-28 13:59:29 +02:00
children_world.push(node_tiles);
2018-03-26 14:22:20 +02:00
}
2018-03-28 13:59:29 +02:00
let node_world : lib_xml.type_node = (
lib_xml.create_normal
2018-03-26 14:22:20 +02:00
(
"g",
{
2018-03-28 13:59:29 +02:00
"class": "world",
2018-03-26 14:22:20 +02:00
},
2018-03-28 13:59:29 +02:00
children_world
2018-03-26 14:22:20 +02:00
)
);
2018-03-29 01:13:39 +02:00
children_game.push(node_world);
2018-03-26 14:22:20 +02:00
}
// Figur
{
2018-03-29 01:13:39 +02:00
let token_ : lib_errormonade.type_errormonade<mod_vtm.mod_model.mod_token.type_token> = mod_vtm.mod_model.mod_game.token_read(game.model);
2018-03-28 13:59:29 +02:00
if (lib_errormonade.filled(token_))
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
let token : mod_vtm.mod_model.mod_token.type_token = lib_errormonade.read(token_);
2018-03-29 01:13:39 +02:00
let manifestation_token : type_manifestation<mod_vtm.mod_model.mod_token.type_token> = mod_token.create_extended(token);
2018-03-28 13:59:29 +02:00
let node_token : lib_xml.type_node = mod_manifestation.view(manifestation_token);
2018-03-29 01:13:39 +02:00
children_game.push(node_token);
2018-03-26 14:22:20 +02:00
}
else
{
2018-03-28 13:59:29 +02:00
// nothing tun
2018-03-26 14:22:20 +02:00
}
}
2018-03-29 01:13:39 +02:00
let node_game : lib_xml.type_node = (
2018-03-28 13:59:29 +02:00
lib_xml.create_normal
2018-03-26 14:22:20 +02:00
(
"g",
{
2018-03-29 01:13:39 +02:00
"class": "game",
2018-03-26 14:22:20 +02:00
},
2018-03-29 01:13:39 +02:00
children_game
2018-03-26 14:22:20 +02:00
)
);
2018-03-29 01:13:39 +02:00
return node_game;
2018-03-26 14:22:20 +02:00
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-29 01:13:39 +02:00
function bind(game : type_game) : void
2018-03-26 14:22:20 +02:00
{
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-29 01:13:39 +02:00
lib_trait.attend<signature_manifestation<mod_vtm.mod_model.mod_game.type_game, lib_xml.type_node>>
2018-03-28 12:09:27 +02:00
(
2018-03-28 13:59:29 +02:00
trait_manifestation,
2018-03-29 01:13:39 +02:00
"svg_game",
2018-03-28 12:09:27 +02:00
{
2018-03-28 13:59:29 +02:00
"view": (manifestation) => view(manifestation.data),
"bind": (manifestation) => bind(manifestation.data),
2018-03-28 12:09:27 +02:00
}
)
2018-03-26 14:22:20 +02:00
;
}
2017-11-09 18:42:09 +01:00
}
2018-03-26 14:22:20 +02:00
2017-11-09 18:42:09 +01:00
}
}