alt-templatesystem-impl #29

Closed
sebastian wants to merge 23 commits from alt-templatesystem-impl into character-specific-gamesystems
3 changed files with 48 additions and 2 deletions
Showing only changes of commit f80e4c3cfa - Show all commits

View File

@ -211,7 +211,7 @@ export class AppComponent implements OnInit{
const gamesystemParser = new GamesystemParser(scriptAccounts); const gamesystemParser = new GamesystemParser(scriptAccounts);
const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems); const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems);
const characterParser = new CharacterParser(); const characterParser = new CharacterParser(gamesystemParser.getParsedTemplateGamesystems(TemplateType.CHARACTER));
const characters = characterParser.parseCharacters(storedGameModel.storedCharacters); const characters = characterParser.parseCharacters(storedGameModel.storedCharacters);
gameModel.scriptAccounts = scriptAccounts gameModel.scriptAccounts = scriptAccounts

View File

@ -1,9 +1,16 @@
import {StoreComponent} from "../../../../../app/storage/StoreComponent"; import {StoreComponent} from "../../../../../app/storage/StoreComponent";
import {Character} from "../../game-model/characters/Character"; import {Character} from "../../game-model/characters/Character";
import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTemplateGamesystem";
export class CharacterParser { export class CharacterParser {
characterSpecificGamesystems: SimpleTemplateGamesystem<Character>[]
constructor(characterSpecificGamesystems: SimpleTemplateGamesystem<Character>[]) {
this.characterSpecificGamesystems = characterSpecificGamesystems;
}
public parseCharacters(characters: StoreComponent[]): Character[] { public parseCharacters(characters: StoreComponent[]): Character[] {
const loadedCharacters: Character[] = [] const loadedCharacters: Character[] = []
characters.forEach(character => loadedCharacters.push(this.parseSingleCharacter(JSON.parse(character.jsonString)))) characters.forEach(character => loadedCharacters.push(this.parseSingleCharacter(JSON.parse(character.jsonString))))
@ -11,6 +18,41 @@ export class CharacterParser {
} }
private parseSingleCharacter(characterData: any): Character { 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);
} }
} }

View File

@ -94,4 +94,8 @@ export class GamesystemParser {
return undefined return undefined
} }
getParsedTemplateGamesystems(templateType: TemplateType) {
const templateGamesystems = this.parsedGamesystems.filter(gamesystem => gamesystem.templateType === templateType);
return templateGamesystems.map(gamesystem => gamesystem as SimpleTemplateGamesystem<any>)
}
} }