/* * 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 { export module mod_model { export module mod_actuator { export module mod_erzeuger { /** * @author kcf */ let kind : string = "erzeuger"; /** * @author kcf */ export type type_erzeuger = { direction : mod_direction.type_direction; } ; /** * @author kcf */ function create ( direction : mod_direction.type_direction ) : type_erzeuger { return { "direction": direction, }; } /** * @author kcf */ export function create_actuator ( direction : mod_direction.type_direction ) : mod_actuator.type_actuator { return lib_call.wrap(kind, create(direction)); } /** * @author kcf */ function example ( ) : type_erzeuger { return create(0); } /** * @author kcf */ export function direction_read ( erzeuger : type_erzeuger ) : mod_direction.type_direction { return erzeuger.direction; } /** * @author kcf */ function rotate ( erzeuger : type_erzeuger, inkrement : int = +1 ) : void { erzeuger.direction = mod_direction.add(erzeuger.direction, inkrement); } /** * @author kcf */ function use ( erzeuger : type_erzeuger, token : mod_token.type_token ) : void { mod_token.move(token, erzeuger.direction); } /** * @author kcf */ function export_ ( erzeuger : type_erzeuger ) : any { return { "direction": mod_direction.export_(erzeuger.direction), }; } /** * @author kcf */ function import_ ( raw : any ) : type_erzeuger { return ( create ( mod_direction.import_(raw["direction"]) ) ); } /** * @author kcf */ lib_trait.attend ( trait_actuator, kind, { "example": () => lib_call.wrap(kind, example()), "rotate": (actuator, inkrement) => rotate(lib_call.unwrap(actuator), inkrement), "use": (actuator, token) => use(lib_call.unwrap(actuator), token), "export": (actuator) => ({"kind": kind, "data": export_(actuator.data)}), "import": (raw) => lib_call.wrap(kind, import_(raw["data"])), } ) ; } } } }