35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import {StoreComponent} from "../StoreComponent";
|
|
import {FileUtils} from "../FileUtils";
|
|
import {ModelComponentType} from "../../../src/app/project/game-model/ModelComponentType";
|
|
import * as fs from "fs";
|
|
import {ModelComponentFileDirectory} from "../ModelComponentFileDirectory";
|
|
import {load} from "@angular-devkit/build-angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks";
|
|
|
|
export class CharacterLoader {
|
|
characterDir: string
|
|
|
|
|
|
constructor(characterDir: string) {
|
|
this.characterDir = characterDir;
|
|
}
|
|
|
|
loadCharacters(): StoreComponent[] {
|
|
const characterFiles = FileUtils.listFilesInDirectory(this.characterDir);
|
|
const loadedCharacters: StoreComponent[] = []
|
|
characterFiles.forEach(characterFile => {
|
|
const loadedCharacter = this.loadSingleCharacter(characterFile);
|
|
if(loadedCharacter != undefined) {
|
|
loadedCharacters.push(loadedCharacter)
|
|
}
|
|
})
|
|
return loadedCharacters;
|
|
}
|
|
|
|
private loadSingleCharacter(characterFile: string) {
|
|
if(characterFile.endsWith(".json")) {
|
|
const characterData = fs.readFileSync(characterFile, 'utf-8');
|
|
return new StoreComponent(characterData, characterFile, ModelComponentType.SCRIPTACCOUNT);
|
|
}
|
|
}
|
|
}
|