issue-15 #21

Merged
sebastian merged 60 commits from issue-15 into main 2024-03-22 08:46:49 +01:00
11 changed files with 98 additions and 54 deletions
Showing only changes of commit 542515db6e - Show all commits

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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);

View File

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

View File

@ -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;
}

View File

@ -9,35 +9,25 @@ import {StorageModel} from "./fs/StorageModel";
export class GameModel {
private readonly _gameModelName: string
private _gamesystems: Gamesystem<any, any>[] = [];
private _scriptAccounts: ScriptAccount[] = [];
gamesystems: Gamesystem<any, any>[] = [];
scriptAccounts: ScriptAccount[] = [];
constructor(gameModelName: string) {
this._gameModelName = gameModelName;
}
get gameModelName(): string {
return this._gameModelName;
}
get gamesystems(): Gamesystem<any, any>[] {
return this._gamesystems;
}
get scriptAccounts(): ScriptAccount[] {
return this._scriptAccounts;
}
addGamesystem(gamesystem: Gamesystem<any, any>) {
if(this.findGamesystem(gamesystem.componentName) == undefined) {
this._gamesystems.push(gamesystem);
this.gamesystems.push(gamesystem);
}
}
removeGamesystem(gamesystem : Gamesystem<any, any>) {
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);
}
}

View File

@ -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));

View File

@ -18,7 +18,16 @@ export class GamesystemParser {
this.stateParser = new StateParser(scriptAccounts)
}
public parseGamesystem(storedGamesystem: StoreComponent) {
public parseStoredGamesystems(storedGamesystems: StoreComponent[]): Gamesystem<any, any>[] {
storedGamesystems.forEach(storedGamesystem => {
this.parseGamesystem(storedGamesystem)
})
return this.computeGamesystemStructure();
}
private parseGamesystem(storedGamesystem: StoreComponent) {
const parsedGamesystemData = JSON.parse(storedGamesystem.jsonString)
let parsedSystem: Gamesystem<any, any>
if(parsedGamesystemData.childsystems != undefined) {
@ -47,7 +56,7 @@ export class GamesystemParser {
return productGamesystem;
}
computeGamesystemStructure(): Gamesystem<any, any>[] {
private computeGamesystemStructure(): Gamesystem<any, any>[] {
const topGamesystems: Gamesystem<any, any>[] = []
this.parsedGamesystems.forEach(parsedGamesystem => {
const searchedParentsystem = this.findParentsystem(parsedGamesystem.componentName)
@ -68,4 +77,5 @@ export class GamesystemParser {
}
return undefined
}
}

View File

@ -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<conditionData.length; i++) {
const parsedCondition = this.parseSingleCondition(conditionData[i]);
if(parsedCondition != undefined) {
conditions.push(parsedCondition)
}
}
return conditions
}
parseSingleCondition(conditionData: any): ScriptAccountCondition | undefined{
const referencedScriptAccount = this.findScriptAccountByName(conditionData.scriptAccount);
if(referencedScriptAccount != undefined) {
const minValue = conditionData.minValue;
const maxValue = conditionData.maxValue;
return ScriptAccountCondition.constructScriptAccountCondition(referencedScriptAccount, minValue, maxValue);
} else {
return undefined;
}
}
findScriptAccountByName(scriptAccountName: string) {
return this.scriptAccounts.find(scriptAccount => scriptAccount.componentName === scriptAccountName);
}
}

View File

@ -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;
}

View File

@ -0,0 +1,6 @@
{
"componentName": "Temperature",
"componentDescription": "",
"minValue": -50,
"maxValue": 50
}