From 9d603364b1502cdeae7fc09c9c6990775239e9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Wed, 8 Nov 2017 15:05:06 +0100 Subject: [PATCH] sicherung --- makefile | 27 +- quelldatein/aufbau/annehmer.ts | 33 +++ quelldatein/aufbau/befoerderer.ts | 9 + quelldatein/aufbau/figur.ts | 113 ++++---- quelldatein/aufbau/leser.ts | 80 ++++++ quelldatein/aufbau/position.ts | 20 -- quelldatein/aufbau/richtung.ts | 9 + quelldatein/aufbau/schreiber.ts | 34 ++- quelldatein/aufbau/stelle.ts | 65 +++++ quelldatein/aufbau/symbol.ts | 16 ++ quelldatein/aufbau/verwerfer.ts | 3 +- quelldatein/aufbau/welt.ts | 75 +++++- quelldatein/aufbau/zustand.ts | 28 ++ quelldatein/darstellung_steuerung/position.ts | 33 +++ quelldatein/darstellung_steuerung/svg.ts | 36 +++ quelldatein/darstellung_steuerung/welt.css | 12 + quelldatein/darstellung_steuerung/welt.ts | 242 ++++++++++++++++++ quelldatein/helfer/hashmap.ts | 23 +- quelldatein/helfer/mathematik.ts | 23 ++ quelldatein/helfer/vektor.ts | 38 +++ quelldatein/helfer/xmlknoten.ts | 143 +++++++++++ quelldatein/test.ts | 41 ++- 22 files changed, 1006 insertions(+), 97 deletions(-) create mode 100644 quelldatein/aufbau/annehmer.ts create mode 100644 quelldatein/aufbau/leser.ts delete mode 100644 quelldatein/aufbau/position.ts create mode 100644 quelldatein/aufbau/stelle.ts create mode 100644 quelldatein/aufbau/zustand.ts create mode 100644 quelldatein/darstellung_steuerung/position.ts create mode 100644 quelldatein/darstellung_steuerung/svg.ts create mode 100644 quelldatein/darstellung_steuerung/welt.css create mode 100644 quelldatein/darstellung_steuerung/welt.ts create mode 100644 quelldatein/helfer/mathematik.ts create mode 100644 quelldatein/helfer/vektor.ts create mode 100644 quelldatein/helfer/xmlknoten.ts diff --git a/makefile b/makefile index 6da96ff..0abc22f 100644 --- a/makefile +++ b/makefile @@ -1,32 +1,51 @@ erzeugnis/vtm.js: \ quelldatein/basis/typen.ts \ quelldatein/basis/fehlermonade.ts \ + quelldatein/helfer/mathematik.ts \ + quelldatein/helfer/vektor.ts \ quelldatein/helfer/hashmap.ts \ + quelldatein/helfer/xmlknoten.ts \ quelldatein/aufbau/richtung.ts \ quelldatein/aufbau/symbol.ts \ - quelldatein/aufbau/position.ts \ + quelldatein/aufbau/stelle.ts \ + quelldatein/aufbau/zustand.ts \ quelldatein/aufbau/figur.ts \ quelldatein/aufbau/aktor.ts \ quelldatein/aufbau/befoerderer.ts \ quelldatein/aufbau/schreiber.ts \ + quelldatein/aufbau/leser.ts \ quelldatein/aufbau/verwerfer.ts \ + quelldatein/aufbau/annehmer.ts \ quelldatein/aufbau/welt.ts \ + quelldatein/darstellung_steuerung/position.ts \ + quelldatein/darstellung_steuerung/svg.ts \ + quelldatein/darstellung_steuerung/welt.ts \ quelldatein/test.ts - mkdir -p erzeugnis - tsc \ + @ echo "-- kompilieren …" + @ mkdir -p erzeugnis + @ tsc \ --allowUnreachableCode \ quelldatein/basis/typen.ts \ quelldatein/basis/fehlermonade.ts \ + quelldatein/helfer/mathematik.ts \ + quelldatein/helfer/vektor.ts \ quelldatein/helfer/hashmap.ts \ + quelldatein/helfer/xmlknoten.ts \ quelldatein/aufbau/richtung.ts \ quelldatein/aufbau/symbol.ts \ - quelldatein/aufbau/position.ts \ + quelldatein/aufbau/stelle.ts \ + quelldatein/aufbau/zustand.ts \ quelldatein/aufbau/figur.ts \ quelldatein/aufbau/aktor.ts \ quelldatein/aufbau/befoerderer.ts \ quelldatein/aufbau/schreiber.ts \ + quelldatein/aufbau/leser.ts \ quelldatein/aufbau/verwerfer.ts \ + quelldatein/aufbau/annehmer.ts \ quelldatein/aufbau/welt.ts \ + quelldatein/darstellung_steuerung/position.ts \ + quelldatein/darstellung_steuerung/svg.ts \ + quelldatein/darstellung_steuerung/welt.ts \ quelldatein/test.ts \ --outFile erzeugnis/vtm.js diff --git a/quelldatein/aufbau/annehmer.ts b/quelldatein/aufbau/annehmer.ts new file mode 100644 index 0000000..85a7fab --- /dev/null +++ b/quelldatein/aufbau/annehmer.ts @@ -0,0 +1,33 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export class klasse_annehmer + implements schnittstelle_aktor + { + + /** + * @author kcf + */ + public constructor() + { + } + + + /** + * @author kcf + * @implementation + */ + public verwenden(figur : klasse_figur) : void + { + figur.annehmen(); + } + + } + + } + + diff --git a/quelldatein/aufbau/befoerderer.ts b/quelldatein/aufbau/befoerderer.ts index df0f81f..d60765b 100644 --- a/quelldatein/aufbau/befoerderer.ts +++ b/quelldatein/aufbau/befoerderer.ts @@ -24,6 +24,15 @@ module mod_vtm_aufbau } + /** + * @author kcf + */ + public richtung_lesen() : typ_richtung + { + return this.richtung; + } + + /** * @author kcf * @implementation diff --git a/quelldatein/aufbau/figur.ts b/quelldatein/aufbau/figur.ts index b800a4c..e204c69 100644 --- a/quelldatein/aufbau/figur.ts +++ b/quelldatein/aufbau/figur.ts @@ -8,6 +8,12 @@ module mod_vtm_aufbau export class klasse_figur { + /** + * @author kcf + */ + private zustand : typ_zustand; + + /** * @author kcf */ @@ -17,25 +23,35 @@ module mod_vtm_aufbau /** * @author kcf */ - private position : typ_position; + private stelle : typ_stelle; /** * @author kcf */ - public constructor(band : Array = [], position : typ_position = {"u": 0, "v": 0}) + public constructor(band : Array = [], stelle : typ_stelle = stelle_null()) { + this.zustand = zustand_normal; this.band = band; - this.position = position; + this.stelle = stelle; } /** * @author kcf */ - public position_lesen() : typ_position + public zustand_lesen() : typ_zustand { - return this.position; + return this.zustand; + } + + + /** + * @author kcf + */ + public stelle_lesen() : typ_stelle + { + return this.stelle; } @@ -44,47 +60,8 @@ module mod_vtm_aufbau */ public bewegen(richtung : typ_richtung) : void { - let summand : typ_position; - switch (richtung) - { - case 0: - { - summand = {"u": +1, "v": 0}; - break; - } - case 1: - { - summand = {"u": +1, "v": 0}; - break; - } - case 2: - { - summand = {"u": +1, "v": 0}; - break; - } - case 3: - { - summand = {"u": +1, "v": 0}; - break; - } - case 4: - { - summand = {"u": +1, "v": 0}; - break; - } - case 5: - { - summand = {"u": +1, "v": 0}; - break; - } - default: - { - let meldung : string = ("ungültige Richtung '" + String(richtung) + "'"); - throw (new Error(meldung)); - break; - } - } - this.position = {"u": (this.position.u + summand.u), "v": (this.position.v + summand.v)}; + let summand : typ_stelle = stelle_von_richtung(richtung); + this.stelle = stelle_addieren(this.stelle, summand); } @@ -112,6 +89,50 @@ module mod_vtm_aufbau } } + + /** + * @author kcf + */ + public band_schieben() : void + { + if (this.band.length <= 0) + { + let meldung : string = "Band ist leer"; + throw (new Error(meldung)); + } + else + { + this.band.shift(); + } + } + + + /** + * @author kcf + */ + public annehmen() : void + { + this.zustand = zustand_fertig; + } + + + /** + * @author kcf + */ + public verwerfen() : void + { + this.zustand = zustand_tot; + } + + + /** + * @author kcf + */ + public zu_string() : string + { + return ("{" + zustand_zu_string(this.zustand) + " / " + stelle_zu_string(this.stelle) + " : " + "[" + this.band.map(symbol => symbol_zu_string(symbol)) + "]" + "}"); + } + } } diff --git a/quelldatein/aufbau/leser.ts b/quelldatein/aufbau/leser.ts new file mode 100644 index 0000000..0f5c126 --- /dev/null +++ b/quelldatein/aufbau/leser.ts @@ -0,0 +1,80 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export class klasse_leser + implements schnittstelle_aktor + { + + /** + * @author kcf + */ + private richtung : typ_richtung; + + + /** + * @author kcf + */ + public constructor(richtung : typ_richtung = 0) + { + this.richtung = richtung; + } + + + /** + * @author kcf + */ + public richtung_lesen() : typ_richtung + { + return this.richtung; + } + + + /** + * @author kcf + * @implementation + */ + public verwenden(figur : klasse_figur) : void + { + let symbol_ : schnittstelle_fehlermonade = figur.band_lesen(); + let summand : typ_richtung; + if (symbol_.ist_schlicht()) + { + let symbol : typ_symbol = symbol_.lesen(); + figur.band_schieben(); + switch (symbol) + { + case symbol_rot: + { + summand = +1; + break; + } + case symbol_gruen: + { + summand = -1; + break; + } + default: + { + let meldung : string = ("ungültiges Symbol '" + String(symbol) + "'"); + throw (new Error(meldung)); + break; + } + } + } + else + { + summand = 0; + } + let richtung : typ_richtung = richtung_addieren(this.richtung, summand); + figur.bewegen(richtung); + } + + } + + } + + diff --git a/quelldatein/aufbau/position.ts b/quelldatein/aufbau/position.ts deleted file mode 100644 index e168ce5..0000000 --- a/quelldatein/aufbau/position.ts +++ /dev/null @@ -1,20 +0,0 @@ - -module mod_vtm_aufbau - { - - /** - * @author kcf - */ - export type typ_position = {u : int; v : int;}; - - - /** - * @author kcf - */ - export function position_hash(position : typ_position) : string - { - return (position.u.toFixed(0) + "_" + position.v.toFixed(0)); - } - - } - diff --git a/quelldatein/aufbau/richtung.ts b/quelldatein/aufbau/richtung.ts index ae35807..3c00a42 100644 --- a/quelldatein/aufbau/richtung.ts +++ b/quelldatein/aufbau/richtung.ts @@ -7,5 +7,14 @@ module mod_vtm_aufbau */ export type typ_richtung = int; + + /** + * @author kcf + */ + export function richtung_addieren(richtung1 : typ_richtung, richtung2 : typ_richtung) : typ_richtung + { + return mod_vtm_helfer.mod(richtung1 + richtung2, 6); + } + } diff --git a/quelldatein/aufbau/schreiber.ts b/quelldatein/aufbau/schreiber.ts index b0ecf70..cba36b9 100644 --- a/quelldatein/aufbau/schreiber.ts +++ b/quelldatein/aufbau/schreiber.ts @@ -9,12 +9,6 @@ module mod_vtm_aufbau implements schnittstelle_aktor { - /** - * @author kcf - */ - private symbol : typ_symbol; - - /** * @author kcf */ @@ -24,10 +18,34 @@ module mod_vtm_aufbau /** * @author kcf */ - public constructor(symbol : int = 0, richtung : int = 0) + private symbol : typ_symbol; + + + /** + * @author kcf + */ + public constructor(richtung : typ_richtung = 0, symbol : typ_symbol = 0) { - this.symbol = symbol; this.richtung = richtung; + this.symbol = symbol; + } + + + /** + * @author kcf + */ + public richtung_lesen() : typ_richtung + { + return this.richtung; + } + + + /** + * @author kcf + */ + public symbol_lesen() : typ_symbol + { + return this.symbol; } diff --git a/quelldatein/aufbau/stelle.ts b/quelldatein/aufbau/stelle.ts new file mode 100644 index 0000000..9e11bfd --- /dev/null +++ b/quelldatein/aufbau/stelle.ts @@ -0,0 +1,65 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export type typ_stelle = {u : int; v : int;}; + + + /** + * @author kcf + */ + export function stelle_hash(stelle : typ_stelle) : string + { + return (stelle.u.toFixed(0) + "_" + stelle.v.toFixed(0)); + } + + + /** + * @author kcf + */ + export function stelle_zu_string(stelle : typ_stelle) : string + { + return ("<" + stelle.u.toFixed(0) + "," + stelle.v.toFixed(0) + ">"); + } + + + /** + * @author kcf + */ + export function stelle_null() : typ_stelle + { + return {"u": 0, "v": 0}; + } + + + /** + * @author kcf + */ + export function stelle_von_richtung(richtung : typ_richtung) : typ_stelle + { + switch (richtung) + { + case 0: {return {"u": +1, "v": 0}; break;} + case 1: {return {"u": +1, "v": +1}; break;} + case 2: {return {"u": 0, "v": +1}; break;} + case 3: {return {"u": -1, "v": 0}; break;} + case 4: {return {"u": -1, "v": -1}; break;} + case 5: {return {"u": 0, "v": -1}; break;} + default: {throw (new Error("ungültige Richtung '" + String(richtung) + "'")); break;} + } + } + + + /** + * @author kcf + */ + export function stelle_addieren(stelle1 : typ_stelle, stelle2 : typ_stelle) : typ_stelle + { + return {"u": (stelle1.u + stelle2.u), "v": (stelle1.v + stelle2.v)}; + } + + } + diff --git a/quelldatein/aufbau/symbol.ts b/quelldatein/aufbau/symbol.ts index badcc53..20d6d31 100644 --- a/quelldatein/aufbau/symbol.ts +++ b/quelldatein/aufbau/symbol.ts @@ -7,5 +7,21 @@ module mod_vtm_aufbau */ export type typ_symbol = int; + + /** + * @author kcf + */ + export var symbol_rot = 0; + export var symbol_gruen = 1; + + + /** + * @author kcf + */ + export function symbol_zu_string(symbol : typ_symbol) : string + { + return symbol.toFixed(0); + } + } diff --git a/quelldatein/aufbau/verwerfer.ts b/quelldatein/aufbau/verwerfer.ts index 75ed968..d4c6361 100644 --- a/quelldatein/aufbau/verwerfer.ts +++ b/quelldatein/aufbau/verwerfer.ts @@ -23,8 +23,7 @@ module mod_vtm_aufbau */ public verwenden(figur : klasse_figur) : void { - // TODO - console.warn("not implemented"); + figur.verwerfen(); } } diff --git a/quelldatein/aufbau/welt.ts b/quelldatein/aufbau/welt.ts index 09d7c82..68007c0 100644 --- a/quelldatein/aufbau/welt.ts +++ b/quelldatein/aufbau/welt.ts @@ -11,7 +11,7 @@ module mod_vtm_aufbau /** * @author kcf */ - private felder : mod_vtm_helfer.klasse_hashmap; + private felder : mod_vtm_helfer.klasse_hashmap; /** @@ -25,7 +25,7 @@ module mod_vtm_aufbau */ public constructor ( - felder : mod_vtm_helfer.klasse_hashmap = new mod_vtm_helfer.klasse_hashmap(position_hash), + felder : mod_vtm_helfer.klasse_hashmap = new mod_vtm_helfer.klasse_hashmap(stelle_hash), figur : klasse_figur = new klasse_figur() ) { @@ -37,24 +37,77 @@ module mod_vtm_aufbau /** * @author kcf */ - public feld_setzen(position : typ_position, aktor : schnittstelle_aktor) : void + public felder_lesen() : Array<{stelle : typ_stelle; aktor : schnittstelle_aktor;}> { - this.felder.setzen(position, aktor); + let felder : Array<{stelle : typ_stelle; aktor : schnittstelle_aktor;}> = []; + this.felder.iterieren + ( + (stelle, aktor) => felder.push({"stelle": stelle, "aktor": aktor}) + ) + ; + return felder; } /** * @author kcf */ - public fortfahren() : void + public figur_lesen() : klasse_figur { - let position : typ_position = this.figur.position_lesen(); - let aktor_ : schnittstelle_fehlermonade = this.felder.holen(position); + return this.figur; + } + + + /** + * @author kcf + */ + public feld_setzen(stelle : typ_stelle, aktor : schnittstelle_aktor) : void + { + this.felder.setzen(stelle, aktor); + } + + + /** + * @author kcf + */ + public fortfahren() : boolean + { + let stelle : typ_stelle = this.figur.stelle_lesen(); + let aktor_ : schnittstelle_fehlermonade = this.felder.holen(stelle); let aktor : schnittstelle_aktor = (aktor_.ist_schlicht() ? aktor_.lesen() : (new klasse_verwerfer())); - let ergebnis : any = aktor.verwenden(this.figur); - // - let position_ : typ_position = this.figur.position_lesen(); - console.info(JSON.stringify(position) + " -> " + JSON.stringify(position_)); + aktor.verwenden(this.figur); + let zustand : typ_zustand = this.figur.zustand_lesen(); + let ergebnis : boolean; + switch (zustand) + { + case zustand_tot: + { + console.info("-- tot"); + ergebnis = false; + break; + } + case zustand_normal: + { + // console.info("-- normal"); + ergebnis = true; + break; + } + case zustand_fertig: + { + console.info("-- fertig"); + ergebnis = false; + break; + } + default: + { + let meldung : string = "unbehandelter Zustand"; + throw (new Error(meldung)); + break; + } + } + if (ergebnis) + console.info(this.figur.zu_string()); + return ergebnis; } } diff --git a/quelldatein/aufbau/zustand.ts b/quelldatein/aufbau/zustand.ts new file mode 100644 index 0000000..2f7dea5 --- /dev/null +++ b/quelldatein/aufbau/zustand.ts @@ -0,0 +1,28 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export type typ_zustand = int; + + + /** + * @author kcf + */ + export var zustand_tot = -1; + export var zustand_normal = 0; + export var zustand_fertig = +1; + + + /** + * @author kcf + */ + export function zustand_zu_string(zustand : typ_zustand) : string + { + return zustand.toFixed(0); + } + + } + diff --git a/quelldatein/darstellung_steuerung/position.ts b/quelldatein/darstellung_steuerung/position.ts new file mode 100644 index 0000000..201ab66 --- /dev/null +++ b/quelldatein/darstellung_steuerung/position.ts @@ -0,0 +1,33 @@ + +module mod_vtm_darstellung_steuerung + { + + /** + * @author kcf + */ + export type typ_position = mod_vtm_helfer.typ_vektor; + + + /** + * @author kcf + */ + var position_basis1 : typ_position = mod_vtm_helfer.vektor_polar(0/6.0 * (2*Math.PI)); + var position_basis2 : typ_position = mod_vtm_helfer.vektor_polar(2/6.0 * (2*Math.PI)); + + + /** + * @author kcf + */ + export function position_von_stelle(stelle : mod_vtm_aufbau.typ_stelle) : typ_position + { + return ( + mod_vtm_helfer.vektor_addieren + ( + mod_vtm_helfer.vektor_skalieren(position_basis1, stelle.u), + mod_vtm_helfer.vektor_skalieren(position_basis2, stelle.v) + ) + ); + } + + } + diff --git a/quelldatein/darstellung_steuerung/svg.ts b/quelldatein/darstellung_steuerung/svg.ts new file mode 100644 index 0000000..f1ae661 --- /dev/null +++ b/quelldatein/darstellung_steuerung/svg.ts @@ -0,0 +1,36 @@ + +module mod_vtm_darstellung_steuerung + { + + /** + * @author kcf + */ + export function svg_wurzel + ( + von_x : float, + von_y : float, + bis_x : float, + bis_y : float, + hoehe : int = 500, + breite : int = 500, + kinder : Array = [] + ) : mod_vtm_helfer.schnittstelle_xmlknoten + { + return ( + new mod_vtm_helfer.klasse_xmlknoten_normal + ( + "svg", + { + "xmlns": "http://www.w3.org/2000/svg", + "xmlns:xlink": "http://www.w3.org/1999/xlink", + "width": breite.toFixed(0), + "height": hoehe.toFixed(0), + "viewBox": [von_x.toFixed(4), von_y.toFixed(4), (bis_x-von_x).toFixed(4), (bis_y-von_y).toFixed(4)].join(" "), + }, + kinder, + ) + ); + } + + } + diff --git a/quelldatein/darstellung_steuerung/welt.css b/quelldatein/darstellung_steuerung/welt.css new file mode 100644 index 0000000..9ddfbe7 --- /dev/null +++ b/quelldatein/darstellung_steuerung/welt.css @@ -0,0 +1,12 @@ +.feld + { + stroke: none; + fill: black; + } + +.figur + { + stroke: none; + fill: white; + } + diff --git a/quelldatein/darstellung_steuerung/welt.ts b/quelldatein/darstellung_steuerung/welt.ts new file mode 100644 index 0000000..c0b2c1d --- /dev/null +++ b/quelldatein/darstellung_steuerung/welt.ts @@ -0,0 +1,242 @@ + +module mod_vtm_darstellung_steuerung + { + + /** + * @author kcf + */ + const svg_float_praezission : int = 4; + + + /** + * @author kcf + */ + function symbol_zu_farbe(symbol : mod_vtm_aufbau.typ_symbol) : string + { + switch (symbol) + { + case 0: {return "hsl( 0, 50%, 50%)"; break;} + case 1: {return "hsl(120, 50%, 50%)"; break;} + default: {throw (new Error("unbehandeltes Symbol")); break;} + } + } + + + /** + * @author kcf + */ + export class klasse_web_welt + { + + /** + * @author kcf + */ + protected aufbau : mod_vtm_aufbau.klasse_welt; + + + /** + * @author kcf + */ + public constructor(aufbau : mod_vtm_aufbau.klasse_welt) + { + this.aufbau = aufbau; + } + + + /** + * @author kcf + */ + public darstellen() : mod_vtm_helfer.schnittstelle_xmlknoten + { + let kinder_welt : Array = []; + // felder + { + let kinder_felder : Array = []; + this.aufbau.felder_lesen().forEach + ( + ({"stelle": stelle, "aktor": aktor}) => + { + let kinder_feld : Array = []; + // rahmen + { + let knoten_rahmen : 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.5).toFixed(svg_float_praezission), + } + ) + ); + kinder_feld.push(knoten_rahmen); + } + // inhalt + { + if (aktor instanceof mod_vtm_aufbau.klasse_befoerderer) + { + let befoerderer : mod_vtm_aufbau.klasse_befoerderer = (aktor); + let richtung : mod_vtm_aufbau.typ_richtung = befoerderer.richtung_lesen(); + let knoten_pfeil = ( + new mod_vtm_helfer.klasse_xmlknoten_normal + ( + "path", + { + "class": "pfeil", + "d": "M +0.4 0.0 L -0.2 +0.1 L -0.2 -0.1 Z", + "style": ("stroke: none; fill: " + "hsl(0, 0%, 50%)" + ";"), + "transform": ("rotate(" + ((richtung/6.0) * 360).toFixed(svg_float_praezission) + ")"), + } + ) + ); + kinder_feld.push(knoten_pfeil); + } + else if (aktor instanceof mod_vtm_aufbau.klasse_schreiber) + { + let schreiber : mod_vtm_aufbau.klasse_schreiber = (aktor); + let richtung : mod_vtm_aufbau.typ_richtung = schreiber.richtung_lesen(); + let symbol : mod_vtm_aufbau.typ_symbol = schreiber.symbol_lesen(); + let knoten_pfeil = ( + new mod_vtm_helfer.klasse_xmlknoten_normal + ( + "path", + { + "class": "pfeil", + "d": "M +0.4 0.0 L -0.2 +0.1 L -0.2 -0.1 Z", + "style": ("stroke: none; fill: " + symbol_zu_farbe(symbol) + ";"), + "transform": ("rotate(" + ((richtung/6.0) * 360).toFixed(svg_float_praezission) + ")"), + } + ) + ); + kinder_feld.push(knoten_pfeil); + } + else if (aktor instanceof mod_vtm_aufbau.klasse_leser) + { + let leser : mod_vtm_aufbau.klasse_leser = (aktor); + let richtung : mod_vtm_aufbau.typ_richtung = leser.richtung_lesen(); + // ausgang ersatz + { + let knoten_pfeil = ( + new mod_vtm_helfer.klasse_xmlknoten_normal + ( + "path", + { + "class": "pfeil", + "d": "M +0.4 0.0 L +0.1 +0.1 L +0.1 -0.1 Z", + "style": ("stroke: none; fill: " + "hsl(0, 0%, 50%)" + ";"), + "transform": ("rotate(" + ((richtung/6.0) * 360).toFixed(svg_float_praezission) + ")"), + } + ) + ); + kinder_feld.push(knoten_pfeil); + } + // ausgang rot + { + let knoten_pfeil = ( + new mod_vtm_helfer.klasse_xmlknoten_normal + ( + "path", + { + "class": "pfeil", + "d": "M +0.4 0.0 L +0.1 +0.1 L +0.1 -0.1 Z", + "style": ("stroke: none; fill: " + symbol_zu_farbe(0) + ";"), + "transform": ("rotate(" + (((richtung+1)/6.0) * 360).toFixed(svg_float_praezission) + ")"), + } + ) + ); + kinder_feld.push(knoten_pfeil); + } + // ausgang gruen + { + let knoten_pfeil = ( + new mod_vtm_helfer.klasse_xmlknoten_normal + ( + "path", + { + "class": "pfeil", + "d": "M +0.4 0.0 L +0.1 +0.1 L +0.1 -0.1 Z", + "style": ("stroke: none; fill: " + symbol_zu_farbe(1) + ";"), + "transform": ("rotate(" + (((richtung-1)/6.0) * 360).toFixed(svg_float_praezission) + ")"), + } + ) + ); + kinder_feld.push(knoten_pfeil); + } + } + else if (aktor instanceof mod_vtm_aufbau.klasse_annehmer) + { + let annehmer : mod_vtm_aufbau.klasse_annehmer = (aktor); + // TODO + console.warn("not implemented"); + } + else + { + let meldung : string = ("unbehandelter Aktor-Typ"); + throw (new Error(meldung)); + } + } + let position : typ_position = position_von_stelle(stelle); + let knoten_feld : mod_vtm_helfer.schnittstelle_xmlknoten = ( + new mod_vtm_helfer.klasse_xmlknoten_normal + ( + "g", + { + "class": "feld", + "transform": ("translate(" + position.x.toFixed(svg_float_praezission) + ", " + position.y.toFixed(svg_float_praezission) + ")"), + }, + kinder_feld + ) + ); + kinder_felder.push(knoten_feld); + } + ) + ; + let knoten_felder : mod_vtm_helfer.schnittstelle_xmlknoten = ( + new mod_vtm_helfer.klasse_xmlknoten_normal + ( + "g", + { + "class": "felder", + }, + kinder_felder + ) + + ); + kinder_welt.push(knoten_felder); + } + // figur + { + let figur : mod_vtm_aufbau.klasse_figur = this.aufbau.figur_lesen(); + let position : typ_position = position_von_stelle(figur.stelle_lesen()); + let knoten_figur : mod_vtm_helfer.schnittstelle_xmlknoten = ( + new mod_vtm_helfer.klasse_xmlknoten_normal + ( + "circle", + { + "class": "figur", + "cx": position.x.toFixed(svg_float_praezission), + "cy": position.y.toFixed(svg_float_praezission), + "r": (0.2).toFixed(svg_float_praezission), + } + ) + ); + kinder_welt.push(knoten_figur); + } + let knoten_welt : mod_vtm_helfer.schnittstelle_xmlknoten = ( + new mod_vtm_helfer.klasse_xmlknoten_normal + ( + "g", + { + "class": "welt", + }, + kinder_welt + ) + ); + return knoten_welt; + } + + } + + } + diff --git a/quelldatein/helfer/hashmap.ts b/quelldatein/helfer/hashmap.ts index 2b42b67..466d2db 100644 --- a/quelldatein/helfer/hashmap.ts +++ b/quelldatein/helfer/hashmap.ts @@ -17,7 +17,7 @@ module mod_vtm_helfer /** * @author kcf */ - private speicher : {[hashwert : string] : typ_wert}; + private speicher : {[hashwert : string] : {schluessel : typ_schluessel; wert : typ_wert;}}; /** @@ -36,7 +36,7 @@ module mod_vtm_helfer public setzen(schluessel : typ_schluessel, wert : typ_wert) : void { let hashwert : string = this.hashfunction(schluessel); - this.speicher[hashwert] = wert; + this.speicher[hashwert] = {"schluessel": schluessel, "wert": wert}; } @@ -48,7 +48,7 @@ module mod_vtm_helfer let hashwert : string = this.hashfunction(schluessel); if (hashwert in this.speicher) { - let wert : typ_wert = this.speicher[hashwert]; + let wert : typ_wert = this.speicher[hashwert].wert; return (new klasse_schlicht(wert)); } else @@ -57,6 +57,23 @@ module mod_vtm_helfer } } + + /** + * @author kcf + */ + public iterieren(prozedur : (schluessel ?: typ_schluessel, wert ?: typ_wert)=>void) : void + { + Object.keys(this.speicher).forEach + ( + (hashwert) => + { + let paar : {schluessel : typ_schluessel; wert : typ_wert;} = this.speicher[hashwert]; + prozedur(paar.schluessel, paar.wert); + } + ) + ; + } + } } diff --git a/quelldatein/helfer/mathematik.ts b/quelldatein/helfer/mathematik.ts new file mode 100644 index 0000000..386169c --- /dev/null +++ b/quelldatein/helfer/mathematik.ts @@ -0,0 +1,23 @@ + +module mod_vtm_helfer + { + + /** + * @author kcf + */ + export function div(x : int, y : int) : int + { + return Math.floor(x/y); + } + + + /** + * @author kcf + */ + export function mod(x : int, y : int) : int + { + return (x - (y * div(x, y))); + } + + } + diff --git a/quelldatein/helfer/vektor.ts b/quelldatein/helfer/vektor.ts new file mode 100644 index 0000000..78ca338 --- /dev/null +++ b/quelldatein/helfer/vektor.ts @@ -0,0 +1,38 @@ + +module mod_vtm_helfer + { + + /** + * @author kcf + */ + export type typ_vektor = {x : float; y : float;}; + + + /** + * @author kcf + */ + export function vektor_polar(winkel : float, radius : float = 1) : typ_vektor + { + return {"x": (radius * Math.cos(winkel)), "y": (radius * Math.sin(winkel))}; + } + + + /** + * @author kcf + */ + export function vektor_skalieren(vektor : typ_vektor, faktor : float) : typ_vektor + { + return {"x": (vektor.x * faktor), "y": (vektor.y * faktor)}; + } + + + /** + * @author kcf + */ + export function vektor_addieren(vektor1 : typ_vektor, vektor2 : typ_vektor) : typ_vektor + { + return {"x": (vektor1.x + vektor2.x), "y": (vektor1.y + vektor2.y)}; + } + + } + diff --git a/quelldatein/helfer/xmlknoten.ts b/quelldatein/helfer/xmlknoten.ts new file mode 100644 index 0000000..4987bb7 --- /dev/null +++ b/quelldatein/helfer/xmlknoten.ts @@ -0,0 +1,143 @@ + +module mod_vtm_helfer + { + + /** + * @author kcf + */ + function einrueckung(tiefe : int, zeichen : string = "\t") : string + { + return ((tiefe === 0) ? "" : (zeichen + einrueckung(tiefe-1))); + } + + + /** + * @author kcf + */ + export interface schnittstelle_xmlknoten + { + + /** + * @author kcf + */ + darstellen(tiefe ?: int) : string; + + } + + + /** + * @author kcf + */ + export class klasse_xmlknoten_text + implements schnittstelle_xmlknoten + { + + /** + * @author kcf + */ + private inhalt : string; + + + /** + * @author kcf + */ + public constructor(inhalt : string) + { + this.inhalt = inhalt; + } + + + /** + * @author kcf + * @implementation + */ + public darstellen(tiefe : int = 0) : string + { + return this.inhalt; + } + + } + + + /** + * @author kcf + */ + export class klasse_xmlknoten_normal + implements schnittstelle_xmlknoten + { + + /** + * @author kcf + */ + private name : string; + + + /** + * @author kcf + */ + private attribute : {[schluessel : string] : string} = {}; + + + /** + * @author kcf + */ + private kinder : Array = []; + + + /** + * @author kcf + */ + public constructor(name : string, attribute : {[schluessel : string] : string} = {}, kinder : Array = []) + { + this.name = name; + this.attribute = attribute; + this.kinder = kinder; + } + + + /** + * @author kcf + * @implementation + */ + public darstellen(tiefe : int = 0) : string + { + let str : string = ""; + // anfang + { + let str_anfang : string = ""; + str_anfang += this.name; + // attribute + { + let str_attribute : string = ""; + Object.keys(this.attribute).forEach + ( + schluessel => + { + let wert : string = this.attribute[schluessel]; + str_attribute += (" " + schluessel + "=" + "\"" + wert + "\""); + } + ) + ; + str_anfang += str_attribute; + } + str_anfang = (einrueckung(tiefe) + "<" + str_anfang + ">" + "\n"); + str += str_anfang; + } + // kinder + { + this.kinder.forEach(kind => (str += kind.darstellen(tiefe+1))); + } + // ende + { + let str_ende : string = ""; + str_ende += this.name; + str_ende = (einrueckung(tiefe) + "<" + "/" + str_ende + ">" + "\n"); + str += str_ende; + } + return str; + } + + } + + } + diff --git a/quelldatein/test.ts b/quelldatein/test.ts index e128b35..f3c8ae1 100644 --- a/quelldatein/test.ts +++ b/quelldatein/test.ts @@ -7,9 +7,44 @@ module mod_vtm_test */ function haupt() : void { - let welt : mod_vtm_aufbau.klasse_welt = new mod_vtm_aufbau.klasse_welt(); - welt.feld_setzen({"u": 0, "v": 0}, new mod_vtm_aufbau.klasse_befoerderer(0)); - welt.fortfahren(); + let aufbau : mod_vtm_aufbau.klasse_welt = new mod_vtm_aufbau.klasse_welt(); + aufbau.feld_setzen({"u": 0, "v": 0}, new mod_vtm_aufbau.klasse_befoerderer(0)); + aufbau.feld_setzen({"u": +1, "v": 0}, new mod_vtm_aufbau.klasse_schreiber(0, 1)); + aufbau.feld_setzen({"u": +2, "v": 0}, new mod_vtm_aufbau.klasse_leser(0)); + aufbau.feld_setzen({"u": +2, "v": -1}, new mod_vtm_aufbau.klasse_annehmer()); + { + let darstellung_steuerung : mod_vtm_darstellung_steuerung.klasse_web_welt = new mod_vtm_darstellung_steuerung.klasse_web_welt(aufbau); + let xmlknoten : mod_vtm_helfer.schnittstelle_xmlknoten = mod_vtm_darstellung_steuerung.svg_wurzel + ( + -4, -4, + +4, +4, + 500, 500, + [ + new mod_vtm_helfer.klasse_xmlknoten_normal + ( + "style", + {}, + [ + new mod_vtm_helfer.klasse_xmlknoten_text(".feld {stroke: none; fill: black;}\n"), + new mod_vtm_helfer.klasse_xmlknoten_text(".figur {stroke: none; fill: white;}\n"), + // new mod_vtm_helfer.klasse_xmlknoten_text(".pfeil {stroke: none; fill: gray;}\n"), + ] + ) + , + darstellung_steuerung.darstellen() + ] + ) + ; + console.info(xmlknoten.darstellen()); + } + /* + while (true) + { + let weiter : boolean = aufbau.fortfahren(); + if (! weiter) + break; + } + */ }