diff --git a/e2e/game-model/gamesystems/FindGamesystem.spec.ts b/e2e/game-model/gamesystems/FindGamesystem.spec.ts new file mode 100644 index 0000000..879717b --- /dev/null +++ b/e2e/game-model/gamesystems/FindGamesystem.spec.ts @@ -0,0 +1,50 @@ +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"; +import {GamesystemTrainer} from "./GamesystemTrainer"; +test.describe('Test Find Gamesystems', () => { + const GAMEMODELNAME: string = "GameModel"; + const SIMPLEGAMESYSTEM_NAME: string = "Simple Gamesystem"; + + + test('Find null or undefined Gamesystem', async () => { + const gameModel = new GameModel(GAMEMODELNAME); + expect(gameModel.findGamesystem(null)).toBeUndefined(); + expect(gameModel.findGamesystem(undefined)).toBeUndefined(); + }) + + test('Find non existend Gamesystem', async () => { + const gameModel = new GameModel(GAMEMODELNAME); + expect(gameModel.findGamesystem("Gamesystem")).toBeUndefined(); + }) + + test("Find existend simple Gamesystem on top layer", async () => { + const gameModel = new GameModel(GAMEMODELNAME); + const gamesystem = new SimpleGamesystem(SIMPLEGAMESYSTEM_NAME); + gameModel.addGamesystem(gamesystem); + + expect(gameModel.findGamesystem(SIMPLEGAMESYSTEM_NAME)).toBeDefined(); + expect(gameModel.findGamesystem(SIMPLEGAMESYSTEM_NAME)).toEqual(gamesystem); + }) + + test('Find existent product gamesystem on top layer', async () => { + const gameModel = GamesystemTrainer.givenGameModelWithProductGamesytemOnTopLayer(); + const result = gameModel.findGamesystem(GamesystemTrainer.TOP_PRODUCT_GAMESYSTEM_NAME); + expect(result).toBeDefined(); + + }) + + test('Find existent simple gamesystem on lower layer', async () => { + const gameModel = GamesystemTrainer.givenGameModelWithProductGamesytemOnTopLayer(); + const result = gameModel.findGamesystem(GamesystemTrainer.SIMPLEGAMESYSTEMNAME); + expect(result).toBeDefined(); + + }) +}); diff --git a/e2e/game-model/gamesystems/GamesystemTrainer.ts b/e2e/game-model/gamesystems/GamesystemTrainer.ts new file mode 100644 index 0000000..8b2055f --- /dev/null +++ b/e2e/game-model/gamesystems/GamesystemTrainer.ts @@ -0,0 +1,37 @@ +import {GameModel} from "../../../src/app/game-model/GameModel"; +import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem"; +import {ProductGamesystem} from "../../../src/app/game-model/gamesystems/ProductGamesystem"; + +export class GamesystemTrainer { + + static GAMEMODELNAME: string = "GAMEMODEL"; + static SIMPLEGAMESYSTEMNAME: string = "SIMPLE GAMESYSTEM"; + static TOP_PRODUCT_GAMESYSTEM_NAME: string = "Top Product Gamesystem" + + static SIMPLEGAMESYSTEM2: string = "Simple Gamesystem Leaf 2"; + static givenEmptyGameModel() { + return new GameModel(GamesystemTrainer.GAMEMODELNAME); + } + + static givenGameModelWithSimpleGamesystemOnTopLayer() { + const gameModel = new GameModel(GamesystemTrainer.GAMEMODELNAME); + const gamesytem = new SimpleGamesystem(GamesystemTrainer.SIMPLEGAMESYSTEMNAME); + gameModel.addGamesystem(gamesytem); + + return gameModel; + } + + static givenGameModelWithProductGamesytemOnTopLayer() { + const gameModel = new GameModel(GamesystemTrainer.GAMEMODELNAME); + const productGamesystem = new ProductGamesystem(this.TOP_PRODUCT_GAMESYSTEM_NAME); + const leaf1 = new SimpleGamesystem(this.SIMPLEGAMESYSTEMNAME); + const leaf2 = new SimpleGamesystem(this.SIMPLEGAMESYSTEM2); + productGamesystem.innerGamesystems.push(leaf1); + productGamesystem.innerGamesystems.push(leaf2); + gameModel.addGamesystem(productGamesystem); + + return gameModel; + } + + +} diff --git a/src/app/game-model/GameModel.ts b/src/app/game-model/GameModel.ts index b8cec69..207fd0a 100644 --- a/src/app/game-model/GameModel.ts +++ b/src/app/game-model/GameModel.ts @@ -1,5 +1,8 @@ import {Gamesystem} from "./gamesystems/Gamesystem"; import {ScriptAccount} from "./scriptAccounts/ScriptAccount"; +import {Transition} from "./gamesystems/Transition"; +import {State} from "./gamesystems/State"; +import {ProductGamesystem} from "./gamesystems/ProductGamesystem"; export class GameModel { private readonly _gameModelName: string @@ -48,4 +51,19 @@ export class GameModel { } } + findGamesystem(gamesystemName: string) { + const gamesystemQueue : Gamesystem, Transition>[] = []; + this.gamesystems.forEach(gamesystem => gamesystemQueue.push(gamesystem)); + + while(gamesystemQueue.length > 0) { + const currentGamesystem = gamesystemQueue.shift()!; + if(currentGamesystem.componentName == gamesystemName) { + return currentGamesystem; + } else if(currentGamesystem instanceof ProductGamesystem) { + const currentProductGamesystem = currentGamesystem as ProductGamesystem; + currentProductGamesystem.innerGamesystems.forEach(gamesystem => gamesystemQueue.push(gamesystem)); + } + } + } + } diff --git a/src/app/side-overviews/gamescript-overview/gamescript-overview.component.html b/src/app/side-overviews/gamescript-overview/gamescript-overview.component.html index e871b87..d8a0d79 100644 --- a/src/app/side-overviews/gamescript-overview/gamescript-overview.component.html +++ b/src/app/side-overviews/gamescript-overview/gamescript-overview.component.html @@ -1,14 +1,17 @@ - + - + - + {{node.name}} - +