Datastructure for Gamesystems and Create and Remove SimpleStates and Transitions
All checks were successful
E2E Testing / test (push) Successful in 1m24s
All checks were successful
E2E Testing / test (push) Successful in 1m24s
This commit is contained in:
parent
0dd87fe81c
commit
d5f593a824
104
e2e/game-model/gamesystems/SimpleGamesystem.spec.ts
Normal file
104
e2e/game-model/gamesystems/SimpleGamesystem.spec.ts
Normal 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 () => {
|
||||
|
||||
})
|
||||
});
|
@ -4,7 +4,7 @@ import {ScriptAccount} from "./scriptAccounts/ScriptAccount";
|
||||
export class GameModel {
|
||||
private readonly _gameModelName: string
|
||||
|
||||
private _gamesystems: Gamesystem[] = [];
|
||||
private _gamesystems: Gamesystem<any, any>[] = [];
|
||||
private _scriptAccounts: ScriptAccount[] = [];
|
||||
|
||||
constructor(gameModelName: string) {
|
||||
@ -13,22 +13,20 @@ export class GameModel {
|
||||
get gameModelName(): string {
|
||||
return this._gameModelName;
|
||||
}
|
||||
|
||||
|
||||
get gamesystems(): Gamesystem[] {
|
||||
get gamesystems(): Gamesystem<any, any>[] {
|
||||
return this._gamesystems;
|
||||
}
|
||||
get scriptAccounts(): ScriptAccount[] {
|
||||
return this._scriptAccounts;
|
||||
}
|
||||
|
||||
addGamesystem(gamesystem: Gamesystem) {
|
||||
addGamesystem(gamesystem: Gamesystem<any, any>) {
|
||||
if(!this.gamesystems.includes(gamesystem)) {
|
||||
this._gamesystems.push(gamesystem);
|
||||
}
|
||||
}
|
||||
|
||||
removeGamesystem(gamesystem : Gamesystem) {
|
||||
removeGamesystem(gamesystem : Gamesystem<any, any>) {
|
||||
this._gamesystems = this._gamesystems.filter(g => g !== gamesystem);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,28 @@
|
||||
export class Gamesystem {
|
||||
export abstract class Gamesystem<S, T> {
|
||||
gamesystemName: string
|
||||
gamesystemDescription: string
|
||||
|
||||
states: S[] = [];
|
||||
transitions: T[] = [];
|
||||
constructor(gamesystemName: string) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
7
src/app/game-model/gamesystems/ProductGamesystem.ts
Normal file
7
src/app/game-model/gamesystems/ProductGamesystem.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import {Gamesystem} from "./Gamesystem";
|
||||
import {ProductState} from "./ProductState";
|
||||
import {ProductTransition} from "./ProductTransition";
|
||||
|
||||
export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> {
|
||||
|
||||
}
|
7
src/app/game-model/gamesystems/ProductState.ts
Normal file
7
src/app/game-model/gamesystems/ProductState.ts
Normal 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[] = [];
|
||||
}
|
6
src/app/game-model/gamesystems/ProductTransition.ts
Normal file
6
src/app/game-model/gamesystems/ProductTransition.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import {Transition} from "./Transition";
|
||||
import {ProductState} from "./ProductState";
|
||||
|
||||
export class ProductTransition extends Transition<ProductState> {
|
||||
|
||||
}
|
45
src/app/game-model/gamesystems/SimpleGamesystem.ts
Normal file
45
src/app/game-model/gamesystems/SimpleGamesystem.ts
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
6
src/app/game-model/gamesystems/SimpleState.ts
Normal file
6
src/app/game-model/gamesystems/SimpleState.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import {State} from "./State";
|
||||
import {SimpleTransition} from "./SimpleTransition";
|
||||
|
||||
export class SimpleState extends State<SimpleTransition> {
|
||||
|
||||
}
|
6
src/app/game-model/gamesystems/SimpleTransition.ts
Normal file
6
src/app/game-model/gamesystems/SimpleTransition.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import {SimpleState} from "./SimpleState";
|
||||
import {Transition} from "./Transition";
|
||||
|
||||
export class SimpleTransition extends Transition<SimpleState> {
|
||||
|
||||
}
|
30
src/app/game-model/gamesystems/State.ts
Normal file
30
src/app/game-model/gamesystems/State.ts
Normal 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) {
|
||||
|
||||
}
|
||||
}
|
15
src/app/game-model/gamesystems/Transition.ts
Normal file
15
src/app/game-model/gamesystems/Transition.ts
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user