diff --git a/src/app/project/game-model/characters/Character.ts b/src/app/project/game-model/characters/Character.ts index 07acf19..7b87f7b 100644 --- a/src/app/project/game-model/characters/Character.ts +++ b/src/app/project/game-model/characters/Character.ts @@ -1,9 +1,35 @@ 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"; export class Character extends ModelComponent{ + characterSpecificGamesystems: Gamesystem[] = [] + 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) + } + } + + 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 + } } diff --git a/src/app/project/game-model/gamesystems/ProductTemplateGamesystem.ts b/src/app/project/game-model/gamesystems/ProductTemplateGamesystem.ts new file mode 100644 index 0000000..9313e94 --- /dev/null +++ b/src/app/project/game-model/gamesystems/ProductTemplateGamesystem.ts @@ -0,0 +1,25 @@ +import { ProductGamesystem } from "./ProductGamesystem"; +import { SimpleGamesystem } from "./SimpleGamesystem"; +import { SimpleTemplateGamesystem } from "./SimpleTemplateGamesystem"; + +export class ProductTemplateGamesystem extends ProductGamesystem { + + referenceSystem: ProductGamesystem + + constructor(referenceSystem: ProductGamesystem) { + super(referenceSystem.componentName, referenceSystem.componentDescription) + this.referenceSystem = referenceSystem; + + this.innerGamesystems = referenceSystem.innerGamesystems.map(innerGamesystem => { + if(innerGamesystem instanceof SimpleGamesystem) { + return new SimpleTemplateGamesystem(innerGamesystem) + } else { + return new ProductTemplateGamesystem(innerGamesystem as ProductTemplateGamesystem) + } + }) + + this.generateFromChildsystems(); + } + + +} diff --git a/src/app/project/game-model/gamesystems/SimpleGamesystem.ts b/src/app/project/game-model/gamesystems/SimpleGamesystem.ts index 9b04b03..c602bfc 100644 --- a/src/app/project/game-model/gamesystems/SimpleGamesystem.ts +++ b/src/app/project/game-model/gamesystems/SimpleGamesystem.ts @@ -1,11 +1,7 @@ import {Gamesystem} from "./Gamesystem"; +import { SimpleTemplateGamesystem } from "./SimpleTemplateGamesystem"; import {SimpleState} from "./states/SimpleState"; import {SimpleTransition} from "./transitions/SimpleTransition"; -import {State} from "./states/State"; -import {Transition} from "./transitions/Transition"; -import {ProductState} from "./states/ProductState"; -import {ProductTransition} from "./transitions/ProductTransition"; -import {ProductGamesystem} from "./ProductGamesystem"; export class SimpleGamesystem extends Gamesystem { @@ -55,4 +51,8 @@ export class SimpleGamesystem extends Gamesystem return updated; } + + protected findStateByStateLabel(stateLabel: string) { + return this.states.find(state => stateLabel === stateLabel); + } } diff --git a/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts new file mode 100644 index 0000000..4e08528 --- /dev/null +++ b/src/app/project/game-model/gamesystems/SimpleTemplateGamesystem.ts @@ -0,0 +1,42 @@ +import { SimpleGamesystem } from "./SimpleGamesystem"; +import { ScriptAccountAction } from "./actions/ScriptAccountAction"; +import { ScriptAccountCondition } from "./conditions/ScriptAccountCondition"; +import { SimpleState } from "./states/SimpleState"; +import { SimpleTransition } from "./transitions/SimpleTransition"; + +export class SimpleTemplateGamesystem extends SimpleGamesystem { + referenceSystem: SimpleGamesystem + + constructor(referenceSystem: SimpleGamesystem) { + super(referenceSystem.componentName, referenceSystem.componentDescription) + this.referenceSystem = referenceSystem; + + this.referenceSystem.states.forEach(state => { + const templateState = new SimpleState(state.stateLabel, state.stateDescription) + templateState.initial = state.initial; + templateState.conditions = state.conditions.map(condition => ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue, condition.maxValue)!) + + this.states.push(templateState); + }); + + this.referenceSystem.transitions.forEach(transition => { + const startingState = this.findStateByStateLabel(transition.startingState.stateLabel); + const endingState = this.findStateByStateLabel(transition.endingState.stateLabel); + + const templateTransition = new SimpleTransition(startingState!, endingState!) + + templateTransition.scriptAccountConditions = transition.scriptAccountConditions.map(condition => + ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue, condition.maxValue)!) + + templateTransition.scriptAccountActions = transition.scriptAccountActions.map(action => { + return new ScriptAccountAction(action.scriptAccount, action.changingValue); + }); + + this.transitions.push(templateTransition); + }) + + + } + + +}