issue-15 #21
@ -2,9 +2,10 @@
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.StoredGameModel = void 0;
|
exports.StoredGameModel = void 0;
|
||||||
class StoredGameModel {
|
class StoredGameModel {
|
||||||
constructor(gameModelName, loadedModels) {
|
constructor(gameModelName, storedScriptAccounts, storedGamesystems) {
|
||||||
this.gameModelName = gameModelName;
|
this.gameModelName = gameModelName;
|
||||||
this.loadedModels = loadedModels;
|
this.storedGamesystems = storedGamesystems;
|
||||||
|
this.storedScriptAccounts = storedScriptAccounts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.StoredGameModel = StoredGameModel;
|
exports.StoredGameModel = StoredGameModel;
|
||||||
|
@ -2,11 +2,14 @@ import {StoreComponent} from "./StoreComponent";
|
|||||||
|
|
||||||
export class StoredGameModel {
|
export class StoredGameModel {
|
||||||
gameModelName: string
|
gameModelName: string
|
||||||
loadedModels: StoreComponent[]
|
|
||||||
|
storedGamesystems: StoreComponent[]
|
||||||
|
storedScriptAccounts: StoreComponent[]
|
||||||
|
|
||||||
|
|
||||||
constructor(gameModelName: string, loadedModels: StoreComponent[]) {
|
constructor(gameModelName: string, storedScriptAccounts: StoreComponent[], storedGamesystems: StoreComponent[]) {
|
||||||
this.gameModelName = gameModelName;
|
this.gameModelName = gameModelName;
|
||||||
this.loadedModels = loadedModels;
|
this.storedGamesystems = storedGamesystems;
|
||||||
|
this.storedScriptAccounts = storedScriptAccounts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,9 @@ class GameModelLoader {
|
|||||||
}
|
}
|
||||||
loadGameModel() {
|
loadGameModel() {
|
||||||
const gameModelName = path.basename(this.gameModelDir);
|
const gameModelName = path.basename(this.gameModelDir);
|
||||||
const gameModelComponents = this.loadGameModelComponents();
|
const storedScriptAccounts = this.loadScriptAccountComponents();
|
||||||
return new StoredGameModel_1.StoredGameModel(gameModelName, gameModelComponents);
|
const storedGamesystems = this.loadGamesystems();
|
||||||
}
|
return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems);
|
||||||
loadGameModelComponents() {
|
|
||||||
let gameModelComponents = this.loadScriptAccountComponents();
|
|
||||||
gameModelComponents = gameModelComponents.concat(this.loadGamesystems());
|
|
||||||
return gameModelComponents;
|
|
||||||
}
|
}
|
||||||
loadScriptAccountComponents() {
|
loadScriptAccountComponents() {
|
||||||
const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME);
|
const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME);
|
||||||
|
@ -16,15 +16,11 @@ export class GameModelLoader {
|
|||||||
|
|
||||||
loadGameModel(): StoredGameModel {
|
loadGameModel(): StoredGameModel {
|
||||||
const gameModelName = path.basename(this.gameModelDir)
|
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[] {
|
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems);
|
||||||
let gameModelComponents: StoreComponent[] = this.loadScriptAccountComponents()
|
|
||||||
gameModelComponents = gameModelComponents.concat(this.loadGamesystems())
|
|
||||||
return gameModelComponents
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadScriptAccountComponents() {
|
private loadScriptAccountComponents() {
|
||||||
|
@ -154,23 +154,13 @@ export class AppComponent implements OnInit{
|
|||||||
onLoadProject(storedGameModel: StoredGameModel) {
|
onLoadProject(storedGameModel: StoredGameModel) {
|
||||||
const gameModel = new GameModel(storedGameModel.gameModelName)
|
const gameModel = new GameModel(storedGameModel.gameModelName)
|
||||||
|
|
||||||
|
const scriptAccounts = ScriptAccountParser.parseScriptAccounts(storedGameModel.storedScriptAccounts);
|
||||||
|
|
||||||
//const gamesystemParser = new GamesystemParser();
|
const gamesystemParser = new GamesystemParser(scriptAccounts);
|
||||||
storedGameModel.loadedModels.forEach(storedComponent => {
|
const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems);
|
||||||
switch (storedComponent.componentType) {
|
|
||||||
case ModelComponentType.SCRIPTACCOUNT: {
|
|
||||||
const scriptAccount = ScriptAccountParser.parseScriptAccount(storedComponent);
|
|
||||||
gameModel.addScriptAccount(scriptAccount);
|
|
||||||
} break
|
|
||||||
case ModelComponentType.GAMESYTEM: {
|
|
||||||
//gamesystemParser.parseGamesystem(storedComponent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/*gamesystemParser.computeGamesystemStructure().forEach(topGamesystem => {
|
gameModel.scriptAccounts = scriptAccounts
|
||||||
gameModel.addGamesystem(topGamesystem)
|
gameModel.gamesystems = gamesystems
|
||||||
})*/
|
|
||||||
|
|
||||||
this.gameModel = gameModel;
|
this.gameModel = gameModel;
|
||||||
}
|
}
|
||||||
|
@ -9,35 +9,25 @@ import {StorageModel} from "./fs/StorageModel";
|
|||||||
export class GameModel {
|
export class GameModel {
|
||||||
private readonly _gameModelName: string
|
private readonly _gameModelName: string
|
||||||
|
|
||||||
private _gamesystems: Gamesystem<any, any>[] = [];
|
gamesystems: Gamesystem<any, any>[] = [];
|
||||||
private _scriptAccounts: ScriptAccount[] = [];
|
scriptAccounts: ScriptAccount[] = [];
|
||||||
|
|
||||||
constructor(gameModelName: string) {
|
constructor(gameModelName: string) {
|
||||||
this._gameModelName = gameModelName;
|
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>) {
|
addGamesystem(gamesystem: Gamesystem<any, any>) {
|
||||||
if(this.findGamesystem(gamesystem.componentName) == undefined) {
|
if(this.findGamesystem(gamesystem.componentName) == undefined) {
|
||||||
this._gamesystems.push(gamesystem);
|
this.gamesystems.push(gamesystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeGamesystem(gamesystem : Gamesystem<any, any>) {
|
removeGamesystem(gamesystem : Gamesystem<any, any>) {
|
||||||
if(gamesystem.parentGamesystem == undefined) {
|
if(gamesystem.parentGamesystem == undefined) {
|
||||||
this._gamesystems = this._gamesystems.filter(g => g !== gamesystem);
|
this.gamesystems = this.gamesystems.filter(g => g !== gamesystem);
|
||||||
} else {
|
} else {
|
||||||
(gamesystem.parentGamesystem as ProductGamesystem).removeChildGamesystem(gamesystem);
|
(gamesystem.parentGamesystem as ProductGamesystem).removeChildGamesystem(gamesystem);
|
||||||
console.log(gamesystem.parentGamesystem)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +67,7 @@ export class GameModel {
|
|||||||
|
|
||||||
removeScriptAccount(scriptAccount: ScriptAccount) {
|
removeScriptAccount(scriptAccount: ScriptAccount) {
|
||||||
if(scriptAccount != undefined) {
|
if(scriptAccount != undefined) {
|
||||||
this._scriptAccounts = this.scriptAccounts.filter(s => s != scriptAccount);
|
this.scriptAccounts = this.scriptAccounts.filter(s => s != scriptAccount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,15 @@ import {ScriptAccount} from "../game-model/scriptAccounts/ScriptAccount";
|
|||||||
|
|
||||||
export class ScriptAccountParser {
|
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)
|
console.log("Parse ScriptAccount: ", storedComponent.fileName)
|
||||||
const parsedScriptAccount = new ScriptAccount("", "");
|
const parsedScriptAccount = new ScriptAccount("", "");
|
||||||
Object.assign(parsedScriptAccount, JSON.parse(storedComponent.jsonString));
|
Object.assign(parsedScriptAccount, JSON.parse(storedComponent.jsonString));
|
||||||
|
@ -18,7 +18,16 @@ export class GamesystemParser {
|
|||||||
this.stateParser = new StateParser(scriptAccounts)
|
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)
|
const parsedGamesystemData = JSON.parse(storedGamesystem.jsonString)
|
||||||
let parsedSystem: Gamesystem<any, any>
|
let parsedSystem: Gamesystem<any, any>
|
||||||
if(parsedGamesystemData.childsystems != undefined) {
|
if(parsedGamesystemData.childsystems != undefined) {
|
||||||
@ -47,7 +56,7 @@ export class GamesystemParser {
|
|||||||
return productGamesystem;
|
return productGamesystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
computeGamesystemStructure(): Gamesystem<any, any>[] {
|
private computeGamesystemStructure(): Gamesystem<any, any>[] {
|
||||||
const topGamesystems: Gamesystem<any, any>[] = []
|
const topGamesystems: Gamesystem<any, any>[] = []
|
||||||
this.parsedGamesystems.forEach(parsedGamesystem => {
|
this.parsedGamesystems.forEach(parsedGamesystem => {
|
||||||
const searchedParentsystem = this.findParentsystem(parsedGamesystem.componentName)
|
const searchedParentsystem = this.findParentsystem(parsedGamesystem.componentName)
|
||||||
@ -68,4 +77,5 @@ export class GamesystemParser {
|
|||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,15 @@
|
|||||||
import {SimpleState} from "../../game-model/gamesystems/states/SimpleState";
|
import {SimpleState} from "../../game-model/gamesystems/states/SimpleState";
|
||||||
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
|
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
|
||||||
import {ScriptAccountCondition} from "../../game-model/gamesystems/conditions/ScriptAccountCondition";
|
import {ScriptAccountCondition} from "../../game-model/gamesystems/conditions/ScriptAccountCondition";
|
||||||
|
import {ScriptAccountConditionParser} from "./ScriptAccountConditionParser";
|
||||||
|
|
||||||
export class StateParser {
|
export class StateParser {
|
||||||
|
|
||||||
private scriptAccounts: ScriptAccount[]
|
private conditionParser
|
||||||
|
|
||||||
|
|
||||||
constructor(scriptAccounts: ScriptAccount[]) {
|
constructor(scriptAccounts: ScriptAccount[]) {
|
||||||
this.scriptAccounts = scriptAccounts;
|
this.conditionParser = new ScriptAccountConditionParser(scriptAccounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
public parseStates(gamesystemData: any): SimpleState[] {
|
public parseStates(gamesystemData: any): SimpleState[] {
|
||||||
@ -25,8 +26,12 @@ export class StateParser {
|
|||||||
const stateLabel = stateData.stateLabel
|
const stateLabel = stateData.stateLabel
|
||||||
const stateDescription = stateData.stateDescription
|
const stateDescription = stateData.stateDescription
|
||||||
|
|
||||||
|
const conditions = this.conditionParser.parseStoredConditions(stateData.conditions)
|
||||||
|
|
||||||
const simpleState = new SimpleState(stateLabel, stateDescription);
|
const simpleState = new SimpleState(stateLabel, stateDescription);
|
||||||
simpleState.initial = initial;
|
simpleState.initial = initial;
|
||||||
|
simpleState.conditions = conditions;
|
||||||
|
|
||||||
return simpleState;
|
return simpleState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
testModel/script-accounts/Temperature.json
Normal file
6
testModel/script-accounts/Temperature.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"componentName": "Temperature",
|
||||||
|
"componentDescription": "",
|
||||||
|
"minValue": -50,
|
||||||
|
"maxValue": 50
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user