Persist CharacterspecificTemplatesystems
All checks were successful
E2E Testing / test (push) Successful in 1m33s
All checks were successful
E2E Testing / test (push) Successful in 1m33s
This commit is contained in:
parent
5a2282ddd3
commit
21bc329778
@ -2,9 +2,13 @@ import {Character} from "../game-model/characters/Character";
|
|||||||
import {StoreComponent} from "../../../../app/storage/StoreComponent";
|
import {StoreComponent} from "../../../../app/storage/StoreComponent";
|
||||||
import {SerializeConstants} from "./SerializeConstants";
|
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 {Gamesystem} from "../game-model/gamesystems/Gamesystem";
|
||||||
|
|
||||||
export class CharacterSerializer {
|
export class CharacterSerializer {
|
||||||
|
|
||||||
|
private static ignoredKeys: string[] = ['unsaved', 'type', 'incomingTransitions', 'outgoingTransitions', 'initial', 'conditions', 'stateDescription', 'templateType', 'parentGamesystem']
|
||||||
|
|
||||||
public static serializeCharacters(characters: Character[]): StoreComponent[] {
|
public static serializeCharacters(characters: Character[]): StoreComponent[] {
|
||||||
const storedCharacters: StoreComponent[] = []
|
const storedCharacters: StoreComponent[] = []
|
||||||
characters.forEach(character => storedCharacters.push(this.serializeSingleCharacter(character)))
|
characters.forEach(character => storedCharacters.push(this.serializeSingleCharacter(character)))
|
||||||
@ -13,14 +17,41 @@ export class CharacterSerializer {
|
|||||||
|
|
||||||
private static serializeSingleCharacter(character: Character): StoreComponent{
|
private static serializeSingleCharacter(character: Character): StoreComponent{
|
||||||
const fileName = character.componentName
|
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) => {
|
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
|
return undefined
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}, SerializeConstants.JSON_INDENT)
|
}, SerializeConstants.JSON_INDENT)
|
||||||
|
|
||||||
|
|
||||||
return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER);
|
return new StoreComponent(jsonString, fileName, ModelComponentType.CHARACTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user