import {Gamesystem} from "./Gamesystem"; import {SimpleState} from "./SimpleState"; import {SimpleTransition} from "./SimpleTransition"; import {State} from "./State"; import {Transition} from "./Transition"; import {ProductState} from "./ProductState"; import {ProductTransition} from "./ProductTransition"; import {ProductGamesystem} from "./ProductGamesystem"; export class SimpleGamesystem extends Gamesystem { parentGamesystem: ProductGamesystem | undefined createState(label: string, description: string): SimpleState | undefined { if(label == null) { return undefined; } if(description == null) { description = ""; } const state = new SimpleState(label, description); if(this.states.find(s => s.stateLabel == label) == undefined) { this.states.push(state); return state; } else { return undefined } } createTransition(startingState: SimpleState, endingState: SimpleState): SimpleTransition | undefined{ if((startingState == null || endingState == null) || startingState === endingState) { return undefined; } const transition = new SimpleTransition(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: SimpleState): 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; } }