ConceptCreator/app/storage/loader/GameModelLoader.ts
Sebastian Böckelmann f01d8c4dab
All checks were successful
E2E Testing / test (push) Successful in 1m33s
Parse Items
2024-05-09 16:03:52 +02:00

61 lines
2.2 KiB
TypeScript

import {StoredGameModel} from "../StoredGameModel";
import {StoreComponent} from "../StoreComponent";
import * as path from "node:path";
import * as fs from "fs";
import {ModelComponentFileDirectory} from "../ModelComponentFileDirectory";
import {ScriptAccountLoader} from "./ScriptAccountLoader";
import {GamesystemLoader} from "./GamesystemLoader";
import {CharacterLoader} from "./CharacterLoader";
import {ItemLoader} from "./ItemLoader";
export class GameModelLoader {
gameModelDir: string
loadedItemgroups: StoreComponent[] = []
loadedItems: StoreComponent[] = []
constructor(gameModelDir: string) {
this.gameModelDir = gameModelDir;
}
loadGameModel(): StoredGameModel {
const gameModelName = path.basename(this.gameModelDir)
const storedScriptAccounts = this.loadScriptAccountComponents();
const storedGamesystems = this.loadGamesystems();
const storedCharacters = this.loadCharacters()
this.loadItemsAndItemgroups();
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, this.loadedItemgroups, this.loadedItems);
}
private loadScriptAccountComponents() {
const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME);
const scriptAccountLoader = new ScriptAccountLoader(scriptAccountDir);
return scriptAccountLoader.loadScriptAccounts()
}
private loadGamesystems(): StoreComponent[] {
const gamesystemDir = path.join(this.gameModelDir, ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME);
const gamesystemLoader = new GamesystemLoader(gamesystemDir);
return gamesystemLoader.loadGamesystems();
}
private loadCharacters(): StoreComponent[] {
const characterDir = path.join(this.gameModelDir, ModelComponentFileDirectory.CHARACTER_DIR_NAME);
const characterLoader = new CharacterLoader(characterDir)
return characterLoader.loadCharacters();
}
private loadItemsAndItemgroups() {
const itemgroupDir = path.join(this.gameModelDir, ModelComponentFileDirectory.ITEMGROUP_DIR_NAME);
const itemgroupLoader = new ItemLoader(itemgroupDir);
itemgroupLoader.loadItemgroups();
this.loadedItems = itemgroupLoader.loadedItems;
this.loadedItemgroups = itemgroupLoader.loadedItemgroups;
}
}