vtm/quelldatein/manifestation/speicher/partie.ts

173 lines
4.8 KiB
TypeScript
Raw Normal View History

/*
* 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
{
2018-03-26 14:22:20 +02:00
export module mod_manifestation
{
2018-03-26 14:22:20 +02:00
2018-03-28 13:59:29 +02:00
export module mod_store
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
export module mod_round
2018-03-26 00:41:10 +02:00
{
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export type type_round =
{
2018-03-28 13:59:29 +02:00
model : mod_vtm.mod_model.mod_round.type_round;
}
2018-03-26 14:22:20 +02:00
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export function create
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
model : mod_vtm.mod_model.mod_round.type_round
2018-03-26 14:22:20 +02:00
)
2018-03-28 13:59:29 +02:00
: type_round
{
2018-03-26 14:22:20 +02:00
return {
2018-03-28 13:59:29 +02:00
"model": model
2018-03-26 14:22:20 +02:00
};
}
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export function create_erweitert
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
model : mod_vtm.mod_model.mod_round.type_round
2018-03-26 14:22:20 +02:00
)
2018-03-28 13:59:29 +02:00
: type_manifestation<mod_vtm.mod_model.mod_round.type_round>
2018-03-26 14:22:20 +02:00
{
return {
2018-03-28 13:59:29 +02:00
"kind": "store_round",
"data": create(model)
2018-03-26 14:22:20 +02:00
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
function view(round : type_round) : void
2018-03-26 14:22:20 +02:00
{
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
function bind(round : type_round) : void
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
mod_vtm.mod_model.mod_round.lauschen
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
round.model,
"aendrung_task",
(data) =>
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
// 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);
2018-03-26 14:22:20 +02:00
let key : string = ("vtm_" + id);
//
if (key in localStorage)
{
let item : string = localStorage.getItem(key);
2018-03-28 13:59:29 +02:00
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);
2018-03-26 14:22:20 +02:00
}
else
{
2018-03-28 13:59:29 +02:00
mod_vtm.mod_model.mod_round.world_clear(round.model);
// nothing tun
2018-03-26 14:22:20 +02:00
}
}
)
;
2018-03-28 13:59:29 +02:00
mod_vtm.mod_model.mod_round.lauschen
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
round.model,
"aendrung_world",
(data) =>
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
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);
2018-03-26 14:22:20 +02:00
let key : string = ("vtm_" + id);
//
2018-03-28 13:59:29 +02:00
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_);
2018-03-26 14:22:20 +02:00
localStorage.setItem(key, item);
}
)
;
2018-03-28 13:59:29 +02:00
mod_vtm.mod_model.mod_round.lauschen
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
round.model,
"aendrung_token",
(data) =>
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
// console.info("aendrung_token", data);
2018-03-26 14:22:20 +02:00
}
)
;
2018-03-28 13:59:29 +02:00
mod_vtm.mod_model.mod_round.lauschen
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
round.model,
"aendrung_mode",
(data) =>
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
// console.info("aendrung_mode", data);
2018-03-26 14:22:20 +02:00
}
)
;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
lib_trait.attend<signature_manifestation<mod_vtm.mod_model.mod_round.type_round, void>>
2018-03-28 12:09:27 +02:00
(
2018-03-28 13:59:29 +02:00
trait_manifestation,
"store_round",
2018-03-28 12:09:27 +02:00
{
2018-03-28 13:59:29 +02:00
"view": (manifestation) => view(manifestation.data),
"bind": (manifestation) => bind(manifestation.data),
2018-03-28 12:09:27 +02:00
}
)
2018-03-26 14:22:20 +02:00
;
2018-03-26 00:41:10 +02:00
}
2018-03-26 14:22:20 +02:00
}
}
}