inventory-slots #49
@ -4,6 +4,8 @@ import {SerializeConstants} from "./SerializeConstants";
 | 
				
			|||||||
import {ModelComponentType} from "../game-model/ModelComponentType";
 | 
					import {ModelComponentType} from "../game-model/ModelComponentType";
 | 
				
			||||||
import {SimpleTemplateGamesystem} from "../game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
 | 
					import {SimpleTemplateGamesystem} from "../game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
 | 
				
			||||||
import {Gamesystem} from "../game-model/gamesystems/Gamesystem";
 | 
					import {Gamesystem} from "../game-model/gamesystems/Gamesystem";
 | 
				
			||||||
 | 
					import {ItemGroup} from "../game-model/inventory/ItemGroup";
 | 
				
			||||||
 | 
					import {InventorySlotSerializer} from "./InventorySlotSerializer";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class CharacterSerializer {
 | 
					export class CharacterSerializer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -19,7 +21,6 @@ export class CharacterSerializer {
 | 
				
			|||||||
    const fileName = character.componentName
 | 
					    const fileName = character.componentName
 | 
				
			||||||
    const templateGamesystemBackup = character.characterSpecificTemplateSystems.concat();
 | 
					    const templateGamesystemBackup = character.characterSpecificTemplateSystems.concat();
 | 
				
			||||||
    character.characterSpecificTemplateSystems = character.characterSpecificTemplateSystems.filter(system => system instanceof SimpleTemplateGamesystem)
 | 
					    character.characterSpecificTemplateSystems = character.characterSpecificTemplateSystems.filter(system => system instanceof SimpleTemplateGamesystem)
 | 
				
			||||||
    console.log("Templatesystem: ", character.characterSpecificTemplateSystems)
 | 
					 | 
				
			||||||
    const jsonString = JSON.stringify(character, (key, value) => {
 | 
					    const jsonString = JSON.stringify(character, (key, value) => {
 | 
				
			||||||
      if(value instanceof Gamesystem) {
 | 
					      if(value instanceof Gamesystem) {
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
@ -29,14 +30,15 @@ export class CharacterSerializer {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if(key == 'inventorySlots') {
 | 
				
			||||||
 | 
					        return InventorySlotSerializer.serializeInventorySlots(value)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if(key === 'scriptAccount') {
 | 
					      if(key === 'scriptAccount') {
 | 
				
			||||||
        return value.componentName
 | 
					        return value.componentName
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if(key === 'conditionMap' || key === 'actionMap' || key === 'initialMap') {
 | 
					      if(key === 'conditionMap' || key === 'actionMap' || key === 'initialMap') {
 | 
				
			||||||
        if(key === 'initialMap') {
 | 
					 | 
				
			||||||
          console.log(value)
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if(value.get(character) == undefined) {
 | 
					        if(value.get(character) == undefined) {
 | 
				
			||||||
          return []
 | 
					          return []
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -54,6 +56,8 @@ export class CharacterSerializer {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    }, SerializeConstants.JSON_INDENT)
 | 
					    }, SerializeConstants.JSON_INDENT)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    console.log(jsonString)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    character.characterSpecificTemplateSystems = templateGamesystemBackup
 | 
					    character.characterSpecificTemplateSystems = templateGamesystemBackup
 | 
				
			||||||
    return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER);
 | 
					    return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										23
									
								
								src/app/project/serializer/InventorySlotSerializer.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/app/project/serializer/InventorySlotSerializer.ts
									
									
									
									
									
										Normal 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
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -66,5 +66,7 @@
 | 
				
			|||||||
            "generateIsolatedStates": true,
 | 
					            "generateIsolatedStates": true,
 | 
				
			||||||
            "symmetric": true
 | 
					            "symmetric": true
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    ]
 | 
					    ],
 | 
				
			||||||
 | 
					    "inventorySlots": [],
 | 
				
			||||||
 | 
					    "combinableInventorySlots": []
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -66,5 +66,20 @@
 | 
				
			|||||||
            "generateIsolatedStates": true,
 | 
					            "generateIsolatedStates": true,
 | 
				
			||||||
            "symmetric": true
 | 
					            "symmetric": true
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    ]
 | 
					    ],
 | 
				
			||||||
 | 
					    "inventorySlots": [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "slotName": "New Inventory Slot",
 | 
				
			||||||
 | 
					            "slotCharacteristics": [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "increasingCharacteristic": "Test0",
 | 
				
			||||||
 | 
					                    "decreasingCharacteristic": "Test0"
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "requiredInheritances": [
 | 
				
			||||||
 | 
					                "Clothing"
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "combinableInventorySlots": []
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user