ConceptCreator/src/app/editor/editor.component.ts
Sebastian Böckelmann 8016f55e85
Some checks failed
E2E Testing / test (push) Failing after 1m34s
Refactor Loading of ScriptAccounts
2024-03-20 09:26:14 +01:00

54 lines
2.0 KiB
TypeScript

import {Component, EventEmitter, Input, Output} from '@angular/core';
import {ModelComponent} from "../project/game-model/ModelComponent";
import {GameModel} from "../project/game-model/GameModel";
import {ScriptAccount} from "../project/game-model/scriptAccounts/ScriptAccount";
import {Gamesystem} from "../project/game-model/gamesystems/Gamesystem";
import {State} from "../project/game-model/gamesystems/states/State";
import {Transition} from "../project/game-model/gamesystems/transitions/Transition";
import {ModelComponentType} from "../project/game-model/ModelComponentType";
@Component({
selector: 'app-editor',
templateUrl: './editor.component.html',
styleUrl: './editor.component.scss'
})
export class EditorComponent {
gameModelComponents: ModelComponent[] = [];
@Output("onModelNameUpdate") onModelNameUpdateEmitter = new EventEmitter<boolean>();
activeTab: number = this.gameModelComponents.length;
@Input() gameModel: GameModel | undefined
openGameModelComponent(gameModelComponent: ModelComponent) {
if(!this.gameModelComponents.includes(gameModelComponent)) {
this.gameModelComponents.push(gameModelComponent);
this.activeTab = this.gameModelComponents.length;
} else {
this.activeTab = this.gameModelComponents.findIndex(component => component.componentName === gameModelComponent.componentName);
}
}
closeGameModelComponent(gameModelComponent: ModelComponent) {
this.gameModelComponents = this.gameModelComponents.filter(modelComponent => modelComponent !== gameModelComponent);
}
convertModelComponentToScriptAccount(modelComponent: ModelComponent) {
if(modelComponent instanceof ScriptAccount) {
return modelComponent as ScriptAccount;
}
}
convertModelComponentToGamesystem(modelComponent: ModelComponent) {
if(modelComponent instanceof Gamesystem) {
return modelComponent as Gamesystem<State<any>, Transition<any>>;
}
}
onModelNameUpdate() {
this.onModelNameUpdateEmitter.emit(true);
}
protected readonly ModelComponentType = ModelComponentType;
}