From 542515db6ee6cdaed29ec0b876f475765fb30fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Wed, 20 Mar 2024 15:15:08 +0100 Subject: [PATCH] Parse ScriptAccountConditions --- app/storage/StoredGameModel.js | 5 ++- app/storage/StoredGameModel.ts | 9 +++-- app/storage/loader/GameModelLoader.js | 10 ++--- app/storage/loader/GameModelLoader.ts | 10 ++--- src/app/app.component.ts | 20 +++------- src/app/project/game-model/GameModel.ts | 20 +++------- src/app/project/parser/ScriptAccountParser.ts | 10 ++++- .../gamesystemParser/GamesystemParser.ts | 14 ++++++- .../ScriptAccountConditionParser.ts | 39 +++++++++++++++++++ .../parser/gamesystemParser/StateParser.ts | 9 ++++- testModel/script-accounts/Temperature.json | 6 +++ 11 files changed, 98 insertions(+), 54 deletions(-) create mode 100644 src/app/project/parser/gamesystemParser/ScriptAccountConditionParser.ts create mode 100644 testModel/script-accounts/Temperature.json diff --git a/app/storage/StoredGameModel.js b/app/storage/StoredGameModel.js index 076e1a0..126a61b 100644 --- a/app/storage/StoredGameModel.js +++ b/app/storage/StoredGameModel.js @@ -2,9 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.StoredGameModel = void 0; class StoredGameModel { - constructor(gameModelName, loadedModels) { + constructor(gameModelName, storedScriptAccounts, storedGamesystems) { this.gameModelName = gameModelName; - this.loadedModels = loadedModels; + this.storedGamesystems = storedGamesystems; + this.storedScriptAccounts = storedScriptAccounts; } } exports.StoredGameModel = StoredGameModel; diff --git a/app/storage/StoredGameModel.ts b/app/storage/StoredGameModel.ts index 8104b44..8edfee0 100644 --- a/app/storage/StoredGameModel.ts +++ b/app/storage/StoredGameModel.ts @@ -2,11 +2,14 @@ import {StoreComponent} from "./StoreComponent"; export class StoredGameModel { gameModelName: string - loadedModels: StoreComponent[] + + storedGamesystems: StoreComponent[] + storedScriptAccounts: StoreComponent[] - constructor(gameModelName: string, loadedModels: StoreComponent[]) { + constructor(gameModelName: string, storedScriptAccounts: StoreComponent[], storedGamesystems: StoreComponent[]) { this.gameModelName = gameModelName; - this.loadedModels = loadedModels; + this.storedGamesystems = storedGamesystems; + this.storedScriptAccounts = storedScriptAccounts; } } diff --git a/app/storage/loader/GameModelLoader.js b/app/storage/loader/GameModelLoader.js index a705ac9..7139cc9 100644 --- a/app/storage/loader/GameModelLoader.js +++ b/app/storage/loader/GameModelLoader.js @@ -12,13 +12,9 @@ class GameModelLoader { } loadGameModel() { const gameModelName = path.basename(this.gameModelDir); - const gameModelComponents = this.loadGameModelComponents(); - return new StoredGameModel_1.StoredGameModel(gameModelName, gameModelComponents); - } - loadGameModelComponents() { - let gameModelComponents = this.loadScriptAccountComponents(); - gameModelComponents = gameModelComponents.concat(this.loadGamesystems()); - return gameModelComponents; + const storedScriptAccounts = this.loadScriptAccountComponents(); + const storedGamesystems = this.loadGamesystems(); + return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems); } loadScriptAccountComponents() { const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME); diff --git a/app/storage/loader/GameModelLoader.ts b/app/storage/loader/GameModelLoader.ts index d9edfb3..bcbfa63 100644 --- a/app/storage/loader/GameModelLoader.ts +++ b/app/storage/loader/GameModelLoader.ts @@ -16,15 +16,11 @@ export class GameModelLoader { loadGameModel(): StoredGameModel { const gameModelName = path.basename(this.gameModelDir) - const gameModelComponents: StoreComponent[] = this.loadGameModelComponents(); - return new StoredGameModel(gameModelName, gameModelComponents); - } + const storedScriptAccounts = this.loadScriptAccountComponents(); + const storedGamesystems = this.loadGamesystems(); - private loadGameModelComponents(): StoreComponent[] { - let gameModelComponents: StoreComponent[] = this.loadScriptAccountComponents() - gameModelComponents = gameModelComponents.concat(this.loadGamesystems()) - return gameModelComponents + return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems); } private loadScriptAccountComponents() { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 71c5078..9a41423 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -154,23 +154,13 @@ export class AppComponent implements OnInit{ onLoadProject(storedGameModel: StoredGameModel) { const gameModel = new GameModel(storedGameModel.gameModelName) + const scriptAccounts = ScriptAccountParser.parseScriptAccounts(storedGameModel.storedScriptAccounts); - //const gamesystemParser = new GamesystemParser(); - storedGameModel.loadedModels.forEach(storedComponent => { - switch (storedComponent.componentType) { - case ModelComponentType.SCRIPTACCOUNT: { - const scriptAccount = ScriptAccountParser.parseScriptAccount(storedComponent); - gameModel.addScriptAccount(scriptAccount); - } break - case ModelComponentType.GAMESYTEM: { - //gamesystemParser.parseGamesystem(storedComponent); - } - } - }) + const gamesystemParser = new GamesystemParser(scriptAccounts); + const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems); - /*gamesystemParser.computeGamesystemStructure().forEach(topGamesystem => { - gameModel.addGamesystem(topGamesystem) - })*/ + gameModel.scriptAccounts = scriptAccounts + gameModel.gamesystems = gamesystems this.gameModel = gameModel; } diff --git a/src/app/project/game-model/GameModel.ts b/src/app/project/game-model/GameModel.ts index ec53871..6a7b5d5 100644 --- a/src/app/project/game-model/GameModel.ts +++ b/src/app/project/game-model/GameModel.ts @@ -9,35 +9,25 @@ import {StorageModel} from "./fs/StorageModel"; export class GameModel { private readonly _gameModelName: string - private _gamesystems: Gamesystem[] = []; - private _scriptAccounts: ScriptAccount[] = []; + gamesystems: Gamesystem[] = []; + scriptAccounts: ScriptAccount[] = []; constructor(gameModelName: string) { this._gameModelName = gameModelName; } - get gameModelName(): string { - return this._gameModelName; - } - get gamesystems(): Gamesystem[] { - return this._gamesystems; - } - get scriptAccounts(): ScriptAccount[] { - return this._scriptAccounts; - } addGamesystem(gamesystem: Gamesystem) { if(this.findGamesystem(gamesystem.componentName) == undefined) { - this._gamesystems.push(gamesystem); + this.gamesystems.push(gamesystem); } } removeGamesystem(gamesystem : Gamesystem) { if(gamesystem.parentGamesystem == undefined) { - this._gamesystems = this._gamesystems.filter(g => g !== gamesystem); + this.gamesystems = this.gamesystems.filter(g => g !== gamesystem); } else { (gamesystem.parentGamesystem as ProductGamesystem).removeChildGamesystem(gamesystem); - console.log(gamesystem.parentGamesystem) } } @@ -77,7 +67,7 @@ export class GameModel { removeScriptAccount(scriptAccount: ScriptAccount) { if(scriptAccount != undefined) { - this._scriptAccounts = this.scriptAccounts.filter(s => s != scriptAccount); + this.scriptAccounts = this.scriptAccounts.filter(s => s != scriptAccount); } } diff --git a/src/app/project/parser/ScriptAccountParser.ts b/src/app/project/parser/ScriptAccountParser.ts index 56a99b7..72538c9 100644 --- a/src/app/project/parser/ScriptAccountParser.ts +++ b/src/app/project/parser/ScriptAccountParser.ts @@ -3,7 +3,15 @@ import {ScriptAccount} from "../game-model/scriptAccounts/ScriptAccount"; export class ScriptAccountParser { - public static parseScriptAccount(storedComponent: StoreComponent): ScriptAccount { + public static parseScriptAccounts(storedScriptAccounts: StoreComponent[]): ScriptAccount[] { + const scriptAccounts: ScriptAccount[] = [] + storedScriptAccounts.forEach(scriptAccount => { + scriptAccounts.push(this.parseScriptAccount(scriptAccount)) + }) + return scriptAccounts; + } + + private static parseScriptAccount(storedComponent: StoreComponent): ScriptAccount { console.log("Parse ScriptAccount: ", storedComponent.fileName) const parsedScriptAccount = new ScriptAccount("", ""); Object.assign(parsedScriptAccount, JSON.parse(storedComponent.jsonString)); diff --git a/src/app/project/parser/gamesystemParser/GamesystemParser.ts b/src/app/project/parser/gamesystemParser/GamesystemParser.ts index 50771d6..4feab98 100644 --- a/src/app/project/parser/gamesystemParser/GamesystemParser.ts +++ b/src/app/project/parser/gamesystemParser/GamesystemParser.ts @@ -18,7 +18,16 @@ export class GamesystemParser { this.stateParser = new StateParser(scriptAccounts) } - public parseGamesystem(storedGamesystem: StoreComponent) { + + public parseStoredGamesystems(storedGamesystems: StoreComponent[]): Gamesystem[] { + storedGamesystems.forEach(storedGamesystem => { + this.parseGamesystem(storedGamesystem) + }) + + return this.computeGamesystemStructure(); + } + + private parseGamesystem(storedGamesystem: StoreComponent) { const parsedGamesystemData = JSON.parse(storedGamesystem.jsonString) let parsedSystem: Gamesystem if(parsedGamesystemData.childsystems != undefined) { @@ -47,7 +56,7 @@ export class GamesystemParser { return productGamesystem; } - computeGamesystemStructure(): Gamesystem[] { + private computeGamesystemStructure(): Gamesystem[] { const topGamesystems: Gamesystem[] = [] this.parsedGamesystems.forEach(parsedGamesystem => { const searchedParentsystem = this.findParentsystem(parsedGamesystem.componentName) @@ -68,4 +77,5 @@ export class GamesystemParser { } return undefined } + } diff --git a/src/app/project/parser/gamesystemParser/ScriptAccountConditionParser.ts b/src/app/project/parser/gamesystemParser/ScriptAccountConditionParser.ts new file mode 100644 index 0000000..6a04131 --- /dev/null +++ b/src/app/project/parser/gamesystemParser/ScriptAccountConditionParser.ts @@ -0,0 +1,39 @@ +import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; +import {ScriptAccountCondition} from "../../game-model/gamesystems/conditions/ScriptAccountCondition"; +import {max, min} from "rxjs"; + +export class ScriptAccountConditionParser { + + scriptAccounts: ScriptAccount[] + + + constructor(scriptAccounts: ScriptAccount[]) { + this.scriptAccounts = scriptAccounts; + } + + parseStoredConditions(conditionData: any): ScriptAccountCondition[] { + const conditions: ScriptAccountCondition[] = [] + for(let i=0; i scriptAccount.componentName === scriptAccountName); + } +} diff --git a/src/app/project/parser/gamesystemParser/StateParser.ts b/src/app/project/parser/gamesystemParser/StateParser.ts index e91aac0..aadb6c3 100644 --- a/src/app/project/parser/gamesystemParser/StateParser.ts +++ b/src/app/project/parser/gamesystemParser/StateParser.ts @@ -1,14 +1,15 @@ import {SimpleState} from "../../game-model/gamesystems/states/SimpleState"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {ScriptAccountCondition} from "../../game-model/gamesystems/conditions/ScriptAccountCondition"; +import {ScriptAccountConditionParser} from "./ScriptAccountConditionParser"; export class StateParser { - private scriptAccounts: ScriptAccount[] + private conditionParser constructor(scriptAccounts: ScriptAccount[]) { - this.scriptAccounts = scriptAccounts; + this.conditionParser = new ScriptAccountConditionParser(scriptAccounts) } public parseStates(gamesystemData: any): SimpleState[] { @@ -25,8 +26,12 @@ export class StateParser { const stateLabel = stateData.stateLabel const stateDescription = stateData.stateDescription + const conditions = this.conditionParser.parseStoredConditions(stateData.conditions) + const simpleState = new SimpleState(stateLabel, stateDescription); simpleState.initial = initial; + simpleState.conditions = conditions; + return simpleState; } diff --git a/testModel/script-accounts/Temperature.json b/testModel/script-accounts/Temperature.json new file mode 100644 index 0000000..db4d1c8 --- /dev/null +++ b/testModel/script-accounts/Temperature.json @@ -0,0 +1,6 @@ +{ + "componentName": "Temperature", + "componentDescription": "", + "minValue": -50, + "maxValue": 50 +} \ No newline at end of file