diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 6b962e0..3ad2831 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -219,7 +219,8 @@ export class AppComponent implements OnInit{ gameModel.generateProductSystemContents() const characterTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER).map(templateSystem => templateSystem as SimpleTemplateGamesystem) - const characterParser = new CharacterParser(characterTemplateSystems, gameModel.scriptAccounts); + const characterRelationTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER_RELATION).map(templateSystem => templateSystem as SimpleTemplateGamesystem) + const characterParser = new CharacterParser(characterTemplateSystems, characterRelationTemplateSystems, gameModel.scriptAccounts); gameModel.characters = characterParser.parseCharacters(storedGameModel.storedCharacters) this.gameModel = gameModel; diff --git a/src/app/project/game-model/characters/Character.ts b/src/app/project/game-model/characters/Character.ts index cba8e91..411abf6 100644 --- a/src/app/project/game-model/characters/Character.ts +++ b/src/app/project/game-model/characters/Character.ts @@ -14,7 +14,7 @@ export class Character extends ModelComponent implements TemplateElement { characterRelations: CharacterRelation[] = [] - assymetricCharacterRelationSpecificTemplateSystems: Gamesystem[] = [] + characterRelationGamesystems: Gamesystem[] = [] constructor(componentName: string, componentDescription: string) { super(componentName, componentDescription, ModelComponentType.CHARACTER); @@ -44,10 +44,12 @@ export class Character extends ModelComponent implements TemplateElement { addAsymetricCharacterRelationGamesystem(gamesystem: Gamesystem, recursiveCall: boolean = false) { if(!this.isTemplateSystemCharacterRelationSpecific(gamesystem.componentName)) { if(gamesystem instanceof SimpleTemplateGamesystem) { - this.assymetricCharacterRelationSpecificTemplateSystems.push(gamesystem); + this.characterRelationGamesystems.push(gamesystem); gamesystem.addTemplateElement(this); + console.log("Should have been added") + console.log(this.characterRelationGamesystems) } else if(gamesystem instanceof ProductTemplateSystem) { - this.characterSpecificTemplateSystems.push(gamesystem); + this.characterRelationGamesystems.push(gamesystem); gamesystem.addTemplateElement(this); if(!recursiveCall) { @@ -59,6 +61,9 @@ export class Character extends ModelComponent implements TemplateElement { this.addAsymetricCharacterRelationGamesystem(gamesystem.parentGamesystem, true) } + } else { + console.log("Was already added") + console.log(this) } } @@ -71,7 +76,7 @@ export class Character extends ModelComponent implements TemplateElement { } private isTemplateSystemCharacterRelationSpecific(gamesystemName: string) { - return this.assymetricCharacterRelationSpecificTemplateSystems.find(gamesystem => + return this.characterRelationGamesystems.find(gamesystem => gamesystem.componentName === gamesystemName) != undefined; } diff --git a/src/app/project/parser/characterParser/CharacterParser.ts b/src/app/project/parser/characterParser/CharacterParser.ts index f980445..4e4e770 100644 --- a/src/app/project/parser/characterParser/CharacterParser.ts +++ b/src/app/project/parser/characterParser/CharacterParser.ts @@ -8,16 +8,19 @@ import {SimpleTemplateState} from "../../game-model/templates/simpleGamesystem/S import {SimpleTemplateTransition} from "../../game-model/templates/simpleGamesystem/SimpleTemplateTransition"; import {CharacterRelation} from "../../game-model/characters/CharacterRelation"; import {load} from "@angular-devkit/build-angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks"; +import {Gamesystem} from "../../game-model/gamesystems/Gamesystem"; export class CharacterParser { characterSpecificGamesystems: SimpleTemplateGamesystem[] + characterRelationSpecificGamesystems: SimpleTemplateGamesystem[] scriptAccountConditionParser: ScriptAccountConditionParser scriptAccountActionParser: ScriptAccountActionParser - constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[], scriptAccounts: ScriptAccount[]) { + constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[], characterRelationSpecificGamesystems: SimpleTemplateGamesystem[], scriptAccounts: ScriptAccount[]) { this.characterSpecificGamesystems = characterSpecificGamesystems; + this.characterRelationSpecificGamesystems = characterRelationSpecificGamesystems; this.scriptAccountActionParser = new ScriptAccountActionParser(scriptAccounts); this.scriptAccountConditionParser = new ScriptAccountConditionParser(scriptAccounts) } @@ -38,23 +41,26 @@ export class CharacterParser { character.addCharacterRelation(characterRelation) }) - const templateSpecificGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterSpecificTemplateSystems); + const templateSpecificGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterSpecificTemplateSystems, this.characterSpecificGamesystems); templateSpecificGamesystems.forEach(system => character.addCharacterSpecificSimpleTemplatesystem(system)) + + const characterRelationGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterRelationGamesystems, this.characterRelationSpecificGamesystems) + characterRelationGamesystems.forEach(gamesystem => character.addAsymetricCharacterRelationGamesystem(gamesystem)) return character; } - private parseCharacterSpecificGamesystems(character: Character, characterSpecificGamesystems: any): SimpleTemplateGamesystem[] { + private parseCharacterSpecificGamesystems(character: Character, characterSpecificGamesystems: any, templateGamesystems: SimpleTemplateGamesystem[]): SimpleTemplateGamesystem[] { const result: SimpleTemplateGamesystem[] = [] for(let i=0; i gamesystem.componentName === componentName) + private findCharacterSpecificGamesystem(gamesystems: SimpleTemplateGamesystem[], componentName: string): SimpleTemplateGamesystem | undefined{ + return gamesystems.find(gamesystem => gamesystem.componentName === componentName) } private findReferencedState(gamesystem: SimpleTemplateGamesystem, stateLabel: string) { diff --git a/src/app/project/serializer/CharacterSerializer.ts b/src/app/project/serializer/CharacterSerializer.ts index bc0d21e..600d065 100644 --- a/src/app/project/serializer/CharacterSerializer.ts +++ b/src/app/project/serializer/CharacterSerializer.ts @@ -7,7 +7,7 @@ import {Gamesystem} from "../game-model/gamesystems/Gamesystem"; export class CharacterSerializer { - private static ignoredKeys: string[] = ['unsaved', 'type', 'incomingTransitions', 'outgoingTransitions', 'initial', 'conditions', 'stateDescription', 'templateType', 'parentGamesystem', 'scriptAccountActions', 'scriptAccountConditions'] + private static ignoredKeys: string[] = ['unsaved', 'type', 'incomingTransitions', 'outgoingTransitions', 'initial', 'conditions', 'stateDescription', 'templateType', 'parentGamesystem', 'scriptAccountActions', 'scriptAccountConditions', 'characterRelations'] public static serializeCharacters(characters: Character[]): StoreComponent[] { const storedCharacters: StoreComponent[] = [] diff --git a/testModel/characters/Astrid Hofferson.json b/testModel/characters/Astrid Hofferson.json index 9437d7c..21cfeca 100644 --- a/testModel/characters/Astrid Hofferson.json +++ b/testModel/characters/Astrid Hofferson.json @@ -1,5 +1,6 @@ { "componentName": "Astrid Hofferson", "componentDescription": "", - "characterSpecificTemplateSystems": [] + "characterSpecificTemplateSystems": [], + "characterRelationGamesystems": [] } \ No newline at end of file diff --git a/testModel/characters/Hicks Haddock.json b/testModel/characters/Hicks Haddock.json index 1f75bd9..414d072 100644 --- a/testModel/characters/Hicks Haddock.json +++ b/testModel/characters/Hicks Haddock.json @@ -1,5 +1,50 @@ { "componentName": "Hicks Haddock", "componentDescription": "", - "characterSpecificTemplateSystems": [] + "characterSpecificTemplateSystems": [], + "characterRelationGamesystems": [ + { + "componentName": "Characterbeziehungssystem", + "states": [ + { + "stateLabel": "Feind", + "conditionMap": [] + }, + { + "stateLabel": "Freund", + "conditionMap": [] + }, + { + "stateLabel": "Fester Freund", + "conditionMap": [] + } + ], + "transitions": [ + { + "startingState": "Feind", + "endingState": "Freund", + "conditionMap": [], + "actionMap": [] + }, + { + "startingState": "Freund", + "endingState": "Feind", + "conditionMap": [], + "actionMap": [] + }, + { + "startingState": "Freund", + "endingState": "Fester Freund", + "conditionMap": [], + "actionMap": [] + }, + { + "startingState": "Fester Freund", + "endingState": "Feind", + "conditionMap": [], + "actionMap": [] + } + ] + } + ] } \ No newline at end of file