alt-templatesystem-impl #29

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

View File

@ -1,9 +1,24 @@
import {ModelComponent} from "../ModelComponent"; import {ModelComponent} from "../ModelComponent";
import {ModelComponentType} from "../ModelComponentType"; import {ModelComponentType} from "../ModelComponentType";
import {SimpleTemplateGamesystem} from "../gamesystems/SimpleTemplateGamesystem";
export class Character extends ModelComponent{ export class Character extends ModelComponent{
private characterSpecificGamesystems: SimpleTemplateGamesystem<Character>[] = []
constructor(componentName: string, componentDescription: string) { constructor(componentName: string, componentDescription: string) {
super(componentName, componentDescription, ModelComponentType.CHARACTER); super(componentName, componentDescription, ModelComponentType.CHARACTER);
} }
addCharacterSpecificGamesystem(templateGamesystem: SimpleTemplateGamesystem<Character>) {
if(!this.isGamesystemCharacterSpecific(templateGamesystem.componentName)) {
this.characterSpecificGamesystems.push(templateGamesystem);
templateGamesystem.addReferenceKey(this);
}
}
private isGamesystemCharacterSpecific(gamesystemName: string) {
const characterSpecificGamesystem = this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === gamesystemName);
return characterSpecificGamesystem != 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[]>()
} }