Datastructure for Gamesystems and Create and Remove SimpleStates and Transitions
All checks were successful
E2E Testing / test (push) Successful in 1m24s

This commit is contained in:
Sebastian Böckelmann 2024-02-05 20:44:39 +01:00
parent 0dd87fe81c
commit d5f593a824
11 changed files with 252 additions and 7 deletions

View File

@ -0,0 +1,104 @@
import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright';
import { test, expect } from '@playwright/test';
import * as PATH from 'path';
import {GameModel} from "../../../src/app/game-model/GameModel";
import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem";
import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount";
import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType";
import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem";
import exp = require("node:constants");
import {end} from "electron-debug";
test.describe('Test SimpleGamesystem', () => {
test("Create SimpleState", async () => {
const gamesystem = new SimpleGamesystem();
let state = gamesystem.createState("Test", "Test2");
expect(state.stateLabel).toEqual("Test");
expect(state.stateDescription).toEqual("Test2");
expect(state.incomingTransitions.length).toEqual(0);
expect(state.outgoingTransitions.length).toEqual(0);
expect(gamesystem.states.includes(state)).toBeTruthy();
state = gamesystem.createState(null, null);
expect(state).toBeUndefined();
expect(gamesystem.states.includes(state)).toBeFalsy();
state = gamesystem.createState(null, "test2");
expect(state).toBeUndefined()
expect(gamesystem.states.includes(state)).toBeFalsy();
state = gamesystem.createState("test2", null);
expect(state).toBeDefined();
expect(state.stateLabel).toEqual("test2");
expect(state.stateDescription).toEqual("");
expect(gamesystem.states.includes(state)).toBeTruthy();
state = gamesystem.createState(undefined, "State");
expect(state).toBeUndefined();
expect(gamesystem.states.includes(state)).toBeFalsy();
state = gamesystem.createState("Test3", undefined);
expect(state).toBeDefined();
expect(state.stateLabel).toEqual("Test3");
expect(state.stateDescription).toEqual("");
expect(gamesystem.states.includes(state)).toBeTruthy();
state = gamesystem.createState("", "");
expect(state).toBeDefined();
expect(state.stateLabel).toEqual("");
expect(state.stateDescription).toEqual("");
expect(gamesystem.states.includes(state)).toBeTruthy();
state = gamesystem.createState("Test3", "");
expect(state).toBeUndefined();
expect(gamesystem.states.includes(state)).toBeFalsy();
})
test("Create SimpleTransition", async () => {
const gamesystem = new SimpleGamesystem();
const startingState = gamesystem.createState("StartingState", "")!;
const endingState = gamesystem.createState("EndingState", "")!
let transition = gamesystem.createTransition(startingState, endingState);
expect(transition).toBeDefined();
expect(transition.startingState).toEqual(startingState);
expect(transition.endingState).toEqual(endingState);
expect(startingState.outgoingTransitions.includes(transition)).toBeTruthy();
expect(endingState.incomingTransitions.includes(transition)).toBeTruthy();
expect(gamesystem.transitions.includes(transition)).toBeTruthy();
transition = gamesystem.createTransition(null, null);
expect(transition).toBeUndefined();
transition = gamesystem.createTransition(null, endingState);
expect(transition).toBeUndefined();
transition = gamesystem.createTransition(undefined, undefined);
expect(transition).toBeUndefined();
transition = gamesystem.createTransition(undefined, endingState);
expect(transition).toBeUndefined();
transition = gamesystem.createTransition(startingState, null);
expect(transition).toBeUndefined();
transition = gamesystem.createTransition(startingState, undefined);
expect(transition).toBeUndefined();
transition = gamesystem.createTransition(startingState, startingState);
expect(transition).toBeUndefined();
transition = gamesystem.createTransition(startingState, endingState);
expect(transition).toBeUndefined();
})
test("Remove SimpleState", async () => {
})
test("Remove SimpleTransition", async () => {
})
});

View File

