From f80e4c3cfa5ecbc27561de9643755122e101b8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 11 Apr 2024 14:58:57 +0200 Subject: [PATCH] Load Basic Characterspecific Gamesystems --- src/app/app.component.ts | 2 +- .../parser/characterParser/CharacterParser.ts | 44 ++++++++++++++++++- .../gamesystemParser/GamesystemParser.ts | 4 ++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index b0c7035..be0a940 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -211,7 +211,7 @@ export class AppComponent implements OnInit{ const gamesystemParser = new GamesystemParser(scriptAccounts); const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems); - const characterParser = new CharacterParser(); + const characterParser = new CharacterParser(gamesystemParser.getParsedTemplateGamesystems(TemplateType.CHARACTER)); const characters = characterParser.parseCharacters(storedGameModel.storedCharacters); gameModel.scriptAccounts = scriptAccounts diff --git a/src/app/project/parser/characterParser/CharacterParser.ts b/src/app/project/parser/characterParser/CharacterParser.ts index 07d7378..11b386d 100644 --- a/src/app/project/parser/characterParser/CharacterParser.ts +++ b/src/app/project/parser/characterParser/CharacterParser.ts @@ -1,9 +1,16 @@ import {StoreComponent} from "../../../../../app/storage/StoreComponent"; import {Character} from "../../game-model/characters/Character"; +import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTemplateGamesystem"; export class CharacterParser { + characterSpecificGamesystems: SimpleTemplateGamesystem[] + + constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[]) { + this.characterSpecificGamesystems = characterSpecificGamesystems; + } + public parseCharacters(characters: StoreComponent[]): Character[] { const loadedCharacters: Character[] = [] characters.forEach(character => loadedCharacters.push(this.parseSingleCharacter(JSON.parse(character.jsonString)))) @@ -11,6 +18,41 @@ export class CharacterParser { } private parseSingleCharacter(characterData: any): Character { - return new Character(characterData.componentName, characterData.componentDescription); + const character = new Character(characterData.componentName, characterData.componentDescription); + character.characterSpecificGamesystems = this.parseCharacterSpecificGamesystems(characterData.characterSpecificGamesystems); + console.log("Parsed Character", character) + return character; + } + + private parseCharacterSpecificGamesystems(characterSpecificGamesystems: any): SimpleTemplateGamesystem[] { + const result: SimpleTemplateGamesystem[] = [] + for(let i=0; i | undefined{ + const referencedGamesystem = this.findCharacterSpecificGamesystem(characterSpecificGamesystem.componentName) + + if(referencedGamesystem != undefined) { + for(let i=0; i | undefined{ + return this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === componentName) + } + + private findReferencedState(gamesystem: SimpleTemplateGamesystem, stateLabel: string) { + return gamesystem.states.find(state => state.stateLabel === stateLabel); } } diff --git a/src/app/project/parser/gamesystemParser/GamesystemParser.ts b/src/app/project/parser/gamesystemParser/GamesystemParser.ts index 029fe25..eec11c1 100644 --- a/src/app/project/parser/gamesystemParser/GamesystemParser.ts +++ b/src/app/project/parser/gamesystemParser/GamesystemParser.ts @@ -94,4 +94,8 @@ export class GamesystemParser { return undefined } + getParsedTemplateGamesystems(templateType: TemplateType) { + const templateGamesystems = this.parsedGamesystems.filter(gamesystem => gamesystem.templateType === templateType); + return templateGamesystems.map(gamesystem => gamesystem as SimpleTemplateGamesystem) + } }