ConceptCreator/src/app/game-model/gamesystems/SimpleGamesystem.ts
Sebastian Böckelmann e873688cb7
All checks were successful
E2E Testing / test (push) Successful in 1m28s
Save Gamesystems and Ignore save status and type of saved gamemodelcomponent
2024-02-17 10:13:32 +01:00

59 lines
1.9 KiB
TypeScript

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<SimpleState, SimpleTransition> {
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;
}
}