Implement GameModel Support for Character Specific Gamesystems
All checks were successful
E2E Testing / test (push) Successful in 1m42s

This commit is contained in:
Sebastian Böckelmann 2024-04-10 20:02:56 +02:00
parent e890d89cc8
commit 28a520a995
4 changed files with 98 additions and 5 deletions

View File

@ -1,9 +1,35 @@
import {ModelComponent} from "../ModelComponent"; import {ModelComponent} from "../ModelComponent";
import {ModelComponentType} from "../ModelComponentType"; 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{ export class Character extends ModelComponent{
characterSpecificGamesystems: Gamesystem<any, any>[] = []
constructor(componentName: string, componentDescription: string) { constructor(componentName: string, componentDescription: string) {
super(componentName, componentDescription, ModelComponentType.CHARACTER); 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
}
} }

View File

@ -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();
}
}

View File

@ -1,11 +1,7 @@
import {Gamesystem} from "./Gamesystem"; import {Gamesystem} from "./Gamesystem";
import { SimpleTemplateGamesystem } from "./SimpleTemplateGamesystem";
import {SimpleState} from "./states/SimpleState"; import {SimpleState} from "./states/SimpleState";
import {SimpleTransition} from "./transitions/SimpleTransition"; 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<SimpleState, SimpleTransition> { export class SimpleGamesystem extends Gamesystem<SimpleState, SimpleTransition> {
@ -55,4 +51,8 @@ export class SimpleGamesystem extends Gamesystem<SimpleState, SimpleTransition>
return updated; return updated;
} }
protected findStateByStateLabel(stateLabel: string) {
return this.states.find(state => stateLabel === stateLabel);
}
} }

View File

@ -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);
})
}
}