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"; import {Character} from "../project/game-model/characters/Character"; @Component({ selector: 'app-editor', templateUrl: './editor.component.html', styleUrl: './editor.component.scss' }) export class EditorComponent { gameModelComponents: ModelComponent[] = []; @Output("onModelNameUpdate") onModelNameUpdateEmitter = new EventEmitter(); 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, Transition>; } } onModelNameUpdate() { this.onModelNameUpdateEmitter.emit(true); } protected readonly ModelComponentType = ModelComponentType; convertModelComponentToCharacter(modelComponent: ModelComponent) { if(modelComponent instanceof Character) { return modelComponent as Character; } } }