vtm/source/manifestation/svg/actuators/_actuator.ts

162 lines
4.4 KiB
TypeScript
Raw Normal View History

2018-03-28 12:09:27 +02:00
/*
* Verrückte Turing-Maschinen A turing complete game
2018-03-29 01:13:39 +02:00
* Copyright (C) 2016-2018 Christian Fraß <vidofnir@folksprak.org>
2018-03-28 12:09:27 +02: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/>.
*/
module mod_vtm
{
export module mod_manifestation
{
export module mod_svg
{
2018-03-28 13:59:29 +02:00
export module mod_actuator
2018-03-28 12:09:27 +02:00
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export type signature_actuator =
2018-03-28 12:09:27 +02:00
{
2018-03-28 13:59:29 +02:00
view : (actuator : mod_vtm.mod_model.mod_actuator.type_actuator)=>Array<lib_xml.type_node>;
2018-03-28 12:09:27 +02:00
}
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export var trait_actuator : lib_trait.type_trait<signature_actuator> = lib_trait.create<signature_actuator>();
2018-03-28 12:09:27 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export type type_actuator =
2018-03-28 12:09:27 +02:00
{
2018-03-28 13:59:29 +02:00
model : mod_vtm.mod_model.mod_actuator.type_actuator;
spot : mod_vtm.mod_model.mod_spot.type_spot;
2018-03-28 12:09:27 +02:00
}
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
function create
2018-03-28 12:09:27 +02:00
(
2018-03-28 13:59:29 +02:00
model : mod_vtm.mod_model.mod_actuator.type_actuator,
spot : mod_vtm.mod_model.mod_spot.type_spot
2018-03-28 12:09:27 +02:00
)
2018-03-28 13:59:29 +02:00
: type_actuator
2018-03-28 12:09:27 +02:00
{
return {
2018-03-28 13:59:29 +02:00
"model": model,
"spot": spot
2018-03-28 12:09:27 +02:00
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-29 01:13:39 +02:00
export function create_extended
2018-03-28 12:09:27 +02:00
(
2018-03-28 13:59:29 +02:00
model : mod_vtm.mod_model.mod_actuator.type_actuator,
spot : mod_vtm.mod_model.mod_spot.type_spot
2018-03-28 12:09:27 +02:00
)
2018-03-28 13:59:29 +02:00
: type_manifestation<mod_vtm.mod_model.mod_actuator.type_actuator>
2018-03-28 12:09:27 +02:00
{
return {
2018-03-28 13:59:29 +02:00
"kind": "svg_actuator",
"data": create(model, spot),
2018-03-28 12:09:27 +02:00
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
function view(actuator_ : type_actuator) : lib_xml.type_node
2018-03-28 12:09:27 +02:00
{
2018-03-28 13:59:29 +02:00
let actuator : mod_vtm.mod_model.mod_actuator.type_actuator = actuator_.model;
let node_rahmen = function () : lib_xml.type_node
2018-03-28 12:09:27 +02:00
{
return (
2018-03-29 01:13:39 +02:00
lib_svg.path
2018-03-28 12:09:27 +02:00
(
2018-03-28 13:59:29 +02:00
mod_vtm.mod_helfer.sequence(6).map(i => lib_vector.polar(((i+0.5)/6) * (2*Math.PI), 0.5)),
2018-03-28 12:09:27 +02:00
true,
{
"class": "rahmen"
}
)
);
}
;
2018-03-29 01:13:39 +02:00
let position : mod_position.type_position = mod_position.from_spot(actuator_.spot);
2018-03-28 13:59:29 +02:00
let node_tile : lib_xml.type_node = (
lib_xml.create_normal
2018-03-28 12:09:27 +02:00
(
"g",
{
2018-03-28 13:59:29 +02:00
"class": "tile",
"rel": mod_vtm.mod_model.mod_spot.hash(actuator_.spot),
2018-03-29 01:13:39 +02:00
"transform": lib_svg.translation(position.x, position.y),
2018-03-28 12:09:27 +02:00
},
(
2018-03-28 13:59:29 +02:00
[node_rahmen()]
.concat(lib_trait.deploy<signature_actuator>(trait_actuator, actuator.kind)["view"](actuator))
2018-03-28 12:09:27 +02:00
)
)
);
2018-03-28 13:59:29 +02:00
return node_tile;
2018-03-28 12:09:27 +02:00
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
function bind(actuator : type_actuator) : void
2018-03-28 12:09:27 +02:00
{
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
lib_trait.attend<signature_manifestation<mod_vtm.mod_model.mod_actuator.type_actuator, lib_xml.type_node>>
2018-03-28 12:09:27 +02:00
(
2018-03-28 13:59:29 +02:00
trait_manifestation,
"svg_actuator",
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
}
)
;
}
}
}
}