From 92fa6926412ffcdb781a8d38806f18d0493f3a6b 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 | 80 +++++++++++-------- .../gamesystems/states/SimpleTemplateState.ts | 8 ++ .../transitions/SimpleTemplateTransition.ts | 9 +++ 3 files changed, 63 insertions(+), 34 deletions(-) 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 index 61184e4..39863fe 100644 --- a/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts +++ b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts @@ -1,42 +1,54 @@ -import { SimpleGamesystem } from "./SimpleGamesystem"; -import { ScriptAccountAction } from "./actions/ScriptAccountAction"; -import { ScriptAccountCondition } from "./conditions/ScriptAccountCondition"; -import { SimpleState } from "./states/SimpleState"; -import { SimpleTransition } from "./transitions/SimpleTransition"; +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 SimpleGamesystem { - referenceSystem: SimpleGamesystem +export class SimpleTemplateGamesystem extends Gamesystem, SimpleTemplateTransition> { - constructor(referenceSystem: SimpleGamesystem) { - super(referenceSystem.componentName, referenceSystem.componentDescription) - this.referenceSystem = referenceSystem; + createState(label: string, description: string): SimpleState | undefined { + if(label == null) { + return undefined; + } - this.referenceSystem.states.forEach(state => { - const templateState = new SimpleState(state.stateLabel, state.stateDescription) - templateState.initial = state.initial; - templateState.conditions = state.conditions.map(condition => ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue, condition.maxValue)!) + if(description == null) { + description = ""; + } - this.states.push(templateState); - }); - - this.referenceSystem.transitions.forEach(transition => { - const startingState = this.findStateByStateLabel(transition.startingState.stateLabel); - const endingState = this.findStateByStateLabel(transition.endingState.stateLabel); - - const templateTransition = new SimpleTransition(startingState!, endingState!) - - templateTransition.scriptAccountConditions = transition.scriptAccountConditions.map(condition => - ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue, condition.maxValue)!) - - templateTransition.scriptAccountActions = transition.scriptAccountActions.map(action => { - return new ScriptAccountAction(action.scriptAccount, action.changingValue); - }); - - this.transitions.push(templateTransition); - }) - - this.referenceSystem.addTemplateSystem(this) + 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(); +}