ConceptCreator/app/storage/loader/GamesystemLoader.js
Sebastian Böckelmann ad36913ff9
Some checks failed
E2E Testing / test (push) Failing after 1m33s
Project Service had to be deleted as the gamemodel binding would suffer flexibility
2024-03-20 12:50:47 +01:00

41 lines
1.8 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GamesystemLoader = void 0;
const StoreComponent_1 = require("../StoreComponent");
const FileUtils_1 = require("../FileUtils");
const fs = require("fs");
const path = require("node:path");
const ModelComponentType_1 = require("../../../src/app/project/game-model/ModelComponentType");
class GamesystemLoader {
constructor(gamesystemDir) {
this.gamesystemDir = gamesystemDir;
}
loadGamesystems() {
return this.loadGamesystemsRecursivly(this.gamesystemDir);
}
loadGamesystemsRecursivly(currentGamesystemDir) {
let loadedGamesystems = [];
const gamesystemFiles = FileUtils_1.FileUtils.listFilesInDirectory(currentGamesystemDir);
gamesystemFiles.forEach(gamesystemFile => {
if (fs.lstatSync(gamesystemFile).isDirectory()) {
const childGamesystems = this.loadGamesystemsRecursivly(gamesystemFile);
loadedGamesystems = loadedGamesystems.concat(childGamesystems);
}
else if (path.basename(gamesystemFile).endsWith(".json")) {
const loadedGamesystem = this.loadGamesystem(gamesystemFile);
if (loadedGamesystem != undefined) {
loadedGamesystems.push(loadedGamesystem);
}
}
});
return loadedGamesystems;
}
loadGamesystem(gamesystemFile) {
if (gamesystemFile.endsWith(".json")) {
const gamesystemData = fs.readFileSync(gamesystemFile, 'utf-8');
return new StoreComponent_1.StoreComponent(gamesystemData, gamesystemFile, ModelComponentType_1.ModelComponentType.GAMESYTEM);
}
}
}
exports.GamesystemLoader = GamesystemLoader;
//# sourceMappingURL=GamesystemLoader.js.map