vtm/quelldatein/manifestation/speicher/partie.ts
Christian Fraß 3193117543 save
2018-03-28 13:59:29 +02:00

173 lines
4.8 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_store
{
export module mod_round
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
export type type_round =
{
model : mod_vtm.mod_model.mod_round.type_round;
}
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function create
(
model : mod_vtm.mod_model.mod_round.type_round
)
: type_round
{
return {
"model": model
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function create_erweitert
(
model : mod_vtm.mod_model.mod_round.type_round
)
: type_manifestation<mod_vtm.mod_model.mod_round.type_round>
{
return {
"kind": "store_round",
"data": create(model)
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function view(round : type_round) : void
{
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function bind(round : type_round) : void
{
mod_vtm.mod_model.mod_round.lauschen
(
round.model,
"aendrung_task",
(data) =>
{
// console.info("aendrung_task", data);
let task : mod_vtm.mod_model.mod_task.type_task = mod_vtm.mod_model.mod_round.task_read(round.model);
let id : string = mod_vtm.mod_model.mod_task.id(task);
let key : string = ("vtm_" + id);
//
if (key in localStorage)
{
let item : string = localStorage.getItem(key);
let world_ : any = JSON.parse(item);
let world : mod_vtm.mod_model.mod_world.type_world = mod_vtm.mod_model.mod_world.import_(world_);
mod_vtm.mod_model.mod_round.world_set(round.model, world, false);
}
else
{
mod_vtm.mod_model.mod_round.world_clear(round.model);
// nothing tun
}
}
)
;
mod_vtm.mod_model.mod_round.lauschen
(
round.model,
"aendrung_world",
(data) =>
{
let task : mod_vtm.mod_model.mod_task.type_task = mod_vtm.mod_model.mod_round.task_read(round.model);
let id : string = mod_vtm.mod_model.mod_task.id(task);
let key : string = ("vtm_" + id);
//
let world : mod_vtm.mod_model.mod_world.type_world = mod_vtm.mod_model.mod_round.world_read(round.model);
let world_ : any = mod_vtm.mod_model.mod_world.export_(world);
let item : string = JSON.stringify(world_);
localStorage.setItem(key, item);
}
)
;
mod_vtm.mod_model.mod_round.lauschen
(
round.model,
"aendrung_token",
(data) =>
{
// console.info("aendrung_token", data);
}
)
;
mod_vtm.mod_model.mod_round.lauschen
(
round.model,
"aendrung_mode",
(data) =>
{
// console.info("aendrung_mode", data);
}
)
;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
lib_trait.attend<signature_manifestation<mod_vtm.mod_model.mod_round.type_round, void>>
(
trait_manifestation,
"store_round",
{
"view": (manifestation) => view(manifestation.data),
"bind": (manifestation) => bind(manifestation.data),
}
)
;
}
}
}
}