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

This commit is contained in:
Sebastian Böckelmann 2024-04-14 08:02:59 +02:00
parent 5a2282ddd3
commit 21bc329778

View File

@ -2,9 +2,13 @@ import {Character} from "../game-model/characters/Character";
import {StoreComponent} from "../../../../app/storage/StoreComponent";
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";
export class CharacterSerializer {
private static ignoredKeys: string[] = ['unsaved', 'type', 'incomingTransitions', 'outgoingTransitions', 'initial', 'conditions', 'stateDescription', 'templateType', 'parentGamesystem']
public static serializeCharacters(characters: Character[]): StoreComponent[] {
const storedCharacters: StoreComponent[] = []
characters.forEach(character => storedCharacters.push(this.serializeSingleCharacter(character)))
@ -13,14 +17,41 @@ export class CharacterSerializer {
private static serializeSingleCharacter(character: Character): StoreComponent{
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(key === 'unsaved' || key === 'type') {
if(value instanceof Gamesystem) {
return {
...value,
componentDescription: undefined,
parentGamesystem: undefined
}
}
if(key === 'scriptAccount') {
return value.componentName
}
if(key === 'conditionMap' || key === 'actionMap') {
if(value.get(character) == undefined) {
return []
}
return value.get(character)
}
if(key === 'startingState' || key === 'endingState') {
return value.stateLabel
}
if(this.ignoredKeys.includes(key)) {
return undefined
} else {
return value;
}
}, SerializeConstants.JSON_INDENT)
return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER);
}
}