From 86097a898ab7bc360211ef541062c40fe81fdf91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sat, 11 May 2024 14:52:40 +0200 Subject: [PATCH] Persist Character Inventory Slots --- .../project/serializer/CharacterSerializer.ts | 12 ++++++---- .../serializer/InventorySlotSerializer.ts | 23 +++++++++++++++++++ testModel/characters/Astrid Hofferson.json | 4 +++- testModel/characters/Hicks Haddock.json | 17 +++++++++++++- 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 src/app/project/serializer/InventorySlotSerializer.ts diff --git a/src/app/project/serializer/CharacterSerializer.ts b/src/app/project/serializer/CharacterSerializer.ts index 56dcff2..e1021e2 100644 --- a/src/app/project/serializer/CharacterSerializer.ts +++ b/src/app/project/serializer/CharacterSerializer.ts @@ -4,6 +4,8 @@ import {SerializeConstants} from "./SerializeConstants"; import {ModelComponentType} from "../game-model/ModelComponentType"; import {SimpleTemplateGamesystem} from "../game-model/templates/simpleGamesystem/SimpleTemplateGamesystem"; import {Gamesystem} from "../game-model/gamesystems/Gamesystem"; +import {ItemGroup} from "../game-model/inventory/ItemGroup"; +import {InventorySlotSerializer} from "./InventorySlotSerializer"; export class CharacterSerializer { @@ -19,7 +21,6 @@ export class CharacterSerializer { const fileName = character.componentName const templateGamesystemBackup = character.characterSpecificTemplateSystems.concat(); character.characterSpecificTemplateSystems = character.characterSpecificTemplateSystems.filter(system => system instanceof SimpleTemplateGamesystem) - console.log("Templatesystem: ", character.characterSpecificTemplateSystems) const jsonString = JSON.stringify(character, (key, value) => { if(value instanceof Gamesystem) { return { @@ -29,14 +30,15 @@ export class CharacterSerializer { } } + if(key == 'inventorySlots') { + return InventorySlotSerializer.serializeInventorySlots(value) + } + if(key === 'scriptAccount') { return value.componentName } if(key === 'conditionMap' || key === 'actionMap' || key === 'initialMap') { - if(key === 'initialMap') { - console.log(value) - } if(value.get(character) == undefined) { return [] } @@ -54,6 +56,8 @@ export class CharacterSerializer { } }, SerializeConstants.JSON_INDENT) + console.log(jsonString) + character.characterSpecificTemplateSystems = templateGamesystemBackup return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER); } diff --git a/src/app/project/serializer/InventorySlotSerializer.ts b/src/app/project/serializer/InventorySlotSerializer.ts new file mode 100644 index 0000000..ae6a6a2 --- /dev/null +++ b/src/app/project/serializer/InventorySlotSerializer.ts @@ -0,0 +1,23 @@ +import {InventorySlot} from "../game-model/inventory/intentory-slots/InventorySlot"; + +export class InventorySlotSerializer { + + private static ignoredKeys: string[] = [''] + + public static serializeInventorySlots(inventorySlots: InventorySlot[]) { + return inventorySlots.map(inventorySlot => { + return { + slotName: inventorySlot.slotName, + slotCharacteristics: inventorySlot.slotCharacteristics.map(slotCharacteristic => { + return { + increasingCharacteristic: slotCharacteristic.increasingCharacteristic!.characteristicName, + decreasingCharacteristic: slotCharacteristic.decreasingCharacteristic!.characteristicName + } + }), + requiredInheritances: inventorySlot.requiredInheritances.map(itemgroup => { + return itemgroup.componentName + }) + } + }) + } +} diff --git a/testModel/characters/Astrid Hofferson.json b/testModel/characters/Astrid Hofferson.json index 64ad8a6..1c8abed 100644 --- a/testModel/characters/Astrid Hofferson.json +++ b/testModel/characters/Astrid Hofferson.json @@ -66,5 +66,7 @@ "generateIsolatedStates": true, "symmetric": true } - ] + ], + "inventorySlots": [], + "combinableInventorySlots": [] } \ No newline at end of file diff --git a/testModel/characters/Hicks Haddock.json b/testModel/characters/Hicks Haddock.json index bfb5c9c..0a3a015 100644 --- a/testModel/characters/Hicks Haddock.json +++ b/testModel/characters/Hicks Haddock.json @@ -66,5 +66,20 @@ "generateIsolatedStates": true, "symmetric": true } - ] + ], + "inventorySlots": [ + { + "slotName": "New Inventory Slot", + "slotCharacteristics": [ + { + "increasingCharacteristic": "Test0", + "decreasingCharacteristic": "Test0" + } + ], + "requiredInheritances": [ + "Clothing" + ] + } + ], + "combinableInventorySlots": [] } \ No newline at end of file