2024-03-20 09:26:14 +01:00
|
|
|
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";
|
2024-03-20 11:19:32 +01:00
|
|
|
import {GamesystemLoader} from "./GamesystemLoader";
|
2024-03-20 09:26:14 +01:00
|
|
|
|
|
|
|
export class GameModelLoader {
|
|
|
|
gameModelDir: string
|
|
|
|
|
|
|
|
|
|
|
|
constructor(gameModelDir: string) {
|
|
|
|
this.gameModelDir = gameModelDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadGameModel(): StoredGameModel {
|
|
|
|
const gameModelName = path.basename(this.gameModelDir)
|
|
|
|
const gameModelComponents: StoreComponent[] = this.loadGameModelComponents();
|
|
|
|
|
|
|
|
return new StoredGameModel(gameModelName, gameModelComponents);
|
|
|
|
}
|
|
|
|
|
|
|
|
private loadGameModelComponents(): StoreComponent[] {
|
|
|
|
let gameModelComponents: StoreComponent[] = this.loadScriptAccountComponents()
|
|
|
|
gameModelComponents = gameModelComponents.concat(this.loadGamesystems())
|
|
|
|
return gameModelComponents
|
|
|
|
}
|
|
|
|
|
|
|
|
private loadScriptAccountComponents() {
|
|
|
|
const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME);
|
|
|
|
const scriptAccountLoader = new ScriptAccountLoader(scriptAccountDir);
|
|
|
|
return scriptAccountLoader.loadScriptAccounts()
|
|
|
|
}
|
|
|
|
|
|
|
|
private loadGamesystems(): StoreComponent[] {
|
2024-03-20 11:19:32 +01:00
|
|
|
const gamesystemDir = path.join(this.gameModelDir, ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME);
|
|
|
|
const gamesystemLoader = new GamesystemLoader(gamesystemDir);
|
|
|
|
return gamesystemLoader.loadGamesystems();
|
2024-03-20 09:26:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|