vtm/quelldatein/manifestation/speicher/partie.ts
2018-03-28 12:09:27 +02:00

173 lines
5 KiB
TypeScript

/*
* 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/>.
*/
module mod_vtm
{
export module mod_manifestation
{
export module mod_speicher
{
export module mod_partie
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
export type typ_partie =
{
aufbau : mod_vtm.mod_aufbau.mod_partie.typ_partie;
}
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function erstellen
(
aufbau : mod_vtm.mod_aufbau.mod_partie.typ_partie
)
: typ_partie
{
return {
"aufbau": aufbau
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function erstellen_erweitert
(
aufbau : mod_vtm.mod_aufbau.mod_partie.typ_partie
)
: typ_manifestation<mod_vtm.mod_aufbau.mod_partie.typ_partie>
{
return {
"art": "speicher_partie",
"angaben": erstellen(aufbau)
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function darstellen(partie : typ_partie) : void
{
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function binden(partie : typ_partie) : void
{
mod_vtm.mod_aufbau.mod_partie.lauschen
(
partie.aufbau,
"aenderung_aufgabe",
(angaben) =>
{
// console.info("aenderung_aufgabe", angaben);
let aufgabe : mod_vtm.mod_aufbau.mod_aufgabe.typ_aufgabe = mod_vtm.mod_aufbau.mod_partie.aufgabe_lesen(partie.aufbau);
let id : string = mod_vtm.mod_aufbau.mod_aufgabe.id(aufgabe);
let key : string = ("vtm_" + id);
//
if (key in localStorage)
{
let item : string = localStorage.getItem(key);
let welt_ : any = JSON.parse(item);
let welt : mod_vtm.mod_aufbau.mod_welt.typ_welt = mod_vtm.mod_aufbau.mod_welt.importieren(welt_);
mod_vtm.mod_aufbau.mod_partie.welt_setzen(partie.aufbau, welt, false);
}
else
{
mod_vtm.mod_aufbau.mod_partie.welt_leeren(partie.aufbau);
// nichts tun
}
}
)
;
mod_vtm.mod_aufbau.mod_partie.lauschen
(
partie.aufbau,
"aenderung_welt",
(angaben) =>
{
let aufgabe : mod_vtm.mod_aufbau.mod_aufgabe.typ_aufgabe = mod_vtm.mod_aufbau.mod_partie.aufgabe_lesen(partie.aufbau);
let id : string = mod_vtm.mod_aufbau.mod_aufgabe.id(aufgabe);
let key : string = ("vtm_" + id);
//
let welt : mod_vtm.mod_aufbau.mod_welt.typ_welt = mod_vtm.mod_aufbau.mod_partie.welt_lesen(partie.aufbau);
let welt_ : any = mod_vtm.mod_aufbau.mod_welt.exportieren(welt);
let item : string = JSON.stringify(welt_);
localStorage.setItem(key, item);
}
)
;
mod_vtm.mod_aufbau.mod_partie.lauschen
(
partie.aufbau,
"aenderung_figur",
(angaben) =>
{
// console.info("aenderung_figur", angaben);
}
)
;
mod_vtm.mod_aufbau.mod_partie.lauschen
(
partie.aufbau,
"aenderung_modus",
(angaben) =>
{
// console.info("aenderung_modus", angaben);
}
)
;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
lib_brauch.umsetzen<signatur_manifestation<mod_vtm.mod_aufbau.mod_partie.typ_partie, void>>
(
brauch_manifestation,
"speicher_partie",
{
"darstellen": (manifestation) => darstellen(manifestation.angaben),
"binden": (manifestation) => binden(manifestation.angaben),
}
)
;
}
}
}
}