Persist ScriptAccountConditions to TemplateTransition
All checks were successful
E2E Testing / test (push) Successful in 1m55s

This commit is contained in:
Sebastian Böckelmann 2024-04-11 18:05:54 +02:00
parent f11e290a6b
commit 803d0d4443
4 changed files with 56 additions and 5 deletions

View File

@ -45,7 +45,7 @@
<app-scriptaccount-action-editor [transition]="element" [scriptAccounts]="scriptAccounts" [enableEditing]="true" [templateReference]="templateReference"></app-scriptaccount-action-editor>
</div>
<div class="condition-container">
<app-scriptaccount-condition-editor [conditions]="element.scriptAccountConditions" [scriptAccounts]="scriptAccounts" [enableEditiong]="true"
<app-scriptaccount-condition-editor [conditions]="fetchConditions(element)" [scriptAccounts]="scriptAccounts" [enableEditiong]="true"
(onCreateCondition)="onCreateCondition(element, $event)" (onDeleteCondition)="deleteCondition(element, $event)"></app-scriptaccount-condition-editor>
</div>
</div>

View File

@ -13,6 +13,7 @@ import {
SimpleTemplateTransition
} from "../../../../project/game-model/gamesystems/transitions/SimpleTemplateTransition";
import {Character} from "../../../../project/game-model/characters/Character";
import {SimpleTemplateState} from "../../../../project/game-model/gamesystems/states/SimpleTemplateState";
@Component({
selector: 'app-simple-transition-editor',
templateUrl: './simple-transition-editor.component.html',
@ -109,7 +110,16 @@ export class SimpleTransitionEditorComponent implements OnInit {
protected readonly transition = transition;
onCreateCondition(transition: SimpleTransition, condition: ScriptAccountCondition) {
transition.addScriptAccountCondition(condition);
if(transition instanceof SimpleTemplateTransition && this.templateReference instanceof Character) {
const templateTransition = transition as SimpleTemplateTransition<Character>
if(templateTransition.conditionMap.has(this.templateReference)) {
templateTransition.conditionMap.get(this.templateReference)!.push(condition)
} else {
templateTransition.conditionMap.set(this.templateReference, [condition])
}
} else {
transition.addScriptAccountCondition(condition);
}
}
deleteCondition(trasition: SimpleTransition, condition: ScriptAccountCondition) {
@ -119,4 +129,16 @@ export class SimpleTransitionEditorComponent implements OnInit {
editTransition(transition: SimpleTransition) {
this.referenceTransitionEmitter.emit(transition)
}
fetchConditions(transition: SimpleTransition): ScriptAccountCondition[] {
if(transition instanceof SimpleTemplateTransition && this.templateReference instanceof Character) {
if(transition.conditionMap.get(this.templateReference) == undefined) {
return transition.scriptAccountConditions
} else {
return transition.conditionMap.get(this.templateReference!)!
}
} else {
return transition.scriptAccountConditions;
}
}
}

View File

@ -4,15 +4,19 @@ import {SimpleTemplateGamesystem} from "../../game-model/gamesystems/SimpleTempl
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {ScriptAccountParser} from "../ScriptAccountParser";
import {ScriptAccountConditionParser} from "../gamesystemParser/ScriptAccountConditionParser";
import {transition} from "@angular/animations";
import {ScriptAccountActionParser} from "../gamesystemParser/ScriptAccountActionParser";
export class CharacterParser {
characterSpecificGamesystems: SimpleTemplateGamesystem<Character>[]
scriptAccountConditionParser: ScriptAccountConditionParser
scriptAccountActionParser: ScriptAccountActionParser
constructor(characterSpecificGamesystems: SimpleTemplateGamesystem<Character>[], scriptAccounts: ScriptAccount[]) {
this.characterSpecificGamesystems = characterSpecificGamesystems;
this.scriptAccountActionParser = new ScriptAccountActionParser(scriptAccounts);
this.scriptAccountConditionParser = new ScriptAccountConditionParser(scriptAccounts)
}
@ -44,11 +48,21 @@ export class CharacterParser {
for(let i=0; i<characterSpecificGamesystem.states.length; i++) {
const stateReference = characterSpecificGamesystem.states[i];
const state = this.findReferencedState(referencedGamesystem, stateReference.stateLabel)!
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);
const condititions = this.scriptAccountConditionParser.parseStoredConditions(transitionReference.conditionMap);
const actions = this.scriptAccountActionParser.parseActions(transitionReference.actionMap);
transition!.actionMap.set(character, actions);
transition!.conditionMap.set(character, condititions);
}
}
return referencedGamesystem;
@ -60,4 +74,8 @@ export class CharacterParser {
private findReferencedState(gamesystem: SimpleTemplateGamesystem<Character>, stateLabel: string) {
return gamesystem.states.find(state => state.stateLabel === stateLabel);
}
private findReferencedTransition(gamesystem: SimpleTemplateGamesystem<Character>, startingLabel: string, endingLabel: string) {
return gamesystem.transitions.find(transition => transition.startingState.stateLabel === startingLabel && transition.endingState.stateLabel === endingLabel);
}
}

View File

@ -26,8 +26,19 @@
"scriptAccountConditions": [],
"startingState": "Fröhlich",
"endingState": "Wütend",
"conditionMap": [],
"actionMap": []
"conditionMap": [
{
"scriptAccount": "Luftfeuchtigkeit",
"minValue": 0,
"maxValue": "10"
}
],
"actionMap": [
{
"changingValue": 0,
"scriptAccount": "New ScriptAccount"
}
]
}
]
}