Compare commits

...

2 Commits

Author SHA1 Message Date
Sebastian Böckelmann
8345b541d4 Merge remote-tracking branch 'origin/inventory-items-2' into inventory-items-2
All checks were successful
E2E Testing / test (push) Successful in 1m38s
2024-05-09 15:25:07 +02:00
Sebastian Böckelmann
cb2094aa49 Parse Itemgroups 2024-05-09 15:24:50 +02:00

View File

@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ItemLoader = void 0;
const StoreComponent_1 = require("../StoreComponent");
const FileUtils_1 = require("../FileUtils");
const fs = require("node:fs");
const path = require("node:path");
const ModelComponentType_1 = require("../../../src/app/project/game-model/ModelComponentType");
class ItemLoader {
constructor(itemDir) {
this.itemDir = itemDir;
}
loadItemgroups() {
return this.loadItemgroupsRecursively(this.itemDir);
}
loadItemgroupsRecursively(currentDir) {
let loadedItemgroups = [];
const itemgroupFiles = FileUtils_1.FileUtils.listFilesInDirectory(currentDir);
itemgroupFiles.forEach(itemgroupFile => {
if (fs.lstatSync(itemgroupFile).isDirectory()) {
const childgroup = this.loadItemgroupsRecursively(itemgroupFile);
loadedItemgroups = loadedItemgroups.concat(childgroup);
}
else if (path.basename(itemgroupFile).endsWith(".json") && this.fileRepresentsItemgroup(itemgroupFile)) {
const loadedItemgroup = this.loadSingleItemgroup(itemgroupFile);
loadedItemgroups.push(loadedItemgroup);
}
});
return loadedItemgroups;
}
loadSingleItemgroup(itemgroupFile) {
if (itemgroupFile.endsWith(".json")) {
const data = fs.readFileSync(itemgroupFile, "utf-8");
return new StoreComponent_1.StoreComponent(data, itemgroupFile, ModelComponentType_1.ModelComponentType.ITEMGROUP);
}
return undefined;
}
fileRepresentsItemgroup(file) {
return path.basename(path.dirname(file)) === path.parse(path.basename(file)).name;
}
}
exports.ItemLoader = ItemLoader;
//# sourceMappingURL=ItemLoader.js.map