Compare commits
2 Commits
2e29d4cde7
...
8345b541d4
Author | SHA1 | Date | |
---|---|---|---|
|
8345b541d4 | ||
|
cb2094aa49 |
43
app/storage/loader/ItemLoader.js
Normal file
43
app/storage/loader/ItemLoader.js
Normal 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
|
Loading…
Reference in New Issue
Block a user