ConceptCreator/src/app/editor/editor.component.ts
Sebastian Böckelmann 9a51cb3a80
Some checks failed
E2E Testing / test (push) Failing after 2m3s
Beginning of Editor for Characterspecific Gamesystems
2024-04-11 13:45:29 +02:00

61 lines
2.3 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";
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<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;
convertModelComponentToCharacter(modelComponent: ModelComponent) {
if(modelComponent instanceof Character) {
return modelComponent as Character;
}
}
}