112 lines
3.5 KiB
TypeScript
112 lines
3.5 KiB
TypeScript
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
|
|
import {FlatTreeControl} from "@angular/cdk/tree";
|
|
import {MatTreeFlatDataSource, MatTreeFlattener} from "@angular/material/tree";
|
|
import {ElectronService} from "../../core/services";
|
|
import {GameModel} from "../../project/game-model/GameModel";
|
|
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 {ProductGamesystem} from "../../project/game-model/gamesystems/ProductGamesystem";
|
|
import {SimpleGamesystem} from "../../project/game-model/gamesystems/SimpleGamesystem";
|
|
|
|
|
|
interface FlatNode {
|
|
expandable: boolean,
|
|
name: string,
|
|
level: number
|
|
}
|
|
@Component({
|
|
selector: 'app-gamescript-overview',
|
|
templateUrl: './gamescript-overview.component.html',
|
|
styleUrl: './gamescript-overview.component.scss'
|
|
})
|
|
export class GamescriptOverviewComponent implements OnInit {
|
|
|
|
@Input('gameModel') gameModel: GameModel | undefined
|
|
@Output('openGamesystemEditor') openGamesystemEmitter : EventEmitter<Gamesystem<State<any>, Transition<any>>> = new EventEmitter<Gamesystem<State<any>, Transition<any>>>();
|
|
|
|
|
|
ngOnInit() {
|
|
this.dataSource.data = this.gameModel!.gamesystems;
|
|
}
|
|
|
|
private _transformer = (node: Gamesystem<State<any>, Transition<any>>, level: number) => {
|
|
return {
|
|
expandable: this.isProductGamesystem(node) && !!(node as ProductGamesystem).innerGamesystems && (node as ProductGamesystem).innerGamesystems.length > 0,
|
|
name: node.componentName,
|
|
level: level
|
|
}
|
|
}
|
|
|
|
treeControl = new FlatTreeControl<FlatNode>(
|
|
node => node.level,
|
|
node => node.expandable
|
|
)
|
|
|
|
treeFlattener = new MatTreeFlattener(
|
|
this._transformer,
|
|
node => node.level,
|
|
node => node.expandable,
|
|
node => this.isSimpleGamesystem(node)? []: (node as ProductGamesystem).innerGamesystems
|
|
);
|
|
|
|
dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
|
|
selectedGamesystem: FlatNode | undefined;
|
|
|
|
constructor(private electronService: ElectronService) {
|
|
|
|
}
|
|
|
|
hasChild = (_: number, node: FlatNode) => node.expandable;
|
|
|
|
|
|
isSimpleGamesystem(gamesystem: Gamesystem<State<any>, Transition<any>>) {
|
|
return gamesystem instanceof SimpleGamesystem;
|
|
}
|
|
|
|
isProductGamesystem(gamesystem: Gamesystem<State<any>, Transition<any>>) {
|
|
return gamesystem instanceof ProductGamesystem;
|
|
}
|
|
|
|
onSelectGamesystem(node: FlatNode) {
|
|
this.selectedGamesystem = node;
|
|
}
|
|
|
|
onContextMenu(event: MouseEvent) {
|
|
this.electronService.ipcRenderer.send('context-menu', {x: event.x, y: event.y});
|
|
}
|
|
|
|
openGamesystemEditor(node: FlatNode) {
|
|
const gamesystem: Gamesystem<State<any>, Transition<any>>| undefined= this.gameModel!.findGamesystem(node.name);
|
|
if(gamesystem != undefined) {
|
|
gamesystem.unsaved = false;
|
|
this.openGamesystemEmitter.emit(gamesystem);
|
|
}
|
|
}
|
|
|
|
get selectedGamesystemName() {
|
|
if(this.selectedGamesystem == undefined) {
|
|
return undefined
|
|
} else {
|
|
return this.selectedGamesystem!.name
|
|
}
|
|
}
|
|
|
|
getSelectedGamesystem() {
|
|
if(this.selectedGamesystem != undefined) {
|
|
return this.gameModel!.findGamesystem(this.selectedGamesystem!.name);
|
|
} else {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
refresh() {
|
|
this.dataSource.data = this.gameModel!.gamesystems;
|
|
this.resetSelectedGamesystem()
|
|
}
|
|
|
|
resetSelectedGamesystem() {
|
|
this.selectedGamesystem = undefined
|
|
}
|
|
}
|