alt-templatesystem-impl #29
@ -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
|
||||
|
@ -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<Character>[]
|
||||
|
||||
constructor(characterSpecificGamesystems: SimpleTemplateGamesystem<Character>[]) {
|
||||
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<Character>[] {
|
||||
const result: SimpleTemplateGamesystem<Character>[] = []
|
||||
for(let i=0; i<characterSpecificGamesystems.length; i++) {
|
||||
const characterSpecificGamesystem = characterSpecificGamesystems[i];
|
||||
result.push(this.parseSingleCharacterSpecificGamesystem(characterSpecificGamesystem)!)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private parseSingleCharacterSpecificGamesystem(characterSpecificGamesystem: any): SimpleTemplateGamesystem<Character> | undefined{
|
||||
const referencedGamesystem = this.findCharacterSpecificGamesystem(characterSpecificGamesystem.componentName)
|
||||
|
||||
if(referencedGamesystem != undefined) {
|
||||
for(let i=0; i<characterSpecificGamesystem.states.length; i++) {
|
||||
const stateReference = characterSpecificGamesystem.states[i];
|
||||
const state = this.findReferencedState(referencedGamesystem, stateReference.stateLabel)!
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return referencedGamesystem;
|
||||
}
|
||||
|
||||
private findCharacterSpecificGamesystem(componentName: string): SimpleTemplateGamesystem<Character> | undefined{
|
||||
return this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === componentName)
|
||||
}
|
||||
|
||||
private findReferencedState(gamesystem: SimpleTemplateGamesystem<Character>, stateLabel: string) {
|
||||
return gamesystem.states.find(state => state.stateLabel === stateLabel);
|
||||
}
|
||||
}
|
||||
|
@ -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<any>)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user