@ -4,7 +4,7 @@ import {ScriptAccount} from "./scriptAccounts/ScriptAccount";
export class GameModel { export class GameModel {
private readonly _gameModelName: string private readonly _gameModelName: string
private _gamesystems: Gamesystem[] = []; private _gamesystems: Gamesystem<any, any>[] = [];
private _scriptAccounts: ScriptAccount[] = []; private _scriptAccounts: ScriptAccount[] = [];
constructor(gameModelName: string) { constructor(gameModelName: string) {
@ -13,22 +13,20 @@ export class GameModel {
get gameModelName(): string { get gameModelName(): string {
return this._gameModelName; return this._gameModelName;
} }
get gamesystems(): Gamesystem<any, any>[] {
get gamesystems(): Gamesystem[] {
return this._gamesystems; return this._gamesystems;
} }
get scriptAccounts(): ScriptAccount[] { get scriptAccounts(): ScriptAccount[] {
return this._scriptAccounts; return this._scriptAccounts;
} }
addGamesystem(gamesystem: Gamesystem) { addGamesystem(gamesystem: Gamesystem<any, any>) {
if(!this.gamesystems.includes(gamesystem)) { if(!this.gamesystems.includes(gamesystem)) {
this._gamesystems.push(gamesystem); this._gamesystems.push(gamesystem);
} }
} }
removeGamesystem(gamesystem : Gamesystem) { removeGamesystem(gamesystem : Gamesystem<any, any>) {
this._gamesystems = this._gamesystems.filter(g => g !== gamesystem); this._gamesystems = this._gamesystems.filter(g => g !== gamesystem);
} }

View File

@ -1,7 +1,28 @@
export class Gamesystem { export abstract class Gamesystem<S, T> {
gamesystemName: string gamesystemName: string
gamesystemDescription: string
states: S[] = [];
transitions: T[] = [];
constructor(gamesystemName: string) { constructor(gamesystemName: string) {
this.gamesystemName = gamesystemName; this.gamesystemName = gamesystemName;
this.gamesystemDescription = "";
}
abstract createState(label: string, description: string): S|undefined;
abstract createTransition(startingState: S, endingState: S): T|undefined;
abstract removeState(state: S): boolean;
removeTransition(transition: T): boolean {
const updatedTransitions = this.transitions.filter(t => t !== transition);
if(updatedTransitions.length == this.transitions.length) {
return false;
}
this.transitions = updatedTransitions;
return true;
} }

View File

@ -0,0 +1,7 @@
import {Gamesystem} from "./Gamesystem";
import {ProductState} from "./ProductState";
import {ProductTransition} from "./ProductTransition";
export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> {
}

View File

@ -0,0 +1,7 @@
import {ProductTransition} from "./ProductTransition";
import {State} from "./State";
import {SimpleState} from "./SimpleState";
export class ProductState extends State<ProductTransition> {
innerStates: SimpleState[] = [];
}

View File

@ -0,0 +1,6 @@
import {Transition} from "./Transition";
import {ProductState} from "./ProductState";
export class ProductTransition extends Transition<ProductState> {
}

View File

@ -0,0 +1,45 @@
import {Gamesystem} from "./Gamesystem";
import {SimpleState} from "./SimpleState";
import {SimpleTransition} from "./SimpleTransition";
export class SimpleGamesystem extends Gamesystem<SimpleState, SimpleTransition> {
createState(label: string, description: string): SimpleState | undefined {
if(label == null) {
return undefined;
}
if(description == null) {
description = "";
}
const state = new SimpleState(label, description);
if(this.states.find(s => s.stateLabel == label) == undefined) {
this.states.push(state);
return state;
} else {
return undefined
}
}
createTransition(startingState: SimpleState, endingState: SimpleState): SimpleTransition | undefined{
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)
return transition;
} else {
startingState.removeOutgoingTransition(transition);
endingState.removeIncomingTransition(transition);
return undefined
}
}
removeState(state: SimpleState): boolean {
return false;
}
}

View File

@ -0,0 +1,6 @@
import {State} from "./State";
import {SimpleTransition} from "./SimpleTransition";
export class SimpleState extends State<SimpleTransition> {
}

View File

@ -0,0 +1,6 @@
import {SimpleState} from "./SimpleState";
import {Transition} from "./Transition";
export class SimpleTransition extends Transition<SimpleState> {
}

View File

@ -0,0 +1,30 @@
import {Transition} from "./Transition";
export abstract class State<T extends Transition<any>> {
stateLabel: string = "";
stateDescription: string = "";
incomingTransitions: T[] =[];
outgoingTransitions: T[] =[];
constructor(stateLabel: string, stateDescription: string) {
this.stateLabel = stateLabel;
this.stateDescription = stateDescription;
}
addIncomingTransition(transition: T) {
this.incomingTransitions.push(transition);
}
addOutgoingTransition(transition: T) {
this.outgoingTransitions.push(transition);
}
removeIncomingTransition(transition: T) {
}
removeOutgoingTransition(transition: T) {
}
}

View File

@ -0,0 +1,15 @@
import {State} from "./State";
export abstract class Transition<S extends State<any>> {
startingState: S
endingState: S
constructor(startingState: S, endingState: S) {
this.startingState = startingState;
this.endingState = endingState;
this.startingState.addOutgoingTransition(this);
this.endingState.addIncomingTransition(this);
}
}