alt-templatesystem-impl #29

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

View File

@ -1,35 +1,24 @@
import {ModelComponent} from "../ModelComponent";
import {ModelComponentType} from "../ModelComponentType";
import { Gamesystem } from "../gamesystems/Gamesystem";
import { ProductGamesystem } from "../gamesystems/ProductGamesystem";
import { ProductTemplateGamesystem } from "../gamesystems/ProductTemplateGamesystem";
import { SimpleGamesystem } from "../gamesystems/SimpleGamesystem";
import { SimpleTemplateGamesystem } from "../gamesystems/SimpleTemplateGamesystem";
import {SimpleTemplateGamesystem} from "../gamesystems/SimpleTemplateGamesystem";
export class Character extends ModelComponent{
characterSpecificGamesystems: Gamesystem<any, any>[] = []
private characterSpecificGamesystems: SimpleTemplateGamesystem<Character>[] = []
constructor(componentName: string, componentDescription: string) {
super(componentName, componentDescription, ModelComponentType.CHARACTER);
}
addCharacterSpecificSimpleGamesystem(referenceSystem: SimpleGamesystem) {
if(!this.findCharacterSpecificGameystemByName(referenceSystem.componentName)) {
const templateGamesystem = new SimpleTemplateGamesystem(referenceSystem);
this.characterSpecificGamesystems.push(templateGamesystem)
addCharacterSpecificGamesystem(templateGamesystem: SimpleTemplateGamesystem<Character>) {
if(!this.isGamesystemCharacterSpecific(templateGamesystem.componentName)) {
this.characterSpecificGamesystems.push(templateGamesystem);
templateGamesystem.addReferenceKey(this);
}
}
addCharacterSpecificProductTemplateGamesystem(referenceSystem: ProductGamesystem) {
if(!this.findCharacterSpecificGameystemByName(referenceSystem.componentName)) {
const templateGamesystem = new ProductTemplateGamesystem(referenceSystem);
this.characterSpecificGamesystems.push(templateGamesystem)
}
}
findCharacterSpecificGameystemByName(referenceName: string) {
return this.characterSpecificGamesystems.find(gamesystem => gamesystem.componentName === referenceName) != undefined
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 {SimpleTemplateTransition} from "./transitions/SimpleTemplateTransition";
import {TemplateType} from "../TemplateType";
import {state} from "@angular/animations";
export class SimpleTemplateGamesystem<ReferenceType> extends Gamesystem<SimpleTemplateState<ReferenceType>, SimpleTemplateTransition<ReferenceType>> {
@ -52,4 +53,22 @@ export class SimpleTemplateGamesystem<ReferenceType> extends Gamesystem<SimpleTe
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 {
conditionMap: Map<ReferenceType, ScriptAccountCondition> = new Map<ReferenceType, ScriptAccountCondition>()
conditionMap: Map<ReferenceType, ScriptAccountCondition[]> = new Map<ReferenceType, ScriptAccountCondition[]>()
}