Alternative Implementation of Templatesystems
All checks were successful
E2E Testing / test (push) Successful in 1m54s

This commit is contained in:
Sebastian Böckelmann 2024-04-11 10:50:05 +02:00
parent e890d89cc8
commit 010adc9136
3 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,54 @@
import {SimpleGamesystem} from "./SimpleGamesystem";
import {SimpleTemplateState} from "./states/SimpleTemplateState";
import {Gamesystem} from "./Gamesystem";
import {SimpleTransition} from "./transitions/SimpleTransition";
import {SimpleState} from "./states/SimpleState";
import {SimpleTemplateTransition} from "./transitions/SimpleTemplateTransition";
export class SimpleTemplateGamesystem<ReferenceType> extends Gamesystem<SimpleTemplateState<ReferenceType>, SimpleTemplateTransition<ReferenceType>> {
createState(label: string, description: string): SimpleState | undefined {
if(label == null) {
return undefined;
}
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();
}