From 40fb7c6ab7e0236c1c84370bffbd15c76d5814ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Tue, 6 Feb 2024 19:50:50 +0100 Subject: [PATCH] Remove SimpleStates from SimpleGamesystems --- .../gamesystems/SimpleGamesystem.spec.ts | 40 +++++++++++++++++++ .../gamesystems/ProductGamesystem.ts | 24 +++++++++++ .../gamesystems/SimpleGamesystem.ts | 17 +++++++- 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/e2e/game-model/gamesystems/SimpleGamesystem.spec.ts b/e2e/game-model/gamesystems/SimpleGamesystem.spec.ts index 504bc30..e916883 100644 --- a/e2e/game-model/gamesystems/SimpleGamesystem.spec.ts +++ b/e2e/game-model/gamesystems/SimpleGamesystem.spec.ts @@ -95,7 +95,47 @@ test.describe('Test SimpleGamesystem', () => { }) test("Remove SimpleState", async () => { + const gamesystem = new SimpleGamesystem("Test"); + const state1 = gamesystem.createState("State1", ""); + const state1_delete = gamesystem.removeState(state1); + expect(state1_delete).toBeTruthy(); + expect(gamesystem.states.includes(state1)).toBeFalsy(); + + let startingState = gamesystem.createState("Start", "End"); + let endingState = gamesystem.createState("End", ""); + let transition = gamesystem.createTransition(startingState, endingState); + let result = gamesystem.removeState(startingState); + expect(result).toBeTruthy(); + expect(gamesystem.states.includes(startingState)).toBeFalsy(); + expect(gamesystem.states.includes(endingState)).toBeTruthy(); + expect(gamesystem.transitions.length).toEqual(0); + + startingState = gamesystem.createState("Start"); + transition = gamesystem.createTransition(startingState, endingState); + gamesystem.removeState(endingState); + expect(result).toBeTruthy(); + expect(gamesystem.states.includes(startingState)).toBeTruthy(); + expect(gamesystem.states.includes(endingState)).toBeFalsy(); + expect(gamesystem.transitions.length).toEqual(0); + + endingState = gamesystem.createState("End"); + transition = gamesystem.createTransition(startingState, endingState); + const testingState = gamesystem.createState("TestingState", ""); + result = gamesystem.removeState(testingState); + expect(result).toBeTruthy(); + expect(gamesystem.transitions.includes(transition)).toBeTruthy(); + + const gamesystem2 = new SimpleGamesystem("test2"); + const state2 = gamesystem2.createState("Test", ""); + result = gamesystem.removeState(state2); + expect(result).toBeFalsy(); + + result = gamesystem.removeState(null); + expect(result).toBeFalsy(); + + result = gamesystem.removeState(undefined); + expect(result).toBeFalsy(); }) test("Remove SimpleTransition", async () => { diff --git a/src/app/game-model/gamesystems/ProductGamesystem.ts b/src/app/game-model/gamesystems/ProductGamesystem.ts index 7ae5ff5..10301eb 100644 --- a/src/app/game-model/gamesystems/ProductGamesystem.ts +++ b/src/app/game-model/gamesystems/ProductGamesystem.ts @@ -1,7 +1,31 @@ import {Gamesystem} from "./Gamesystem"; import {ProductState} from "./ProductState"; import {ProductTransition} from "./ProductTransition"; +import {State} from "./State"; +import {Transition} from "./Transition"; +import {SimpleState} from "./SimpleState"; export class ProductGamesystem extends Gamesystem { + innerGamesystems: Gamesystem, Transition>[] = []; + parentGamesystem: ProductGamesystem | undefined + + createState(label: string, description: string): ProductState | undefined { + return undefined; + } + + createTransition(startingState: ProductState, endingState: ProductState): ProductTransition | undefined { + return undefined; + } + + removeState(state: ProductState): boolean { + return false; + } + + removeInnerState(state: SimpleState) { + + } + + + } diff --git a/src/app/game-model/gamesystems/SimpleGamesystem.ts b/src/app/game-model/gamesystems/SimpleGamesystem.ts index 6654332..4021c93 100644 --- a/src/app/game-model/gamesystems/SimpleGamesystem.ts +++ b/src/app/game-model/gamesystems/SimpleGamesystem.ts @@ -1,7 +1,15 @@ import {Gamesystem} from "./Gamesystem"; import {SimpleState} from "./SimpleState"; import {SimpleTransition} from "./SimpleTransition"; +import {State} from "./State"; +import {Transition} from "./Transition"; +import {ProductState} from "./ProductState"; +import {ProductTransition} from "./ProductTransition"; +import {ProductGamesystem} from "./ProductGamesystem"; export class SimpleGamesystem extends Gamesystem { + + parentGamesystem: ProductGamesystem | undefined + createState(label: string, description: string): SimpleState | undefined { if(label == null) { return undefined; @@ -24,6 +32,7 @@ export class SimpleGamesystem extends Gamesystem if((startingState == null || endingState == null) || startingState === endingState) { return undefined; } + const transition = new SimpleTransition(startingState, endingState); if(this.transitions.find(t => t.startingState === startingState && t.endingState === endingState) == undefined) { this.transitions.push(transition) @@ -38,7 +47,13 @@ export class SimpleGamesystem extends Gamesystem removeState(state: SimpleState): boolean { - return false; + 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; }