CharacterSpecific Templatesystems #36

Merged
sebastian merged 31 commits from template-systems into main 2024-04-14 13:45:04 +02:00
2 changed files with 77 additions and 5 deletions
Showing only changes of commit df3933d147 - Show all commits

View File

@ -26,6 +26,7 @@ import {CharacterSerializer} from "./project/serializer/CharacterSerializer";
import {CharacterParser} from "./project/parser/characterParser/CharacterParser"; import {CharacterParser} from "./project/parser/characterParser/CharacterParser";
import {TemplateType} from "./project/game-model/templates/TemplateType"; import {TemplateType} from "./project/game-model/templates/TemplateType";
import {TemplateTypeUtilities} from "./project/game-model/templates/TemplateTypeUtilities"; import {TemplateTypeUtilities} from "./project/game-model/templates/TemplateTypeUtilities";
import {SimpleTemplateGamesystem} from "./project/game-model/templates/simpleGamesystem/SimpleTemplateGamesystem";
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@ -208,14 +209,13 @@ 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 characters = characterParser.parseCharacters(storedGameModel.storedCharacters);
gameModel.scriptAccounts = scriptAccounts gameModel.scriptAccounts = scriptAccounts
gameModel.gamesystems = gamesystems gameModel.gamesystems = gamesystems
gameModel.generateProductSystemContents() gameModel.generateProductSystemContents()
gameModel.characters = characters const characterTemplateSystems = gameModel.getTemplateSystems(TemplateType.CHARACTER).map(templateSystem => templateSystem as SimpleTemplateGamesystem)
const characterParser = new CharacterParser(characterTemplateSystems, gameModel.scriptAccounts);
gameModel.characters = characterParser.parseCharacters(storedGameModel.storedCharacters)
this.gameModel = gameModel; this.gameModel = gameModel;
} }

View File

@ -1,9 +1,26 @@
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/templates/simpleGamesystem/SimpleTemplateGamesystem";
import {ScriptAccountActionParser} from "../gamesystemParser/ScriptAccountActionParser";
import {ScriptAccountConditionParser} from "../gamesystemParser/ScriptAccountConditionParser";
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {SimpleTemplateState} from "../../game-model/templates/simpleGamesystem/SimpleTemplateState";
import {SimpleTemplateTransition} from "../../game-model/templates/simpleGamesystem/SimpleTemplateTransition";
export class CharacterParser { export class CharacterParser {
characterSpecificGamesystems: SimpleTemplateGamesystem[]
scriptAccountConditionParser: ScriptAccountConditionParser
scriptAccountActionParser: ScriptAccountActionParser
constructor(characterSpecificGamesystems: SimpleTemplateGamesystem[], scriptAccounts: ScriptAccount[]) {
this.characterSpecificGamesystems = characterSpecificGamesystems;
this.scriptAccountActionParser = new ScriptAccountActionParser(scriptAccounts);
this.scriptAccountConditionParser = new ScriptAccountConditionParser(scriptAccounts)
}
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 +28,61 @@ 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);
const templateSpecificGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterSpecificTemplateSystems);
templateSpecificGamesystems.forEach(system => character.addCharacterSpecificSimpleTemplatesystem(system))
return character;
} }
private parseCharacterSpecificGamesystems(character: Character, characterSpecificGamesystems: any): SimpleTemplateGamesystem[] {
const result: SimpleTemplateGamesystem[] = []
for(let i=0; i<characterSpecificGamesystems.length; i++) {
const characterSpecificGamesystem = characterSpecificGamesystems[i];
result.push(this.parseSingleCharacterSpecificGamesystem(character, characterSpecificGamesystem)!)
}
return result;
}
private parseSingleCharacterSpecificGamesystem(character: Character, characterSpecificGamesystem: any): SimpleTemplateGamesystem | 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)! as SimpleTemplateState
const conditions = this.scriptAccountConditionParser.parseStoredConditions(stateReference.conditionMap);
state.conditionMap.set(character, conditions)
}
for(let i=0; i<characterSpecificGamesystem.transitions.length; i++) {
const transitionReference = characterSpecificGamesystem.transitions[i];
const transition = this.findReferencedTransition(referencedGamesystem, transitionReference.startingState, transitionReference.endingState) as SimpleTemplateTransition;
const condititions = this.scriptAccountConditionParser.parseStoredConditions(transitionReference.conditionMap);
const actions = this.scriptAccountActionParser.parseActions(transitionReference.actionMap);
transition!.actionMap.set(character, actions);
transition!.conditionMap.set(character, condititions);
}
} else {
console.log(this.characterSpecificGamesystems)
console.log("Cannot find system: ", characterSpecificGamesystem.componentName)
}
return referencedGamesystem;
}
private findCharacterSpecificGamesystem(componentName: string): SimpleTemplateGamesystem | undefined{
return this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === componentName)
}
private findReferencedState(gamesystem: SimpleTemplateGamesystem, stateLabel: string) {
return gamesystem.states.find(state => state.stateLabel === stateLabel);
}
private findReferencedTransition(gamesystem: SimpleTemplateGamesystem, startingLabel: string, endingLabel: string) {
return gamesystem.transitions.find(transition => transition.startingState.stateLabel === startingLabel && transition.endingState.stateLabel === endingLabel);
}
} }