From 010adc913652c99a33488c3c366251b3fa18ec3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 10:50:05 +0200 Subject: [PATCH] Alternative Implementation of Templatesystems --- .../gamesystems/SimpleTemplateGamesystem.ts | 54 +++++++++++++++++++ .../gamesystems/states/SimpleTemplateState.ts | 8 +++ .../transitions/SimpleTemplateTransition.ts | 9 ++++ 3 files changed, 71 insertions(+) create mode 100644 src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts create mode 100644 src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts create mode 100644 src/app/project/game-model/gamesystems/transitions/SimpleTemplateTransition.ts diff --git a/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts new file mode 100644 index 0000000..39863fe --- /dev/null +++ b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts @@ -0,0 +1,54 @@ +import {SimpleGamesystem} from "./SimpleGamesystem"; +import {SimpleTemplateState} from "./states/SimpleTemplateState"; +import {Gamesystem} from "./Gamesystem"; +import {SimpleTransition} from "./transitions/SimpleTransition"; +import {SimpleState} from "./states/SimpleState"; +import {SimpleTemplateTransition} from "./transitions/SimpleTemplateTransition"; + +export class SimpleTemplateGamesystem extends Gamesystem, SimpleTemplateTransition> { + + createState(label: string, description: string): SimpleState | undefined { + if(label == null) { + return undefined; + } + + if(description == null) { + description = ""; + } + + const state = new SimpleTemplateState(label, description); + if(this.states.find(s => s.stateLabel == label) == undefined) { + this.states.push(state); + return state; + } else { + return undefined + } + } + + createTransition(startingState: SimpleTemplateState, endingState: SimpleTemplateState): SimpleTemplateTransition | undefined { + if((startingState == null || endingState == null) || startingState === endingState) { + return undefined; + } + + const transition = new SimpleTemplateTransition(startingState, endingState); + if(this.transitions.find(t => t.startingState === startingState && t.endingState === endingState) == undefined) { + this.transitions.push(transition) + return transition; + } else { + startingState.removeOutgoingTransition(transition); + endingState.removeIncomingTransition(transition); + return undefined + } + } + + removeState(state: SimpleTemplateState): boolean { + const updatedStates = this.states.filter(s => s !== state); + const updated = updatedStates.length != this.states.length; + this.states = updatedStates; + + this.transitions = this.transitions.filter(t => t.startingState !== state && t.endingState !== state); + + return updated; + } + +} diff --git a/src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts b/src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts new file mode 100644 index 0000000..f10055c --- /dev/null +++ b/src/app/project/game-model/gamesystems/states/SimpleTemplateState.ts @@ -0,0 +1,8 @@ +import {SimpleState} from "./SimpleState"; +import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; + +export class SimpleTemplateState extends SimpleState { + + conditionMap: Map = new Map() + +} diff --git a/src/app/project/game-model/gamesystems/transitions/SimpleTemplateTransition.ts b/src/app/project/game-model/gamesystems/transitions/SimpleTemplateTransition.ts new file mode 100644 index 0000000..72d267a --- /dev/null +++ b/src/app/project/game-model/gamesystems/transitions/SimpleTemplateTransition.ts @@ -0,0 +1,9 @@ +import {SimpleTransition} from "./SimpleTransition"; +import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; +import {ScriptAccountAction} from "../actions/ScriptAccountAction"; + +export class SimpleTemplateTransition extends SimpleTransition { + + conditions: Map = new Map(); + actions: Map = new Map(); +}