ConceptCreator/src/app/app.component.ts

274 lines
10 KiB
TypeScript
Raw Normal View History

import {Component, NgZone, OnInit, ViewChild} from '@angular/core';
import {MatDrawerContainer} from "@angular/material/sidenav";
import {EditorComponent} from "./editor/editor.component";
import {
ScriptAccountOverviewComponent
} from "./side-overviews/script-account-overview/script-account-overview.component";
2024-01-27 15:25:32 +01:00
import {MatDialog} from "@angular/material/dialog";
import {DeleteConfirmationDialogComponent} from "./delete-confirmation-dialog/delete-confirmation-dialog.component";
2024-02-06 20:21:52 +01:00
import {GamescriptOverviewComponent} from "./side-overviews/gamescript-overview/gamescript-overview.component";
2024-03-20 09:26:14 +01:00
import {ModelComponentType} from "./project/game-model/ModelComponentType";
import {ModelComponentTypeUtillities} from "./project/game-model/ModelComponentTypeUtillities";
import {ScriptAccount} from "./project/game-model/scriptAccounts/ScriptAccount";
import {Gamesystem} from "./project/game-model/gamesystems/Gamesystem";
import {ModelComponent} from "./project/game-model/ModelComponent";
import {GameModel} from "./project/game-model/GameModel";
import {StoredGameModel} from "../../app/storage/StoredGameModel";
import {GamesystemParser} from "./project/parser/gamesystemParser/GamesystemParser";
import {ScriptAccountParser} from "./project/parser/ScriptAccountParser";
import {ElectronService} from "./core/services";
2024-03-20 16:23:37 +01:00
import {ScriptAccountSerializer} from "./project/serializer/ScriptAccountSerializer";
import {StoreComponent} from "../../app/storage/StoreComponent";
2024-03-20 19:35:24 +01:00
import {GamesystemSerializer} from "./project/serializer/GamesystemSerializer";
2024-03-22 09:46:03 +01:00
import {Character} from "./project/game-model/characters/Character";
import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component";
2024-03-22 10:01:47 +01:00
import {CharacterSerializer} from "./project/serializer/CharacterSerializer";
2024-01-26 23:07:40 +01:00
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
openContent : ModelComponentType | undefined = undefined;
@ViewChild('drawer') drawer: MatDrawerContainer|undefined
@ViewChild('editor') editor: EditorComponent|undefined
@ViewChild('scriptAccountOverview') scriptAccountOverview: ScriptAccountOverviewComponent | undefined
2024-02-06 20:21:52 +01:00
@ViewChild('gamesystemOverview') gamesystemOverview: GamescriptOverviewComponent | undefined
2024-03-22 09:46:03 +01:00
@ViewChild('characterOverview') characterOverview: CharacterOverviewComponent | undefined
gameModel: GameModel | undefined
constructor(private electronService: ElectronService,
private dialog: MatDialog,
private zone: NgZone
2024-01-26 23:07:40 +01:00
) {
if(electronService.isElectron) {
electronService.ipcRenderer.on('context-menu', (event: any, message: string) => {
this.zone.run(() => {
this.onContextMenuMessageRecieved(message);
});
})
electronService.ipcRenderer.on('get-project-data', (event: any, message: string) => {
this.zone.run(() => {
this.onSaveProject();
})
})
electronService.ipcRenderer.on('open-project', (event: any, loadedProject: StoredGameModel) => {
this.zone.run(() => {
this.onLoadProject(loadedProject)
})
})
}
}
2024-02-10 10:11:07 +01:00
onContextMenuMessageRecieved(message: string) {
if(message == "edit") {
this.onEditModelComponent();
} else if(message == "delete") {
this.onDeleteModelComponent();
} else if(message.startsWith("new")) {
const splittedMessage = message.split("-");
const modelComponentType = ModelComponentTypeUtillities.fromString(splittedMessage[1]);
if(modelComponentType != undefined) {
this.onCreateModelComponent(modelComponentType);
} else {
console.log("[ERROR] [App-Component] Unknown Context-Menu Command!")
}
}
}
private onEditModelComponent() {
2024-02-10 10:17:21 +01:00
switch (this.openContent!) {
case ModelComponentType.SCRIPTACCOUNT: {
if(this.scriptAccountOverview!.selectedScriptAccount != undefined) {
this.editor!.openGameModelComponent(this.scriptAccountOverview!.selectedScriptAccount);
}
} break;
case ModelComponentType.GAMESYTEM: {
if(this.gamesystemOverview!.selectedGamesystem != undefined) {
const gamesystem = this.gameModel!.findGamesystem(this.gamesystemOverview!.selectedGamesystemName!);
2024-02-10 10:17:21 +01:00
this.editor!.openGameModelComponent(gamesystem!);
}
} break
2024-03-22 09:47:39 +01:00
case ModelComponentType.CHARACTER: {
if(this.characterOverview!.selectedCharacter != undefined) {
this.editor!.openGameModelComponent(this.characterOverview!.selectedCharacter);
}
}break
2024-02-10 10:11:07 +01:00
}
}
private onDeleteModelComponent() {
const affectedModelComponent = this.getSelectedModelComponent();
console.log("Affected ModelComponent: ", affectedModelComponent)
2024-02-10 10:11:07 +01:00
const dialogRef = this.dialog.open(DeleteConfirmationDialogComponent, {data: affectedModelComponent, minWidth: "400px"});
dialogRef.afterClosed().subscribe(res => {
if(res != undefined && res) {
if(affectedModelComponent instanceof ScriptAccount) {
this.gameModel!.removeScriptAccount(affectedModelComponent);
2024-03-20 09:26:14 +01:00
//this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.SCRIPTACCOUNT))
} else if(affectedModelComponent instanceof Gamesystem) {
2024-03-21 08:43:28 +01:00
this.gameModel!.removeGamesystem(affectedModelComponent);
2024-03-20 09:26:14 +01:00
//this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.GAMESYTEM))
this.gamesystemOverview!.refresh()
2024-03-22 09:46:03 +01:00
} else if(affectedModelComponent instanceof Character) {
this.gameModel!.removeCharacter(affectedModelComponent)
2024-02-10 10:11:07 +01:00
}
}
})
}
private onCreateModelComponent(modelComponentType: ModelComponentType) {
switch (modelComponentType) {
case ModelComponentType.SCRIPTACCOUNT: this.onCreateNewScriptAccount(); break
case ModelComponentType.GAMESYTEM: this.onCreateNewGamesystem(); break
2024-03-22 09:42:05 +01:00
case ModelComponentType.CHARACTER: this.onCreateNewCharacter(); break
2024-02-10 10:11:07 +01:00
}
}
private onCreateNewScriptAccount() {
const createdScriptAccount = this.gameModel!.createScriptAccount("New ScriptAccount");
2024-02-10 10:11:07 +01:00
if(createdScriptAccount != undefined) {
this.editor?.openGameModelComponent(createdScriptAccount);
} else {
console.log("[DEBUG] [App-Component] ScriptAccount could not be created (Name not unique)");
}
}
private onCreateNewGamesystem() {
let parentGamesystemName = undefined
if(this.openContent != ModelComponentType.GAMESYTEM) {
this.openGamesystemsOverview();
} else {
parentGamesystemName = this.gamesystemOverview!.selectedGamesystemName;
}
const createdGamesystem = this.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName);
if(createdGamesystem != undefined) {
this.gamesystemOverview!.refresh();
this.editor?.openGameModelComponent(createdGamesystem);
}
2024-02-10 10:11:07 +01:00
}
2024-03-22 09:42:05 +01:00
private onCreateNewCharacter() {
const createdCharacter = this.gameModel!.createCharacter("New Character")
if(createdCharacter != undefined) {
this.editor?.openGameModelComponent(createdCharacter);
} else {
console.log("[DEBUG] [App-Component] ScriptAccount could not be created (Name not unique)");
}
}
2024-01-27 15:25:32 +01:00
private getSelectedModelComponent(): ModelComponent | undefined {
if(this.openContent == ModelComponentType.SCRIPTACCOUNT) {
if(this.scriptAccountOverview != undefined) {
return this.scriptAccountOverview.selectedScriptAccount;
2024-01-27 15:25:32 +01:00
} else {
console.log("[WARN] [App.component] ScriptAccountOverview is undefined")
}
} else if(this.openContent == ModelComponentType.GAMESYTEM){
if(this.gamesystemOverview != undefined) {
return this.gamesystemOverview.getSelectedGamesystem()
} else {
console.log("[WARN] [App.component] GamesystemOverview is undefined")
}
2024-03-22 09:46:03 +01:00
} else if(this.openContent == ModelComponentType.CHARACTER) {
if(this.characterOverview != undefined) {
return this.characterOverview.selectedCharacter;
} else {
console.log("[WARN] [App.component] ScriptAccountOverview is undefined")
}
2024-01-27 15:25:32 +01:00
}
return undefined;
}
ngOnInit() {
2024-03-20 16:31:17 +01:00
}
2024-02-10 12:21:31 +01:00
onLoadProject(storedGameModel: StoredGameModel) {
const gameModel = new GameModel(storedGameModel.gameModelName)
2024-03-20 15:15:08 +01:00
const scriptAccounts = ScriptAccountParser.parseScriptAccounts(storedGameModel.storedScriptAccounts);
2024-03-20 15:15:08 +01:00
const gamesystemParser = new GamesystemParser(scriptAccounts);
const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems);
2024-02-10 17:07:24 +01:00
2024-03-20 15:15:08 +01:00
gameModel.scriptAccounts = scriptAccounts
gameModel.gamesystems = gamesystems
2024-03-22 07:45:59 +01:00
gameModel.generateProductSystemContents()
2024-02-10 17:07:24 +01:00
2024-03-20 16:23:37 +01:00
console.log(gameModel.scriptAccounts)
this.gameModel = gameModel;
}
2024-02-10 17:07:24 +01:00
onSaveProject() {
2024-03-20 19:35:24 +01:00
if(this.gameModel != undefined) {
const storedScriptAccounts = ScriptAccountSerializer.serializeScriptAccounts(this.gameModel.scriptAccounts)
const storedGamesystems: StoreComponent[] = GamesystemSerializer.serializeGamesystems(this.gameModel.gamesystems)
2024-03-22 10:01:47 +01:00
const storedCharacters: StoreComponent[] = CharacterSerializer.serializeCharacters(this.gameModel.characters)
const storeModel = new StoredGameModel(this.gameModel.gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters)
2024-03-20 19:35:24 +01:00
if(this.electronService.isElectron) {
this.electronService.ipcRenderer.send('save-model', storeModel)
}
}
}
openScriptAccountsOverview() {
this.openContent = ModelComponentType.SCRIPTACCOUNT
this.drawer!.open();
}
2024-02-06 20:21:52 +01:00
openGamesystemsOverview() {
this.openContent = ModelComponentType.GAMESYTEM;
this.drawer!.open();
}
openCharactersOverview() {
this.openContent = ModelComponentType.CHARACTER
this.drawer!.open()
}
protected readonly ModelComponentType = ModelComponentType;
closeContentOverview() {
this.drawer!.close();
this.openContent = undefined;
}
protected readonly ModelComponentTypeUtillities = ModelComponentTypeUtillities;
openModelComponent(modelComponent: ModelComponent) {
if(this.editor != undefined) {
this.editor.openGameModelComponent(modelComponent);
} else {
console.log("[WARN] [App.Component] Editor is undefined")
}
}
onModelNameUpdate() {
if(this.openContent == ModelComponentType.GAMESYTEM) {
2024-02-10 10:11:07 +01:00
this.gamesystemOverview!.refresh();
}
}
2024-03-18 17:33:24 +01:00
resetSelection() {
if(this.gamesystemOverview != undefined) {
this.gamesystemOverview.resetSelectedGamesystem()
}
}
2024-03-22 09:42:05 +01:00
2024-01-26 23:07:40 +01:00
}