issue-15 #21
@ -5,6 +5,7 @@ const StoredGameModel_1 = require("../StoredGameModel");
|
||||
const path = require("node:path");
|
||||
const ModelComponentFileDirectory_1 = require("../ModelComponentFileDirectory");
|
||||
const ScriptAccountLoader_1 = require("./ScriptAccountLoader");
|
||||
const GamesystemLoader_1 = require("./GamesystemLoader");
|
||||
class GameModelLoader {
|
||||
constructor(gameModelDir) {
|
||||
this.gameModelDir = gameModelDir;
|
||||
@ -25,7 +26,9 @@ class GameModelLoader {
|
||||
return scriptAccountLoader.loadScriptAccounts();
|
||||
}
|
||||
loadGamesystems() {
|
||||
return [];
|
||||
const gamesystemDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME);
|
||||
const gamesystemLoader = new GamesystemLoader_1.GamesystemLoader(gamesystemDir);
|
||||
return gamesystemLoader.loadGamesystems();
|
||||
}
|
||||
}
|
||||
exports.GameModelLoader = GameModelLoader;
|
||||
|
@ -4,6 +4,7 @@ import * as path from "node:path";
|
||||
import * as fs from "fs";
|
||||
import {ModelComponentFileDirectory} from "../ModelComponentFileDirectory";
|
||||
import {ScriptAccountLoader} from "./ScriptAccountLoader";
|
||||
import {GamesystemLoader} from "./GamesystemLoader";
|
||||
|
||||
export class GameModelLoader {
|
||||
gameModelDir: string
|
||||
@ -33,7 +34,9 @@ export class GameModelLoader {
|
||||
}
|
||||
|
||||
private loadGamesystems(): StoreComponent[] {
|
||||
return []
|
||||
const gamesystemDir = path.join(this.gameModelDir, ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME);
|
||||
const gamesystemLoader = new GamesystemLoader(gamesystemDir);
|
||||
return gamesystemLoader.loadGamesystems();
|
||||
}
|
||||
|
||||
|
||||
|
44
app/storage/loader/GamesystemLoader.ts
Normal file
44
app/storage/loader/GamesystemLoader.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import {StoreComponent} from "../StoreComponent";
|
||||
import {FileUtils} from "../FileUtils";
|
||||
import * as fs from "fs";
|
||||
import * as path from "node:path";
|
||||
import {ModelComponentType} from "../../../src/app/project/game-model/ModelComponentType";
|
||||
|
||||
export class GamesystemLoader {
|
||||
|
||||
gamesystemDir: string
|
||||
|
||||
|
||||
constructor(gamesystemDir: string) {
|
||||
this.gamesystemDir = gamesystemDir;
|
||||
}
|
||||
|
||||
loadGamesystems() {
|
||||
return this.loadGamesystemsRecursivly(this.gamesystemDir)
|
||||
}
|
||||
|
||||
private loadGamesystemsRecursivly(currentGamesystemDir: string) {
|
||||
let loadedGamesystems: StoreComponent[] = []
|
||||
const gamesystemFiles = FileUtils.listFilesInDirectory(currentGamesystemDir);
|
||||
gamesystemFiles.forEach(gamesystemFile => {
|
||||
if(fs.lstatSync(gamesystemFile).isDirectory()) {
|
||||
const childGamesystems = this.loadGamesystemsRecursivly(gamesystemFile);
|
||||
loadedGamesystems = loadedGamesystems.concat(childGamesystems);
|
||||
} else if(path.basename(gamesystemFile).endsWith(".json")) {
|
||||
const loadedGamesystem = this.loadGamesystem(gamesystemFile);
|
||||
if(loadedGamesystem != undefined) {
|
||||
loadedGamesystems.push(loadedGamesystem);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return loadedGamesystems;
|
||||
}
|
||||
|
||||
private loadGamesystem(gamesystemFile: string) {
|
||||
if(gamesystemFile.endsWith(".json")) {
|
||||
const gamesystemData = fs.readFileSync(gamesystemFile, 'utf-8');
|
||||
return new StoreComponent(gamesystemData, gamesystemFile, ModelComponentType.GAMESYTEM);
|
||||
}
|
||||
}
|
||||
}
|
60
src/app/project/parser/gamesystemParser/GamesystemParser.ts
Normal file
60
src/app/project/parser/gamesystemParser/GamesystemParser.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import {StoreComponent} from "../../../../../app/storage/StoreComponent";
|
||||
import {Gamesystem} from "../../game-model/gamesystems/Gamesystem";
|
||||
import {ParsedParentGamesystems} from "./ParsedParentGamesystems";
|
||||
import {ProductGamesystem} from "../../game-model/gamesystems/ProductGamesystem";
|
||||
import {SimpleGamesystem} from "../../game-model/gamesystems/SimpleGamesystem";
|
||||
|
||||
export class GamesystemParser {
|
||||
|
||||
parsedParentGamesystems: ParsedParentGamesystems[] = []
|
||||
parsedGamesystems: Gamesystem<any, any>[] = []
|
||||
public parseGamesystem(storedGamesystem: StoreComponent) {
|
||||
const parsedGamesystemData = JSON.parse(storedGamesystem.jsonString)
|
||||
let parsedSystem: Gamesystem<any, any>
|
||||
if(parsedGamesystemData.childsystems != undefined) {
|
||||
parsedSystem = this.parseProductGamesystem(parsedGamesystemData)
|
||||
} else {
|
||||
parsedSystem = this.parseSimpleGamesystem(parsedGamesystemData)
|
||||
}
|
||||
this.parsedGamesystems.push(parsedSystem);
|
||||
}
|
||||
|
||||
parseSimpleGamesystem(gamesystemData: any): SimpleGamesystem {
|
||||
const simpleGamesystem = new SimpleGamesystem(gamesystemData.componentName, gamesystemData.componentDescription)
|
||||
|
||||
return simpleGamesystem
|
||||
}
|
||||
|
||||
parseProductGamesystem(gamesystemData: any) {
|
||||
const productGamesystem = new ProductGamesystem(gamesystemData.componentName, gamesystemData.componentDescription);
|
||||
const childsystemNames: string[] = []
|
||||
for(let i=0; i<gamesystemData.childsystems.length; i++) {
|
||||
childsystemNames.push(gamesystemData.childsystems[i].componentName)
|
||||
}
|
||||
this.parsedParentGamesystems.push(new ParsedParentGamesystems(productGamesystem, childsystemNames))
|
||||
|
||||
return productGamesystem;
|
||||
}
|
||||
|
||||
computeGamesystemStructure(): Gamesystem<any, any>[] {
|
||||
const topGamesystems: Gamesystem<any, any>[] = []
|
||||
this.parsedGamesystems.forEach(parsedGamesystem => {
|
||||
const searchedParentsystem = this.findParentsystem(parsedGamesystem.componentName)
|
||||
if(searchedParentsystem != undefined) {
|
||||
searchedParentsystem.addChildGamesystem(parsedGamesystem)
|
||||
} else {
|
||||
topGamesystems.push(parsedGamesystem)
|
||||
}
|
||||
})
|
||||
return topGamesystems
|
||||
}
|
||||
|
||||
findParentsystem(childsystemName: string) {
|
||||
for(let i=0; i<this.parsedParentGamesystems.length; i++) {
|
||||
if(this.parsedParentGamesystems[i].childsystemNames.includes(childsystemName)) {
|
||||
return this.parsedParentGamesystems[i].parentGamesystem;
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
import {ProductGamesystem} from "../../game-model/gamesystems/ProductGamesystem";
|
||||
|
||||
export class ParsedParentGamesystems {
|
||||
parentGamesystem: ProductGamesystem
|
||||
childsystemNames: string[]
|
||||
|
||||
|
||||
constructor(parentGamesystem: ProductGamesystem, childsystemNames: string[]) {
|
||||
this.parentGamesystem = parentGamesystem;
|
||||
this.childsystemNames = childsystemNames;
|
||||
}
|
||||
}
|
@ -5,6 +5,8 @@ import {StoredGameModel} from "../../../app/storage/StoredGameModel";
|
||||
import {ScriptAccount} from "./game-model/scriptAccounts/ScriptAccount";
|
||||
import {ModelComponentType} from "./game-model/ModelComponentType";
|
||||
import {ScriptAccountParser} from "./parser/ScriptAccountParser";
|
||||
import {GamesystemParser} from "./parser/gamesystemParser/GamesystemParser";
|
||||
import {Gamesystem} from "./game-model/gamesystems/Gamesystem";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -30,14 +32,24 @@ export class ProjectService {
|
||||
|
||||
loadProject(storedGameModel: StoredGameModel) {
|
||||
const gameModel = new GameModel(storedGameModel.gameModelName)
|
||||
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);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
gamesystemParser.computeGamesystemStructure().forEach(topGamesystem => {
|
||||
gameModel.addGamesystem(topGamesystem)
|
||||
})
|
||||
|
||||
console.log(gameModel)
|
||||
this.gameModel = gameModel;
|
||||
}
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
{
|
||||
"componentName": "Numbers",
|
||||
"componentDescription": "",
|
||||
"states": [
|
||||
{
|
||||
"initial": false,
|
||||
"conditions": [],
|
||||
"stateLabel": "1",
|
||||
"stateDescription": ""
|
||||
},
|
||||
{
|
||||
"initial": false,
|
||||
"conditions": [
|
||||
{
|
||||
"scriptAccount": "Luftfeuchtigkeit",
|
||||
"minValue": 0,
|
||||
"maxValue": "5"
|
||||
}
|
||||
],
|
||||
"stateLabel": "2",
|
||||
"stateDescription": ""
|
||||
}
|
||||
],
|
||||
"transitions": [
|
||||
{
|
||||
"scriptAccountActions": [],
|
||||
"scriptAccountConditions": [],
|
||||
"startingState": "1",
|
||||
"endingState": "2"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"componentName": "ParentTestSystem",
|
||||
"componentDescription": ""
|
||||
}
|
@ -1,4 +1,12 @@
|
||||
{
|
||||
"componentName": "Weathersystem",
|
||||
"componentDescription": "Ein Wettersystem, dass sich aus normalem Wetter (Sonne, Regen, Wolke, Schnee, Sturm etc.) und zusätzlich den Jahreszeiten (Frühling, Sommer, Herbst, Winter, etc.) zusammensetzt."
|
||||
"componentDescription": "Ein Wettersystem, dass sich aus normalem Wetter (Sonne, Regen, Wolke, Schnee, Sturm etc.) und zusätzlich den Jahreszeiten (Frühling, Sommer, Herbst, Winter, etc.) zusammensetzt.",
|
||||
"childsystems": [
|
||||
{
|
||||
"componentName": "Season"
|
||||
},
|
||||
{
|
||||
"componentName": "Weather"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user