Remove SimpleStates from SimpleGamesystems
All checks were successful
E2E Testing / test (push) Successful in 1m25s

This commit is contained in:
Sebastian Böckelmann 2024-02-06 19:50:50 +01:00
parent d5f593a824
commit 40fb7c6ab7
3 changed files with 80 additions and 1 deletions

View File

@ -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 () => {

View File

@ -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<ProductState, ProductTransition> {
innerGamesystems: Gamesystem<State<any>, Transition<any>>[] = [];
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) {
}
}

View File

@ -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<SimpleState, SimpleTransition> {
parentGamesystem: ProductGamesystem | undefined
createState(label: string, description: string): SimpleState | undefined {
if(label == null) {
return undefined;
@ -24,6 +32,7 @@ export class SimpleGamesystem extends Gamesystem<SimpleState, SimpleTransition>
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<SimpleState, SimpleTransition>
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;
}