Persist Character Inventory Slots
All checks were successful
E2E Testing / test (push) Successful in 1m33s

This commit is contained in:
Sebastian Böckelmann 2024-05-11 14:52:40 +02:00
parent bc523029fc
commit 86097a898a
4 changed files with 50 additions and 6 deletions

View File

@ -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);
}

View File

@ -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
})
}
})
}
}

View File

@ -66,5 +66,7 @@
"generateIsolatedStates": true,
"symmetric": true
}
]
],
"inventorySlots": [],
"combinableInventorySlots": []
}

View File

@ -66,5 +66,20 @@
"generateIsolatedStates": true,
"symmetric": true
}
],
"inventorySlots": [
{
"slotName": "New Inventory Slot",
"slotCharacteristics": [
{
"increasingCharacteristic": "Test0",
"decreasingCharacteristic": "Test0"
}
],
"requiredInheritances": [
"Clothing"
]
}
],
"combinableInventorySlots": []
}