/* * Verrückte Turing-Maschinen — A turing complete game * Copyright (C) 2016-2018 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_writer { /** * @author kcf */ let kind : string = "writer"; /** * @author kcf */ export type type_writer = { direction : mod_direction.type_direction; symbol : mod_symbol.type_symbol; } ; /** * @author kcf */ function create ( direction : mod_direction.type_direction, symbol : mod_symbol.type_symbol ) : type_writer { return { "direction": direction, "symbol": symbol, }; } /** * @author kcf */ export function create_extended ( direction : mod_direction.type_direction, symbol : mod_symbol.type_symbol ) : mod_actuator.type_actuator { return lib_call.wrap(kind, create(direction, symbol)); } /** * @author kcf */ function example ( ) : type_writer { return create(0, 0); } /** * @author kcf */ export function direction_read ( writer : type_writer ) : mod_direction.type_direction { return writer.direction; } /** * @author kcf */ export function symbol_read ( writer : type_writer ) : mod_symbol.type_symbol { return writer.symbol; } /** * @author kcf */ function rotate ( writer : type_writer, inkrement : int = +1 ) : void { writer.direction = mod_direction.add(writer.direction, inkrement); } /** * @author kcf */ function use ( writer : type_writer, token : mod_token.type_token ) : void { mod_token.write(token, writer.symbol); mod_token.move(token, writer.direction); } /** * @author kcf */ function export_ ( writer : type_writer ) : any { return { "direction": mod_direction.export_(writer.direction), "symbol": mod_symbol.export_(writer.symbol), }; } /** * @author kcf */ function import_ ( raw : any ) : type_writer { return ( create ( mod_direction.import_(raw["direction"]), mod_symbol.import_(raw["symbol"]) ) ); } /** * @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"])), } ) ; } } } }