main #48
@ -7,6 +7,7 @@ const ModelComponentFileDirectory_1 = require("../ModelComponentFileDirectory");
|
||||
const ScriptAccountLoader_1 = require("./ScriptAccountLoader");
|
||||
const GamesystemLoader_1 = require("./GamesystemLoader");
|
||||
const CharacterLoader_1 = require("./CharacterLoader");
|
||||
const ItemLoader_1 = require("./ItemLoader");
|
||||
class GameModelLoader {
|
||||
constructor(gameModelDir) {
|
||||
this.gameModelDir = gameModelDir;
|
||||
@ -16,6 +17,7 @@ class GameModelLoader {
|
||||
const storedScriptAccounts = this.loadScriptAccountComponents();
|
||||
const storedGamesystems = this.loadGamesystems();
|
||||
const storedCharacters = this.loadCharacters();
|
||||
const storedItemgroupsd = this.loadItemgroups();
|
||||
return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, [], []);
|
||||
}
|
||||
loadScriptAccountComponents() {
|
||||
@ -33,6 +35,11 @@ class GameModelLoader {
|
||||
const characterLoader = new CharacterLoader_1.CharacterLoader(characterDir);
|
||||
return characterLoader.loadCharacters();
|
||||
}
|
||||
loadItemgroups() {
|
||||
const itemgroupDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.ITEMGROUP_DIR_NAME);
|
||||
const itemgroupLoader = new ItemLoader_1.ItemLoader(itemgroupDir);
|
||||
return itemgroupLoader.loadItemgroups();
|
||||
}
|
||||
}
|
||||
exports.GameModelLoader = GameModelLoader;
|
||||
//# sourceMappingURL=GameModelLoader.js.map
|
@ -6,6 +6,7 @@ import {ModelComponentFileDirectory} from "../ModelComponentFileDirectory";
|
||||
import {ScriptAccountLoader} from "./ScriptAccountLoader";
|
||||
import {GamesystemLoader} from "./GamesystemLoader";
|
||||
import {CharacterLoader} from "./CharacterLoader";
|
||||
import {ItemLoader} from "./ItemLoader";
|
||||
|
||||
export class GameModelLoader {
|
||||
gameModelDir: string
|
||||
@ -21,8 +22,9 @@ export class GameModelLoader {
|
||||
const storedScriptAccounts = this.loadScriptAccountComponents();
|
||||
const storedGamesystems = this.loadGamesystems();
|
||||
const storedCharacters = this.loadCharacters()
|
||||
const storedItemgroups = this.loadItemgroups()
|
||||
|
||||
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, [], []);
|
||||
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, storedItemgroups, []);
|
||||
}
|
||||
|
||||
private loadScriptAccountComponents() {
|
||||
@ -44,7 +46,9 @@ export class GameModelLoader {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private loadItemgroups() {
|
||||
const itemgroupDir = path.join(this.gameModelDir, ModelComponentFileDirectory.ITEMGROUP_DIR_NAME);
|
||||
const itemgroupLoader = new ItemLoader(itemgroupDir);
|
||||
return itemgroupLoader.loadItemgroups();
|
||||
}
|
||||
}
|
||||
|
46
app/storage/loader/ItemLoader.ts
Normal file
46
app/storage/loader/ItemLoader.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import {StoreComponent} from "../StoreComponent";
|
||||
import {FileUtils} from "../FileUtils";
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import {ModelComponentType} from "../../../src/app/project/game-model/ModelComponentType";
|
||||
|
||||
export class ItemLoader {
|
||||
|
||||
itemDir: string
|
||||
|
||||
constructor(itemDir: string) {
|
||||
this.itemDir = itemDir;
|
||||
}
|
||||
|
||||
loadItemgroups(): StoreComponent[] {
|
||||
return this.loadItemgroupsRecursively(this.itemDir);
|
||||
}
|
||||
|
||||
private loadItemgroupsRecursively(currentDir: string): StoreComponent[] {
|
||||
let loadedItemgroups : StoreComponent[] = []
|
||||
const itemgroupFiles = 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;
|
||||
}
|
||||
|
||||
private loadSingleItemgroup(itemgroupFile: string): StoreComponent | undefined {
|
||||
if(itemgroupFile.endsWith(".json")) {
|
||||
const data = fs.readFileSync(itemgroupFile, "utf-8");
|
||||
return new StoreComponent(data, itemgroupFile, ModelComponentType.ITEMGROUP);
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
private fileRepresentsItemgroup(file: string): boolean {
|
||||
return path.basename(path.dirname(file)) === path.parse(path.basename(file)).name;
|
||||
}
|
||||
}
|
@ -19,7 +19,6 @@ class ItemgroupStorage {
|
||||
const completeFileName = path.join(this.itemgroupDir, file);
|
||||
const itemgroupDirectory = path.join(...itemgroup.fileName.split("/").slice(0, -1));
|
||||
const completeItemgroupDirectory = path.join(this.itemgroupDir, itemgroupDirectory);
|
||||
console.log(completeItemgroupDirectory);
|
||||
FileUtils_1.FileUtils.prepareDirectoryFroWriting(completeItemgroupDirectory);
|
||||
fs.writeFileSync(completeFileName + ".json", itemgroup.jsonString, "utf-8");
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ export class ItemgroupStorage {
|
||||
|
||||
const itemgroupDirectory = path.join(... itemgroup.fileName.split("/").slice(0, -1))
|
||||
const completeItemgroupDirectory = path.join(this.itemgroupDir, itemgroupDirectory)
|
||||
console.log(completeItemgroupDirectory)
|
||||
FileUtils.prepareDirectoryFroWriting(completeItemgroupDirectory);
|
||||
fs.writeFileSync(completeFileName + ".json", itemgroup.jsonString, "utf-8")
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
import {ItemGroup} from "./ItemGroup";
|
||||
import {ItemGroupCharacteristic} from "./ItemgroupCharacteristic";
|
||||
import {ItemgroupType} from "./ItemgroupType";
|
||||
|
||||
export class AbstractItemGroup extends ItemGroup {
|
||||
|
||||
children: ItemGroup[] = [];
|
||||
itemgroupType = ItemgroupType.ABSTRACT
|
||||
|
||||
addChildItemgroup(itemGroup: ItemGroup) {
|
||||
this.children.push(itemGroup)
|
||||
|
@ -1,10 +1,12 @@
|
||||
import {ItemGroup} from "./ItemGroup";
|
||||
import {Item} from "./Item";
|
||||
import {ItemGroupCharacteristic} from "./ItemgroupCharacteristic";
|
||||
import {ItemgroupType} from "./ItemgroupType";
|
||||
|
||||
export class ConcreteItemGroup extends ItemGroup {
|
||||
|
||||
items: Item[] = [];
|
||||
itemgroupType = ItemgroupType.CONCRETE
|
||||
|
||||
addItem(item: Item, parentItemgroups: ItemGroup[]) {
|
||||
if(this.findItemByName(item.componentName) == undefined) {
|
||||
|
4
src/app/project/game-model/inventory/ItemgroupType.ts
Normal file
4
src/app/project/game-model/inventory/ItemgroupType.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum ItemgroupType {
|
||||
CONCRETE,
|
||||
ABSTRACT
|
||||
}
|
8
src/app/project/parser/itemParser/ItemgroupParser.ts
Normal file
8
src/app/project/parser/itemParser/ItemgroupParser.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import {ItemGroup} from "../../game-model/inventory/ItemGroup";
|
||||
|
||||
export class ItemgroupParser {
|
||||
|
||||
private parsedItemgroups: ItemGroup[] = []
|
||||
|
||||
|
||||
}
|
@ -7,5 +7,6 @@
|
||||
"characteristicDescription": ""
|
||||
}
|
||||
],
|
||||
"manuallyInheritedItems": []
|
||||
"manuallyInheritedItems": [],
|
||||
"itemgroupType": 1
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
"componentDescription": "",
|
||||
"itemGroupCharacteristics": [],
|
||||
"manuallyInheritedItems": [],
|
||||
"itemgroupType": 0,
|
||||
"parentGroup": {
|
||||
"componentName": "Clothing",
|
||||
"componentDescription": "",
|
||||
@ -12,6 +13,7 @@
|
||||
"characteristicDescription": ""
|
||||
}
|
||||
],
|
||||
"manuallyInheritedItems": []
|
||||
"manuallyInheritedItems": [],
|
||||
"itemgroupType": 1
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
"componentDescription": "",
|
||||
"itemGroupCharacteristics": [],
|
||||
"manuallyInheritedItems": [],
|
||||
"itemgroupType": 0,
|
||||
"parentGroup": {
|
||||
"componentName": "Clothing",
|
||||
"componentDescription": "",
|
||||
@ -12,6 +13,7 @@
|
||||
"characteristicDescription": ""
|
||||
}
|
||||
],
|
||||
"manuallyInheritedItems": []
|
||||
"manuallyInheritedItems": [],
|
||||
"itemgroupType": 1
|
||||
}
|
||||
}
|
@ -18,5 +18,6 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"itemgroupType": 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user