vtm/quelldatein/manifestation/svg/figur.ts

198 lines
5.4 KiB
TypeScript
Raw Normal View History

2017-11-09 18:42:09 +01:00
/*
* Verrückte Turing-Maschinen A turing complete game
* Copyright (C) 2016 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/>.
*/
2018-03-26 14:22:20 +02:00
module mod_vtm
2017-11-09 18:42:09 +01:00
{
2018-03-26 14:22:20 +02:00
export module mod_manifestation
2017-11-09 18:42:09 +01:00
{
2018-03-26 14:22:20 +02:00
export module mod_svg
{
export module mod_figur
2018-03-26 00:41:10 +02:00
{
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
export type typ_figur =
{
aufbau : mod_vtm.mod_aufbau.mod_figur.typ_figur;
}
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
function erstellen
(
aufbau : mod_vtm.mod_aufbau.mod_figur.typ_figur
)
: typ_figur
{
return {
"aufbau": aufbau,
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function erstellen_manifestation
(
aufbau : mod_vtm.mod_aufbau.mod_figur.typ_figur
)
: typ_manifestation<mod_vtm.mod_aufbau.mod_figur.typ_figur>
{
return {
"art": "svg_figur",
"angaben": erstellen(aufbau),
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function darstellen
(
figur_ : typ_figur
)
2018-03-28 11:19:46 +02:00
: lib_xml.typ_knoten
2018-03-26 14:22:20 +02:00
{
let figur : mod_vtm.mod_aufbau.mod_figur.typ_figur = figur_.aufbau;
2018-03-28 11:19:46 +02:00
let kinder_figur : Array<lib_xml.typ_knoten> = [];
2018-03-26 14:22:20 +02:00
// Stein
{
2018-03-28 11:19:46 +02:00
let knoten_stein : lib_xml.typ_knoten = (
lib_xml.erstellen_normal
2018-03-26 14:22:20 +02:00
(
"circle",
{
"cx": (0.0).toFixed(float_praezission),
"cy": (0.0).toFixed(float_praezission),
"r": (0.125).toFixed(float_praezission),
"class": "stein",
}
)
);
kinder_figur.push(knoten_stein);
}
// Band
{
let band : Array<mod_vtm.mod_aufbau.mod_symbol.typ_symbol> = mod_vtm.mod_aufbau.mod_figur.band_lesen(figur);
2018-03-28 11:19:46 +02:00
let kinder_band : Array<lib_xml.typ_knoten> = [];
2018-03-26 14:22:20 +02:00
band.forEach
(
(symbol, index) =>
{
let r : float = 0.06125;
let x : float = (+0.1+(2*r*1.25)*index);
let y : float = (-0.1);
2018-03-28 11:19:46 +02:00
let knoten_eintrag : lib_xml.typ_knoten = (
lib_xml.erstellen_normal
2018-03-26 14:22:20 +02:00
(
"circle",
{
"cx": x.toFixed(float_praezission),
"cy": y.toFixed(float_praezission),
"r": r.toFixed(float_praezission),
/*
"x": (x-r).toFixed(float_praezission),
"y": (y-r).toFixed(float_praezission),
"width": (2*r).toFixed(float_praezission),
"height": (2*r).toFixed(float_praezission),
*/
"class": (
[
"eintrag",
"symbol_" + symbol.toFixed(0),
].join(" ")
),
}
)
);
kinder_band.push(knoten_eintrag);
}
)
;
let knoten_band = (
2018-03-28 11:19:46 +02:00
lib_xml.erstellen_normal
2018-03-26 14:22:20 +02:00
(
"g",
{
"class": "band",
},
kinder_band
)
);
kinder_figur.push(knoten_band);
}
let position : mod_position.typ_position = mod_position.von_stelle(mod_vtm.mod_aufbau.mod_figur.stelle_lesen(figur));
let knoten_figur = (
2018-03-28 11:19:46 +02:00
lib_xml.erstellen_normal
2018-03-26 14:22:20 +02:00
(
"g",
{
"class": "figur",
"transform": (
"translate"
+ "("
+ position.x.toFixed(float_praezission)
+ ","
+ position.y.toFixed(float_praezission)
+ ")"
),
},
kinder_figur
)
);
return knoten_figur;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function binden(figur : typ_figur) : void
{
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
implementierung_manifestation["svg_figur"] =
{
"darstellen": (manifestation) => darstellen(manifestation.angaben),
"binden": (manifestation) => binden(manifestation.angaben),
}
;
}
}
2018-03-26 00:41:10 +02:00
}
2017-11-09 18:42:09 +01:00
}