186 lines
4.3 KiB
TypeScript
186 lines
4.3 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_model
|
|
{
|
|
|
|
export module mod_actuator
|
|
{
|
|
|
|
export module mod_befoerderer
|
|
{
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
let kind : string = "befoerderer";
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export type type_befoerderer =
|
|
{
|
|
direction : mod_direction.type_direction;
|
|
}
|
|
;
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function create
|
|
(
|
|
direction : mod_direction.type_direction
|
|
)
|
|
: type_befoerderer
|
|
{
|
|
return {
|
|
"direction": direction,
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function create_actuator
|
|
(
|
|
direction : mod_direction.type_direction
|
|
)
|
|
: mod_actuator.type_actuator
|
|
{
|
|
return lib_call.wrap(kind, create(direction));
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function example
|
|
(
|
|
)
|
|
: type_befoerderer
|
|
{
|
|
return create(0);
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function direction_read
|
|
(
|
|
befoerderer : type_befoerderer
|
|
)
|
|
: mod_direction.type_direction
|
|
{
|
|
return befoerderer.direction;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function rotate
|
|
(
|
|
befoerderer : type_befoerderer,
|
|
inkrement : int = +1
|
|
)
|
|
: void
|
|
{
|
|
befoerderer.direction = mod_direction.add(befoerderer.direction, inkrement);
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function use
|
|
(
|
|
befoerderer : type_befoerderer,
|
|
token : mod_token.type_token
|
|
)
|
|
: void
|
|
{
|
|
mod_token.move(token, befoerderer.direction);
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function export_
|
|
(
|
|
befoerderer : type_befoerderer
|
|
)
|
|
: any
|
|
{
|
|
return {
|
|
"direction": mod_direction.export_(befoerderer.direction),
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function import_
|
|
(
|
|
befoerderer_ : any
|
|
)
|
|
: type_befoerderer
|
|
{
|
|
return (
|
|
create
|
|
(
|
|
mod_direction.import_(befoerderer_["direction"])
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
lib_trait.attend<signature_actuator>
|
|
(
|
|
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"])),
|
|
}
|
|
)
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|