alt-templatesystem-impl #29

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

View File

@ -1,42 +1,54 @@
import {SimpleGamesystem} from "./SimpleGamesystem"; import {SimpleGamesystem} from "./SimpleGamesystem";
import { ScriptAccountAction } from "./actions/ScriptAccountAction"; import {SimpleTemplateState} from "./states/SimpleTemplateState";
import { ScriptAccountCondition } from "./conditions/ScriptAccountCondition"; import {Gamesystem} from "./Gamesystem";
import { SimpleState } from "./states/SimpleState";
import {SimpleTransition} from "./transitions/SimpleTransition"; import {SimpleTransition} from "./transitions/SimpleTransition";
import {SimpleState} from "./states/SimpleState";
import {SimpleTemplateTransition} from "./transitions/SimpleTemplateTransition";
export class SimpleTemplateGamesystem extends SimpleGamesystem { export class SimpleTemplateGamesystem<ReferenceType> extends Gamesystem<SimpleTemplateState<ReferenceType>, SimpleTemplateTransition<ReferenceType>> {
referenceSystem: SimpleGamesystem
constructor(referenceSystem: SimpleGamesystem) { createState(label: string, description: string): SimpleState | undefined {
super(referenceSystem.componentName, referenceSystem.componentDescription) if(label == null) {
this.referenceSystem = referenceSystem; return undefined;
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);
})
this.referenceSystem.addTemplateSystem(this)
} }
if(description == null) {
description = "";
}
const state = new SimpleTemplateState<ReferenceType>(label, description);
if(this.states.find(s => s.stateLabel == label) == undefined) {
this.states.push(state);
return state;
} else {
return undefined
}
}
createTransition(startingState: SimpleTemplateState<ReferenceType>, endingState: SimpleTemplateState<ReferenceType>): SimpleTemplateTransition<ReferenceType> | undefined {
if((startingState == null || endingState == null) || startingState === endingState) {
return undefined;
}
const transition = new SimpleTemplateTransition<ReferenceType>(startingState, endingState);
if(this.transitions.find(t => t.startingState === startingState && t.endingState === endingState) == undefined) {
this.transitions.push(transition)
return transition;
} else {
startingState.removeOutgoingTransition(transition);
endingState.removeIncomingTransition(transition);
return undefined
}
}
removeState(state: SimpleTemplateState<ReferenceType>): boolean {
const updatedStates = this.states.filter(s => s !== state);
const updated = updatedStates.length != this.states.length;
this.states = updatedStates;
this.transitions = this.transitions.filter(t => t.startingState !== state && t.endingState !== state);
return updated;
}
} }

View File

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

View File

@ -0,0 +1,9 @@
import {SimpleTransition} from "./SimpleTransition";
import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
import {ScriptAccountAction} from "../actions/ScriptAccountAction";
export class SimpleTemplateTransition<ReferenceType> extends SimpleTransition {
conditions: Map<ReferenceType, ScriptAccountCondition[]> = new Map();
actions: Map<ReferenceType, ScriptAccountAction[]> = new Map();
}