ConceptCreator/app/storage/loader/GameModelLoader.ts
Sebastian Böckelmann e890d89cc8
All checks were successful
E2E Testing / test (push) Successful in 1m31s
Load Characters from Persistence
2024-03-22 10:13:50 +01:00

51 lines
1.7 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";
export class GameModelLoader {
gameModelDir: string
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()
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters);
}
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();
}
}