inventory-items-2 #44
@ -8,6 +8,7 @@ import {ModelComponentFileDirectory} from "./storage/ModelComponentFileDirectory
|
||||
import {GamesystemStorage} from "./storage/storing/GamesystemStorage";
|
||||
import {Character} from "../src/app/project/game-model/characters/Character";
|
||||
import {CharacterStorage} from "./storage/storing/CharacterStorage";
|
||||
import {ItemgroupStorage} from "./storage/storing/ItemgroupStorage";
|
||||
|
||||
let win: BrowserWindow | null = null;
|
||||
const args = process.argv.slice(1),
|
||||
@ -270,6 +271,9 @@ function recieveGameModelToStore(gameModel: StoredGameModel) {
|
||||
|
||||
const characterStorage = new CharacterStorage(path.join(projectDirectory, ModelComponentFileDirectory.CHARACTER_DIR_NAME))
|
||||
characterStorage.storeCharacters(gameModel.storedCharacters)
|
||||
|
||||
const itemgroupStorage = new ItemgroupStorage(path.join(projectDirectory, ModelComponentFileDirectory.ITEMGROUP_DIR_NAME))
|
||||
itemgroupStorage.storeItemgroups(gameModel.storedItemgroups);
|
||||
}
|
||||
|
||||
/*function deleteComponent(component: DeleteModel) {
|
||||
|
@ -7,4 +7,5 @@ exports.ModelComponentFileDirectory = ModelComponentFileDirectory;
|
||||
ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME = "script-accounts";
|
||||
ModelComponentFileDirectory.GAMESYSTEM_DIR_NAME = "gamesystems";
|
||||
ModelComponentFileDirectory.CHARACTER_DIR_NAME = "characters";
|
||||
ModelComponentFileDirectory.ITEMGROUP_DIR_NAME = "items";
|
||||
//# sourceMappingURL=ModelComponentFileDirectory.js.map
|
@ -2,4 +2,5 @@ export class ModelComponentFileDirectory {
|
||||
public static SCRIPTACCOUNT_DIR_NAME = "script-accounts"
|
||||
public static GAMESYSTEM_DIR_NAME = "gamesystems";
|
||||
public static CHARACTER_DIR_NAME = "characters";
|
||||
static ITEMGROUP_DIR_NAME = "items";
|
||||
}
|
||||
|
@ -2,11 +2,12 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.StoredGameModel = void 0;
|
||||
class StoredGameModel {
|
||||
constructor(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters) {
|
||||
constructor(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, storedItemgroups) {
|
||||
this.gameModelName = gameModelName;
|
||||
this.storedGamesystems = storedGamesystems;
|
||||
this.storedScriptAccounts = storedScriptAccounts;
|
||||
this.storedCharacters = storedCharacters;
|
||||
this.storedItemgroups = storedItemgroups;
|
||||
}
|
||||
}
|
||||
exports.StoredGameModel = StoredGameModel;
|
||||
|
@ -6,13 +6,15 @@ export class StoredGameModel {
|
||||
storedGamesystems: StoreComponent[]
|
||||
storedScriptAccounts: StoreComponent[]
|
||||
storedCharacters: StoreComponent[]
|
||||
storedItemgroups: StoreComponent[]
|
||||
|
||||
|
||||
constructor(gameModelName: string, storedScriptAccounts: StoreComponent[], storedGamesystems: StoreComponent[],
|
||||
storedCharacters: StoreComponent[]) {
|
||||
storedCharacters: StoreComponent[], storedItemgroups: StoreComponent[]) {
|
||||
this.gameModelName = gameModelName;
|
||||
this.storedGamesystems = storedGamesystems;
|
||||
this.storedScriptAccounts = storedScriptAccounts;
|
||||
this.storedCharacters = storedCharacters;
|
||||
this.storedItemgroups = storedItemgroups;
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class GameModelLoader {
|
||||
const storedScriptAccounts = this.loadScriptAccountComponents();
|
||||
const storedGamesystems = this.loadGamesystems();
|
||||
const storedCharacters = this.loadCharacters();
|
||||
return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters);
|
||||
return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, []);
|
||||
}
|
||||
loadScriptAccountComponents() {
|
||||
const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME);
|
||||
|
@ -22,7 +22,7 @@ export class GameModelLoader {
|
||||
const storedGamesystems = this.loadGamesystems();
|
||||
const storedCharacters = this.loadCharacters()
|
||||
|
||||
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters);
|
||||
return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, []);
|
||||
}
|
||||
|
||||
private loadScriptAccountComponents() {
|
||||
|
29
app/storage/storing/ItemgroupStorage.js
Normal file
29
app/storage/storing/ItemgroupStorage.js
Normal file
@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ItemgroupStorage = void 0;
|
||||
const FileUtils_1 = require("../FileUtils");
|
||||
const path = require("node:path");
|
||||
const fs = require("node:fs");
|
||||
class ItemgroupStorage {
|
||||
constructor(itemgroupDir) {
|
||||
this.itemgroupDir = itemgroupDir;
|
||||
FileUtils_1.FileUtils.prepareDirectoryFroWriting(this.itemgroupDir);
|
||||
}
|
||||
storeItemgroups(itemgroups) {
|
||||
console.log("Store Itemgroups");
|
||||
itemgroups.forEach(itemgroup => {
|
||||
this.storeItemgroup(itemgroup);
|
||||
});
|
||||
}
|
||||
storeItemgroup(itemgroup) {
|
||||
const file = path.join(...itemgroup.fileName.split("/"));
|
||||
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");
|
||||
}
|
||||
}
|
||||
exports.ItemgroupStorage = ItemgroupStorage;
|
||||
//# sourceMappingURL=ItemgroupStorage.js.map
|
34
app/storage/storing/ItemgroupStorage.ts
Normal file
34
app/storage/storing/ItemgroupStorage.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import {FileUtils} from "../FileUtils";
|
||||
import {StoreComponent} from "../StoreComponent";
|
||||
import * as path from "node:path";
|
||||
import * as fs from "node:fs";
|
||||
|
||||
export class ItemgroupStorage {
|
||||
private itemgroupDir: string
|
||||
|
||||
|
||||
constructor(itemgroupDir: string) {
|
||||
this.itemgroupDir = itemgroupDir;
|
||||
FileUtils.prepareDirectoryFroWriting(this.itemgroupDir);
|
||||
}
|
||||
|
||||
public storeItemgroups(itemgroups: StoreComponent[]) {
|
||||
console.log("Store Itemgroups")
|
||||
itemgroups.forEach(itemgroup => {
|
||||
this.storeItemgroup(itemgroup)
|
||||
})
|
||||
}
|
||||
|
||||
private storeItemgroup(itemgroup: StoreComponent) {
|
||||
const file = path.join(... itemgroup.fileName.split("/"));
|
||||
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.prepareDirectoryFroWriting(completeItemgroupDirectory);
|
||||
fs.writeFileSync(completeFileName + ".json", itemgroup.jsonString, "utf-8")
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -27,6 +27,7 @@ import {CharacterParser} from "./project/parser/characterParser/CharacterParser"
|
||||
import {TemplateType} from "./project/game-model/templates/TemplateType";
|
||||
import {TemplateTypeUtilities} from "./project/game-model/templates/TemplateTypeUtilities";
|
||||
import {SimpleTemplateGamesystem} from "./project/game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
|
||||
import {ItemSerializer} from "./project/serializer/ItemSerializer";
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@ -231,7 +232,10 @@ export class AppComponent implements OnInit{
|
||||
const storedScriptAccounts = ScriptAccountSerializer.serializeScriptAccounts(this.gameModel.scriptAccounts)
|
||||
const storedGamesystems: StoreComponent[] = GamesystemSerializer.serializeGamesystems(this.gameModel.gamesystems)
|
||||
const storedCharacters: StoreComponent[] = CharacterSerializer.serializeCharacters(this.gameModel.characters)
|
||||
const storeModel = new StoredGameModel(this.gameModel.gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters)
|
||||
|
||||
const itemSerializer = new ItemSerializer();
|
||||
const storedItemgroups: StoreComponent[] = itemSerializer.serializeItemgroups(this.gameModel!.itemgroups);
|
||||
const storeModel = new StoredGameModel(this.gameModel.gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters, storedItemgroups)
|
||||
|
||||
if(this.electronService.isElectron) {
|
||||
this.electronService.ipcRenderer.send('save-model', storeModel)
|
||||
|
@ -16,6 +16,7 @@ import {AbstractItemGroup} from "./inventory/AbstractItemGroup";
|
||||
import {ConcreteItemGroup} from "./inventory/ConcreteItemGroup";
|
||||
import {Item} from "./inventory/Item";
|
||||
import {ItemgroupUtilities} from "./utils/ItemgroupUtilities";
|
||||
import {ItemGroupCharacteristic} from "./inventory/ItemgroupCharacteristic";
|
||||
|
||||
export class GameModel {
|
||||
gameModelName: string
|
||||
@ -29,11 +30,13 @@ export class GameModel {
|
||||
this.gameModelName = gameModelName;
|
||||
|
||||
this.addAbstractItemgroup("Clothing", undefined);
|
||||
this.addConcreteItemgroup("Inventory", undefined);
|
||||
this.addAbstractItemgroup("Inventory", undefined);
|
||||
this.addConcreteItemgroup("Oberteil", GameModel.findItemgroupByName("Clothing", this.itemgroups)! as AbstractItemGroup);
|
||||
this.addConcreteItemgroup("Hose", GameModel.findItemgroupByName("Clothing", this.itemgroups)! as AbstractItemGroup);
|
||||
|
||||
this.addItem("Hose 1", "Hose");
|
||||
const item = this.addItem("Hose 1", "Hose");
|
||||
item!.addInheritedGroup(GameModel.findItemgroupByName("Inventory", this.itemgroups!)!)
|
||||
console.log(GameModel.findItemgroupByName("Inventory", this.itemgroups!)!.manuallyInheritedItems)
|
||||
this.addItem("Hose 2", "Hose");
|
||||
}
|
||||
|
||||
@ -41,7 +44,9 @@ export class GameModel {
|
||||
//Ensure that Itemgroup does not exist
|
||||
if(parentgroup == undefined) {
|
||||
if(GameModel.findItemgroupByName(groupName, this.itemgroups) == undefined) {
|
||||
this.itemgroups.push(new AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP));
|
||||
const itemgroup = new AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP)
|
||||
this.itemgroups.push(itemgroup);
|
||||
itemgroup.addItemgroupCharacteristic(new ItemGroupCharacteristic("Test0", "", itemgroup));
|
||||
}
|
||||
} else {
|
||||
if(GameModel.findItemgroupByName(groupName, parentgroup.children) == undefined) {
|
||||
@ -69,7 +74,9 @@ export class GameModel {
|
||||
const itemgroups: ItemGroup[] = ItemgroupUtilities.findItemgroupPathToItemgroup(conceteItemgroupName, this.itemgroups);
|
||||
|
||||
if(itemgroups.length > 0) {
|
||||
itemgroup.addItem(new Item(itemName, "", ModelComponentType.ITEM ), itemgroups)
|
||||
const item = new Item(itemName, "", ModelComponentType.ITEM )
|
||||
itemgroup.addItem(item, itemgroups)
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,7 @@ export class GamesystemSerializer {
|
||||
|
||||
private static serializeSimpleGamesystem(simpleGamesystem: SimpleGamesystem): StoreComponent {
|
||||
const fileName = this.computeSimpleGamesystemPath(simpleGamesystem);
|
||||
if(simpleGamesystem.componentName === "Weather(Child)") {
|
||||
console.log(fileName)
|
||||
}
|
||||
const jsonString = JSON.stringify(simpleGamesystem, (key, value) => {
|
||||
|
||||
if(this.IGNORED_SIMPLE_ATTRIBUTES.includes(key)) {
|
||||
|
64
src/app/project/serializer/ItemSerializer.ts
Normal file
64
src/app/project/serializer/ItemSerializer.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import {ItemGroup} from "../game-model/inventory/ItemGroup";
|
||||
import {StoreComponent} from "../../../../app/storage/StoreComponent";
|
||||
import {AbstractItemGroup} from "../game-model/inventory/AbstractItemGroup";
|
||||
import {ConcreteItemGroup} from "../game-model/inventory/ConcreteItemGroup";
|
||||
import {ModelComponentType} from "../game-model/ModelComponentType";
|
||||
import {SerializeConstants} from "./SerializeConstants";
|
||||
|
||||
export class ItemSerializer {
|
||||
|
||||
private serializedItemgroups: StoreComponent[] = []
|
||||
private static ignoredKeys: string[] = ['type', 'unsaved', 'children', "itemgroup", "manuallyInheritedGroups", "hierarchyInheritedGroups", "items"]
|
||||
|
||||
public serializeItemgroups(itemgroups: ItemGroup[]): StoreComponent[] {
|
||||
itemgroups.forEach(itemgroup => {
|
||||
this.serializeSingleItemgroupHierarchy(itemgroup)
|
||||
})
|
||||
return this.serializedItemgroups;
|
||||
}
|
||||
|
||||
private serializeSingleItemgroupHierarchy(itemgroup: ItemGroup) {
|
||||
if(itemgroup instanceof AbstractItemGroup) {
|
||||
const storeComponent = this.serializeItemgroup(itemgroup)
|
||||
this.serializedItemgroups.push(storeComponent)
|
||||
itemgroup.children.forEach(child => this.serializeSingleItemgroupHierarchy(child));
|
||||
} else {
|
||||
const storeComponent = this.serializeItemgroup(itemgroup);
|
||||
this.serializedItemgroups.push(storeComponent)
|
||||
}
|
||||
}
|
||||
|
||||
private serializeItemgroup(itemgroup: ItemGroup): StoreComponent {
|
||||
const componentType = ModelComponentType.ITEMGROUP;
|
||||
const fileName = ItemSerializer.computeItemgroupPath(itemgroup);
|
||||
|
||||
const jsonString = JSON.stringify(itemgroup, (key, value) => {
|
||||
if(ItemSerializer.ignoredKeys.includes(key)) {
|
||||
return undefined
|
||||
} else {
|
||||
|
||||
if(key === 'key') {
|
||||
return value.characteristicName
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
}, SerializeConstants.JSON_INDENT);
|
||||
console.log(fileName)
|
||||
return new StoreComponent(jsonString, fileName, componentType)
|
||||
}
|
||||
|
||||
private static computeItemgroupPath(itemgroup: ItemGroup): string {
|
||||
const itemgroupPath: string[] = [];
|
||||
itemgroupPath.push(itemgroup.componentName);
|
||||
itemgroupPath.push(itemgroup.componentName);
|
||||
|
||||
while(itemgroup.parentGroup !== undefined) {
|
||||
itemgroupPath.unshift(itemgroup.parentGroup.componentName);
|
||||
itemgroup = itemgroup.parentGroup;
|
||||
}
|
||||
|
||||
return itemgroupPath.join("/");
|
||||
}
|
||||
}
|
11
testModel/items/Clothing/Clothing.json
Normal file
11
testModel/items/Clothing/Clothing.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"componentName": "Clothing",
|
||||
"componentDescription": "",
|
||||
"itemGroupCharacteristics": [
|
||||
{
|
||||
"characteristicName": "Test0",
|
||||
"characteristicDescription": ""
|
||||
}
|
||||
],
|
||||
"manuallyInheritedItems": []
|
||||
}
|
17
testModel/items/Clothing/Hose/Hose.json
Normal file
17
testModel/items/Clothing/Hose/Hose.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"componentName": "Hose",
|
||||
"componentDescription": "",
|
||||
"itemGroupCharacteristics": [],
|
||||
"manuallyInheritedItems": [],
|
||||
"parentGroup": {
|
||||
"componentName": "Clothing",
|
||||
"componentDescription": "",
|
||||
"itemGroupCharacteristics": [
|
||||
{
|
||||
"characteristicName": "Test0",
|
||||
"characteristicDescription": ""
|
||||
}
|
||||
],
|
||||
"manuallyInheritedItems": []
|
||||
}
|
||||
}
|
17
testModel/items/Clothing/Oberteil/Oberteil.json
Normal file
17
testModel/items/Clothing/Oberteil/Oberteil.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"componentName": "Oberteil",
|
||||
"componentDescription": "",
|
||||
"itemGroupCharacteristics": [],
|
||||
"manuallyInheritedItems": [],
|
||||
"parentGroup": {
|
||||
"componentName": "Clothing",
|
||||
"componentDescription": "",
|
||||
"itemGroupCharacteristics": [
|
||||
{
|
||||
"characteristicName": "Test0",
|
||||
"characteristicDescription": ""
|
||||
}
|
||||
],
|
||||
"manuallyInheritedItems": []
|
||||
}
|
||||
}
|
22
testModel/items/Inventory/Inventory.json
Normal file
22
testModel/items/Inventory/Inventory.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"componentName": "Inventory",
|
||||
"componentDescription": "",
|
||||
"itemGroupCharacteristics": [
|
||||
{
|
||||
"characteristicName": "Test0",
|
||||
"characteristicDescription": ""
|
||||
}
|
||||
],
|
||||
"manuallyInheritedItems": [
|
||||
{
|
||||
"componentName": "Hose 1",
|
||||
"componentDescription": "",
|
||||
"itemCharacteristicValues": [
|
||||
{
|
||||
"key": "Test0",
|
||||
"value": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user