vtm/source/manifestation/svg/token.ts
Christian Fraß 931b6f61d3 update
2018-03-29 22:00:42 +02:00

195 lines
5.3 KiB
TypeScript

/*
* Verrückte Turing-Maschinen — A turing complete game
* Copyright (C) 2016-2018 kcf <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_token
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
export type type_token =
{
model : mod_vtm.mod_model.mod_token.type_token;
}
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
function create
(
model : mod_vtm.mod_model.mod_token.type_token
)
: type_token
{
return {
"model": model,
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function create_extended
(
model : mod_vtm.mod_model.mod_token.type_token
)
: type_manifestation<mod_vtm.mod_model.mod_token.type_token>
{
return {
"kind": "svg_token",
"data": create(model),
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function view
(
token_ : type_token
)
: lib_xml.type_node
{
let token : mod_vtm.mod_model.mod_token.type_token = token_.model;
let children_token : Array<lib_xml.type_node> = [];
// Stein
{
let node_stein : lib_xml.type_node = (
lib_xml.create_normal
(
"circle",
{
"cx": (0.0).toFixed(lib_svg.float_precision),
"cy": (0.0).toFixed(lib_svg.float_precision),
"r": (0.125).toFixed(lib_svg.float_precision),
"class": "stein",
}
)
);
children_token.push(node_stein);
}
// Band
{
let tape : Array<mod_vtm.mod_model.mod_symbol.type_symbol> = mod_vtm.mod_model.mod_token.tape_read(token);
let children_tape : Array<lib_xml.type_node> = [];
tape.forEach
(
(symbol, index) =>
{
let r : float = 0.06125;
let x : float = (+0.1+(2*r*1.25)*index);
let y : float = (-0.1);
let node_eintrag : lib_xml.type_node = (
lib_xml.create_normal
(
"circle",
{
"cx": x.toFixed(lib_svg.float_precision),
"cy": y.toFixed(lib_svg.float_precision),
"r": r.toFixed(lib_svg.float_precision),
/*
"x": (x-r).toFixed(lib_svg.float_precision),
"y": (y-r).toFixed(lib_svg.float_precision),
"width": (2*r).toFixed(lib_svg.float_precision),
"height": (2*r).toFixed(lib_svg.float_precision),
*/
"class": (
[
"eintrag",
"symbol_" + symbol.toFixed(0),
].join(" ")
),
}
)
);
children_tape.push(node_eintrag);
}
)
;
let node_tape = (
lib_xml.create_normal
(
"g",
{
"class": "tape",
},
children_tape
)
);
children_token.push(node_tape);
}
let position : mod_position.type_position = mod_position.from_spot(mod_vtm.mod_model.mod_token.spot_read(token));
let node_token = (
lib_xml.create_normal
(
"g",
{
"class": "token",
"transform": lib_svg.translation(position.x, position.y),
},
children_token
)
);
return node_token;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function bind(token : type_token) : void
{
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
lib_trait.attend<signature_manifestation<mod_vtm.mod_model.mod_token.type_token, lib_xml.type_node>>
(
trait_manifestation,
"svg_token",
{
"view": (manifestation) => view(manifestation.data),
"bind": (manifestation) => bind(manifestation.data),
}
)
;
}
}
}
}