Add Reference to CharacterSpecific Gamesystems in relevant characters

This commit is contained in:
Sebastian Böckelmann 2024-04-11 13:40:40 +02:00
parent 21dc74376b
commit 244222bc5b
3 changed files with 29 additions and 21 deletions

View File

@ -1,35 +1,24 @@
import {ModelComponent} from "../ModelComponent"; import {ModelComponent} from "../ModelComponent";
import {ModelComponentType} from "../ModelComponentType"; import {ModelComponentType} from "../ModelComponentType";
import { Gamesystem } from "../gamesystems/Gamesystem"; import {SimpleTemplateGamesystem} from "../gamesystems/SimpleTemplateGamesystem";
import { ProductGamesystem } from "../gamesystems/ProductGamesystem";
import { ProductTemplateGamesystem } from "../gamesystems/ProductTemplateGamesystem";
import { SimpleGamesystem } from "../gamesystems/SimpleGamesystem";
import { SimpleTemplateGamesystem } from "../gamesystems/SimpleTemplateGamesystem";
export class Character extends ModelComponent{ export class Character extends ModelComponent{
characterSpecificGamesystems: Gamesystem<any, any>[] = [] private characterSpecificGamesystems: SimpleTemplateGamesystem<Character>[] = []
constructor(componentName: string, componentDescription: string) { constructor(componentName: string, componentDescription: string) {
super(componentName, componentDescription, ModelComponentType.CHARACTER); super(componentName, componentDescription, ModelComponentType.CHARACTER);
} }
addCharacterSpecificSimpleGamesystem(referenceSystem: SimpleGamesystem) { addCharacterSpecificGamesystem(templateGamesystem: SimpleTemplateGamesystem<Character>) {
if(!this.findCharacterSpecificGameystemByName(referenceSystem.componentName)) { if(!this.isGamesystemCharacterSpecific(templateGamesystem.componentName)) {
const templateGamesystem = new SimpleTemplateGamesystem(referenceSystem); this.characterSpecificGamesystems.push(templateGamesystem);
this.characterSpecificGamesystems.push(templateGamesystem) templateGamesystem.addReferenceKey(this);
} }
} }
addCharacterSpecificProductTemplateGamesystem(referenceSystem: ProductGamesystem) { private isGamesystemCharacterSpecific(gamesystemName: string) {
if(!this.findCharacterSpecificGameystemByName(referenceSystem.componentName)) { const characterSpecificGamesystem = this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === gamesystemName);
const templateGamesystem = new ProductTemplateGamesystem(referenceSystem); return characterSpecificGamesystem != undefined
this.characterSpecificGamesystems.push(templateGamesystem)
}
}
findCharacterSpecificGameystemByName(referenceName: string) {
return this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === referenceName) != undefined
} }
} }

View File

@ -5,6 +5,7 @@ import {SimpleTransition} from "./transitions/SimpleTransition";
import {SimpleState} from "./states/SimpleState"; import {SimpleState} from "./states/SimpleState";
import {SimpleTemplateTransition} from "./transitions/SimpleTemplateTransition"; import {SimpleTemplateTransition} from "./transitions/SimpleTemplateTransition";
import {TemplateType} from "../TemplateType"; import {TemplateType} from "../TemplateType";
import {state} from "@angular/animations";
export class SimpleTemplateGamesystem<ReferenceType> extends Gamesystem<SimpleTemplateState<ReferenceType>, SimpleTemplateTransition<ReferenceType>> { export class SimpleTemplateGamesystem<ReferenceType> extends Gamesystem<SimpleTemplateState<ReferenceType>, SimpleTemplateTransition<ReferenceType>> {
@ -52,4 +53,22 @@ export class SimpleTemplateGamesystem<ReferenceType> extends Gamesystem<SimpleTe
return updated; return updated;
} }
addReferenceKey(reference: ReferenceType) {
this.states.forEach(state => {
if(!state.conditionMap.has(reference)) {
state.conditionMap.set(reference, state.conditions.concat())
}
})
this.transitions.forEach(transition => {
if(!transition.conditions.has(reference)) {
transition.conditions.set(reference, transition.scriptAccountConditions.concat())
}
if(!transition.actions.has(reference)) {
transition.actions.set(reference, transition.scriptAccountActions.concat())
}
})
}
} }

View File

@ -3,6 +3,6 @@ import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
export class SimpleTemplateState<ReferenceType> extends SimpleState { export class SimpleTemplateState<ReferenceType> extends SimpleState {
conditionMap: Map<ReferenceType, ScriptAccountCondition> = new Map<ReferenceType, ScriptAccountCondition>() conditionMap: Map<ReferenceType, ScriptAccountCondition[]> = new Map<ReferenceType, ScriptAccountCondition[]>()
} }