31 lines
1.3 KiB
JavaScript
31 lines
1.3 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.CharacterLoader = void 0;
|
||
|
const StoreComponent_1 = require("../StoreComponent");
|
||
|
const FileUtils_1 = require("../FileUtils");
|
||
|
const ModelComponentType_1 = require("../../../src/app/project/game-model/ModelComponentType");
|
||
|
const fs = require("fs");
|
||
|
class CharacterLoader {
|
||
|
constructor(characterDir) {
|
||
|
this.characterDir = characterDir;
|
||
|
}
|
||
|
loadCharacters() {
|
||
|
const characterFiles = FileUtils_1.FileUtils.listFilesInDirectory(this.characterDir);
|
||
|
const loadedCharacters = [];
|
||
|
characterFiles.forEach(characterFile => {
|
||
|
const loadedCharacter = this.loadSingleCharacter(characterFile);
|
||
|
if (loadedCharacter != undefined) {
|
||
|
loadedCharacters.push(loadedCharacter);
|
||
|
}
|
||
|
});
|
||
|
return loadedCharacters;
|
||
|
}
|
||
|
loadSingleCharacter(characterFile) {
|
||
|
if (characterFile.endsWith(".json")) {
|
||
|
const characterData = fs.readFileSync(characterFile, 'utf-8');
|
||
|
return new StoreComponent_1.StoreComponent(characterData, characterFile, ModelComponentType_1.ModelComponentType.SCRIPTACCOUNT);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
exports.CharacterLoader = CharacterLoader;
|
||
|
//# sourceMappingURL=CharacterLoader.js.map
|