vtm/quelldatein/aufbau/aktoren/leser.ts

148 lines
3.7 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 export function aktor_leser_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 export function aktor_leser_License for more details.
*
* You should have received a copy of the GNU General export function aktor_leser_License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
module mod_vtm_aufbau
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
export type typ_aktor_leser =
{
"richtung": typ_richtung,
"symbol_links": typ_symbol,
"symbol_rechts": typ_symbol,
}
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function aktor_leser_erstellen(richtung : typ_richtung = 0, symbol_links : typ_symbol = 0, symbol_rechts : typ_symbol = 1) : typ_aktor_leser
{
return {
"richtung": richtung,
"symbol_links": symbol_links,
"symbol_rechts": symbol_rechts,
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function aktor_leser_richtung_lesen(aktor_leser : typ_aktor_leser) : typ_richtung
{
return aktor_leser.richtung;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function aktor_leser_symbol_links_lesen(aktor_leser : typ_aktor_leser) : typ_symbol
{
return aktor_leser.symbol_links;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function aktor_leser_symbol_rechts_lesen(aktor_leser : typ_aktor_leser) : typ_symbol
{
return aktor_leser.symbol_rechts;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function aktor_leser_drehen(aktor_leser : typ_aktor_leser, inkrement : int = +1) : void
{
aktor_leser.richtung = richtung_addieren(aktor_leser.richtung, inkrement);
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function aktor_leser_verwenden(aktor_leser : typ_aktor_leser, figur : typ_figur) : void
{
let symbol_ : schnittstelle_fehlermonade<typ_symbol> = figur_lesen(figur);
let summand : typ_richtung;
if (symbol_.ist_schlicht())
{
let symbol : typ_symbol = symbol_.lesen();
if (symbol === aktor_leser.symbol_links)
{
figur_schieben(figur);
summand = +2;
}
else if (symbol === aktor_leser.symbol_rechts)
{
figur_schieben(figur);
summand = -2;
}
else
{
summand = 0;
}
}
else
{
summand = 0;
}
let richtung : typ_richtung = richtung_addieren(aktor_leser.richtung, summand);
figur_bewegen(figur, richtung);
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function aktor_leser_exportieren(aktor_leser : typ_aktor_leser) : any
{
return {
"richtung": richtung_exportieren(aktor_leser.richtung),
"symbol_links": symbol_exportieren(aktor_leser.symbol_links),
"symbol_rechts": symbol_exportieren(aktor_leser.symbol_rechts),
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function aktor_leser_importieren(roh : any) : typ_aktor_leser
{
return (
aktor_leser_erstellen
(
richtung_importieren(roh["richtung"]),
symbol_importieren(roh["symbol_links"]),
symbol_importieren(roh["symbol_rechts"])
)
);
}
}