ConceptCreator/app/storage/loader/GameModelLoader.ts

61 lines
2.2 KiB
TypeScript
Raw Normal View History

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-22 10:13:50 +01:00
import {CharacterLoader} from "./CharacterLoader";
2024-05-09 13:33:26 +02:00
import {ItemLoader} from "./ItemLoader";
2024-03-20 09:26:14 +01:00
export class GameModelLoader {
gameModelDir: string
2024-05-09 16:03:52 +02:00
loadedItemgroups: StoreComponent[] = []
loadedItems: StoreComponent[] = []
2024-03-20 09:26:14 +01:00
constructor(gameModelDir: string) {
this.gameModelDir = gameModelDir;
}
loadGameModel(): StoredGameModel {
const gameModelName = path.basename(this.gameModelDir)
2024-03-20 15:15:08 +01:00
const storedScriptAccounts = this.loadScriptAccountComponents();
const storedGamesystems = this.loadGamesystems();
2024-03-22 10:13:50 +01:00
const storedCharacters = this.loadCharacters()
2024-05-09 16:03:52 +02:00
this.loadItemsAndItemgroups();
2024-03-20 09:26:14 +01:00
2024-05-09 16:03:52 +02:00
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, this.loadedItemgroups, this.loadedItems);
2024-03-20 09:26:14 +01:00
}
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
}
2024-03-22 10:13:50 +01:00
private loadCharacters(): StoreComponent[] {
const characterDir = path.join(this.gameModelDir, ModelComponentFileDirectory.CHARACTER_DIR_NAME);
const characterLoader = new CharacterLoader(characterDir)
return characterLoader.loadCharacters();
}
2024-03-20 09:26:14 +01:00
2024-05-09 16:03:52 +02:00
private loadItemsAndItemgroups() {
2024-05-09 13:33:26 +02:00
const itemgroupDir = path.join(this.gameModelDir, ModelComponentFileDirectory.ITEMGROUP_DIR_NAME);
const itemgroupLoader = new ItemLoader(itemgroupDir);
2024-05-09 16:03:52 +02:00
itemgroupLoader.loadItemgroups();
this.loadedItems = itemgroupLoader.loadedItems;
this.loadedItemgroups = itemgroupLoader.loadedItemgroups;
2024-05-09 13:33:26 +02:00
}
2024-03-20 09:26:14 +01:00
}