/* * Verrückte Turing-Maschinen — A turing complete game * Copyright (C) 2016 Christian Fraß * * 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 . */ module mod_vtm_manifestation { /** * @author kcf */ export class klasse_svg_aktor extends klasse_manifestation { /** * @author kcf */ private stelle : mod_vtm_aufbau.typ_stelle; /** * @author kcf */ public constructor(aufbau : mod_vtm_aufbau.typ_aktor, stelle : mod_vtm_aufbau.typ_stelle) { super(aufbau); this.stelle = stelle; } /** * @author kcf * @implementation */ public darstellen() : mod_vtm_helfer.schnittstelle_xmlknoten { let aktor : mod_vtm_aufbau.typ_aktor = this.aufbau; let knoten_rahmen = function () : mod_vtm_helfer.schnittstelle_xmlknoten { return ( svg_pfad ( mod_vtm_helfer.sequenz(6).map(i => mod_vtm_helfer.vektor_polar(((i+0.5)/6.0) * (2*Math.PI), 0.5)), true, { "class": "rahmen" } ) ); } ; let kinder_feld : Array = []; switch (aktor.art) { case "erzeuger": { kinder_feld.push(knoten_rahmen()); let richtung : mod_vtm_aufbau.typ_richtung = mod_vtm_aufbau.aktor_erzeuger_richtung_lesen(aktor.angaben); let knoten_pfeil : mod_vtm_helfer.schnittstelle_xmlknoten = ( new mod_vtm_helfer.klasse_xmlknoten_normal ( "path", { "d": svg_form_pfeil, "class": ( [ "pfeil", "erzeuger", ].join(" ") ), "transform": ( [ "rotate(" + ((richtung/6.0) * 360).toFixed(svg_float_praezission) + ")", "translate(-0.2, 0)", "scale(0.12)", ].join(" ") ), } ) ); kinder_feld.push(knoten_pfeil); break; } case "befoerderer": { kinder_feld.push(knoten_rahmen()); let richtung : mod_vtm_aufbau.typ_richtung = mod_vtm_aufbau.aktor_befoerderer_richtung_lesen(aktor.angaben); let knoten_pfeil : mod_vtm_helfer.schnittstelle_xmlknoten = ( new mod_vtm_helfer.klasse_xmlknoten_normal ( "path", { "d": svg_form_pfeil, "class": ( [ "pfeil", "neutral", ].join(" ") ), "transform": ( [ "rotate(" + ((richtung/6.0) * 360).toFixed(svg_float_praezission) + ")", "translate(-0.2, 0)", "scale(0.12)", ].join(" ") ), } ) ); kinder_feld.push(knoten_pfeil); break; } case "schreiber": { kinder_feld.push(knoten_rahmen()); let richtung : mod_vtm_aufbau.typ_richtung = mod_vtm_aufbau.aktor_schreiber_richtung_lesen(aktor.angaben); let symbol : mod_vtm_aufbau.typ_symbol = mod_vtm_aufbau.aktor_schreiber_symbol_lesen(aktor.angaben); let knoten_pfeil : mod_vtm_helfer.schnittstelle_xmlknoten = ( new mod_vtm_helfer.klasse_xmlknoten_normal ( "path", { "d": svg_form_pfeil, "class": ( [ "pfeil", "symbol_" + symbol.toFixed(0), ].join(" ") ), "transform": ( [ "rotate(" + ((richtung/6.0) * 360).toFixed(svg_float_praezission) + ")", "translate(-0.2, 0)", "scale(0.12)", ].join(" ") ), } ) ); kinder_feld.push(knoten_pfeil); break; } case "leser": { kinder_feld.push(knoten_rahmen()); let richtung : mod_vtm_aufbau.typ_richtung = mod_vtm_aufbau.aktor_leser_richtung_lesen(aktor.angaben); let symbol_links : mod_vtm_aufbau.typ_symbol = mod_vtm_aufbau.aktor_leser_symbol_links_lesen(aktor.angaben); let symbol_rechts : mod_vtm_aufbau.typ_symbol = mod_vtm_aufbau.aktor_leser_symbol_rechts_lesen(aktor.angaben); let ausgaenge : Array<{summand : mod_vtm_aufbau.typ_richtung, symbol : schnittstelle_fehlermonade;}> = [ { "summand": 0, "symbol": new klasse_nichts(), }, { "summand": +2, "symbol": new klasse_schlicht(symbol_links), }, { "summand": -2, "symbol": new klasse_schlicht(symbol_rechts), }, ] ; ausgaenge.forEach ( eintrag => { let winkel : float = ((mod_vtm_aufbau.richtung_addieren(richtung, eintrag.summand) / 6.0) * 360); let knoten_pfeil : mod_vtm_helfer.schnittstelle_xmlknoten = ( new mod_vtm_helfer.klasse_xmlknoten_normal ( "path", { "d": svg_form_pfeil, "class": ( [ "pfeil", ( eintrag.symbol.ist_schlicht() ? "symbol_" + eintrag.symbol.lesen().toFixed(0) : "neutral" ), ].join(" ") ), "transform": ( [ "rotate(" + winkel.toFixed(svg_float_praezission) + ")", "translate(0.1, 0)", "scale(0.075)", ].join(" ") ), } ) ); kinder_feld.push(knoten_pfeil); } ) ; break; } case "verwerfer": { kinder_feld.push(knoten_rahmen()); let knoten_kreis : mod_vtm_helfer.schnittstelle_xmlknoten = ( new mod_vtm_helfer.klasse_xmlknoten_normal ( "circle", { "cx": (0.0).toFixed(svg_float_praezission), "cy": (0.0).toFixed(svg_float_praezission), "r": (0.25).toFixed(svg_float_praezission), "class": ( [ "kreis", "negativ", ].join(" ") ), } ) ); kinder_feld.push(knoten_kreis); break; } case "annehmer": { kinder_feld.push(knoten_rahmen()); let knoten_kreis : mod_vtm_helfer.schnittstelle_xmlknoten = ( new mod_vtm_helfer.klasse_xmlknoten_normal ( "circle", { "cx": (0.0).toFixed(svg_float_praezission), "cy": (0.0).toFixed(svg_float_praezission), "r": (0.25).toFixed(svg_float_praezission), "class": ( [ "kreis", "positiv", ].join(" ") ), } ) ); kinder_feld.push(knoten_kreis); break; } default: { let meldung : string = ("unbehandelter Aktor-Typ"); throw (new Error(meldung)); break; } } let position : typ_position = position_von_stelle(this.stelle); let knoten_feld : mod_vtm_helfer.schnittstelle_xmlknoten = ( new mod_vtm_helfer.klasse_xmlknoten_normal ( "g", { "class": "feld", "rel": mod_vtm_aufbau.stelle_hash(this.stelle), "transform": ("translate(" + position.x.toFixed(svg_float_praezission) + ", " + position.y.toFixed(svg_float_praezission) + ")"), }, kinder_feld ) ); return knoten_feld; } /** * @author kcf * @implementation */ public binden() : void { } } }