79 lines
3.8 KiB
TypeScript
79 lines
3.8 KiB
TypeScript
import {GameModel} from "../GameModel";
|
|
import {LoadedProject} from "../../../../app/LoadedProject";
|
|
import {LoadModel} from "../../../../app/LoadModel";
|
|
import {ModelComponentType} from "../ModelComponentType";
|
|
import {ScriptAccount} from "../scriptAccounts/ScriptAccount";
|
|
import {RecursiveLoadModel} from "../../../../app/RecursiveLoadModel";
|
|
import {SimpleGamesystemParser} from "./parser/SimpleGamesystemParser";
|
|
import {SimpleGamesystem} from "../gamesystems/SimpleGamesystem";
|
|
import {ProductGamesystem} from "../gamesystems/ProductGamesystem";
|
|
import {ProductGamesystemParser} from "./parser/ProductGamesystemParser";
|
|
import {Gamesystem} from "../gamesystems/Gamesystem";
|
|
|
|
export class ProcessLoadedProject {
|
|
|
|
static processLoadedProject(loadedProject: LoadedProject): GameModel {
|
|
const gameModel = new GameModel(loadedProject.projectName);
|
|
loadedProject.loadedModels.forEach(loadedModel => this.processLoadedModel(gameModel, loadedModel))
|
|
//Generate product Gamesystems
|
|
this.generateProductGamesystems(gameModel.gamesystems)
|
|
return gameModel;
|
|
}
|
|
|
|
static generateProductGamesystems(gamesystems: Gamesystem<any, any>[]) {
|
|
gamesystems.forEach(gamesystem => {
|
|
if(gamesystem instanceof ProductGamesystem) {
|
|
gamesystem.generateFromChildsystems();
|
|
}
|
|
})
|
|
}
|
|
|
|
static processLoadedModel(gameModel: GameModel, loadedModel: LoadModel) {
|
|
switch (loadedModel.modelType) {
|
|
case ModelComponentType.SCRIPTACCOUNT: this.processLoadedScriptAccount(gameModel, loadedModel); break;
|
|
case ModelComponentType.GAMESYTEM: this.processLoadedGamesystem(gameModel, loadedModel); break;
|
|
}
|
|
}
|
|
static processLoadedScriptAccount(gameModel: GameModel, loadedModel: LoadModel) {
|
|
const scriptAccount = new ScriptAccount("", "");
|
|
Object.assign(scriptAccount, JSON.parse(loadedModel.jsonString));
|
|
gameModel.addScriptAccount(scriptAccount);
|
|
}
|
|
|
|
static processLoadedGamesystem(gameModel: GameModel, loadedModel: LoadModel) {
|
|
const parsedJsonString = JSON.parse(loadedModel.jsonString);
|
|
if(loadedModel.hasOwnProperty('parentLoadModelname')) {
|
|
const recursiveLoadModel = loadedModel as RecursiveLoadModel
|
|
console.log("Loaded Model should be an instance of recursivemodel")
|
|
if(parsedJsonString.hasOwnProperty('states') && parsedJsonString.hasOwnProperty('transitions')) {
|
|
//SimpleGamesystem
|
|
const simpleGamesystem: SimpleGamesystem = SimpleGamesystemParser.parseSimpleGamesystem(parsedJsonString, gameModel.scriptAccounts);
|
|
const parentModel: ProductGamesystem = gameModel.findGamesystem(recursiveLoadModel.parentLoadModelname) as ProductGamesystem
|
|
parentModel.addChildGamesystem(simpleGamesystem);
|
|
simpleGamesystem.parentGamesystem = parentModel
|
|
} else {
|
|
console.log("Gamesystems: ", )
|
|
//ProductGamesystem
|
|
const productGamesystem: ProductGamesystem = ProductGamesystemParser.parseProductGamesystem(parsedJsonString);
|
|
const parentModel: ProductGamesystem = gameModel.findGamesystem(recursiveLoadModel.parentLoadModelname) as ProductGamesystem;
|
|
parentModel.addChildGamesystem(productGamesystem);
|
|
productGamesystem.parentGamesystem = parentModel
|
|
}
|
|
} else {
|
|
//Top Gamesystem
|
|
if(parsedJsonString.hasOwnProperty('states') && parsedJsonString.hasOwnProperty('transitions')) {
|
|
//SimpleGamesystem
|
|
const simpleGamesystem: SimpleGamesystem = SimpleGamesystemParser.parseSimpleGamesystem(parsedJsonString, gameModel.scriptAccounts);
|
|
gameModel.addGamesystem(simpleGamesystem);
|
|
} else {
|
|
//ProductGamesystem
|
|
const productGamesystem = ProductGamesystemParser.parseProductGamesystem(parsedJsonString);
|
|
console.log("Generated Productsystem: ", productGamesystem)
|
|
gameModel.addGamesystem(productGamesystem);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|