/* * 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_task { /** * @author kcf */ export type type_task = lib_call.type_complex; /** * @author kcf */ var _liste : Array = []; /** * @author kcf */ export function id ( task : type_task ) : string { return ( lib_call.distinguish ( task, { "acceptortask": (data) => mod_acceptortask.id(data), "transducertask": (data) => mod_transducertask.id(data), } ) ); } /** * @author kcf */ export function title ( task : type_task ) : string { return ( lib_call.distinguish ( task, { "acceptortask": (data) => mod_acceptortask.title(data), "transducertask": (data) => mod_transducertask.title(data), } ) ); } /** * @author kcf */ export function text ( task : type_task ) : string { return ( lib_call.distinguish ( task, { "acceptortask": (data) => mod_acceptortask.text(data), "transducertask": (data) => mod_transducertask.text(data), } ) ); } /** * @author kcf */ export function tests ( task : type_task ) : Array { return ( lib_call.distinguish> ( task, { "acceptortask": (data) => ( mod_acceptortask.tests(data) .map(data_ => ({"kind": "acceptortest", "data": data_})) ), "transducertask": (data) => ( mod_transducertask.tests(data) .map(data_ => ({"kind": "transducertest", "data": data_})) ), } ) ); } /** * @author kcf */ export function import_(task_raw : any) : type_task { switch (task_raw["kind"]) { case "acceptor": { return { "kind": "acceptortask", "data": ( mod_acceptortask.create ( task_raw["id"], lib_translate.get(["tasks", task_raw["id"], "title"].join(".")), lib_translate.get(["tasks", task_raw["id"], "text"].join(".")), task_raw["parameter"]["tests"].map ( test_raw => ( mod_acceptortest.create ( test_raw["input"], test_raw["accept"] ) ) ) ) ) }; break; } case "transducer": { return { "kind": "transducertask", "data": ( mod_transducertask.create ( task_raw["id"], lib_translate.get(["tasks", task_raw["id"], "title"].join(".")), lib_translate.get(["tasks", task_raw["id"], "text"].join(".")), task_raw["parameter"]["tests"].map ( test_raw => ( mod_transducertest.create ( test_raw["input"], test_raw["output"] ) ) ) ) ) }; break; } default: { let message : string = "unbehandelte Art '" + task_raw["kind"] + "'"; throw (new Error(message)); break; } } } /** * @author kcf */ export function registrieren(task : type_task) : void { _liste.push(task); } /** * @author kcf */ export function get(index : int) : type_task { return _liste[index]; } } } }