2024-01-27 13:36:12 +01:00
import { Component , NgZone , OnInit , ViewChild } from '@angular/core' ;
2024-01-27 10:34:41 +01:00
import { ElectronService } from './core/services' ;
import { APP_CONFIG } from '../environments/environment' ;
import { ModelComponentType } from "./game-model/ModelComponentType" ;
import { MatDrawerContainer } from "@angular/material/sidenav" ;
import { ModelComponentTypeUtillities } from "./game-model/ModelComponentTypeUtillities" ;
2024-01-27 11:07:40 +01:00
import { GameModel } from "./game-model/GameModel" ;
2024-01-27 11:25:02 +01:00
import { EditorComponent } from "./editor/editor.component" ;
import { ModelComponent } from "./game-model/ModelComponent" ;
2024-01-27 13:36:12 +01:00
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" ;
import { ScriptAccount } from "./game-model/scriptAccounts/ScriptAccount" ;
2024-02-06 20:21:52 +01:00
import { GamescriptOverviewComponent } from "./side-overviews/gamescript-overview/gamescript-overview.component" ;
2024-02-17 08:45:22 +01:00
import { LoadedProject } from "../../app/LoadedProject" ;
import { ProcessLoadedProject } from "./game-model/fs/ProcessLoadedProject" ;
2024-02-17 10:13:32 +01:00
import { StoreProject } from "./game-model/fs/store/StoreProject" ;
2024-03-18 18:12:55 +01:00
import { Gamesystem } from "./game-model/gamesystems/Gamesystem" ;
2024-03-19 17:03:07 +01:00
import { DeleteModel } from "./game-model/fs/DeleteModel" ;
2024-01-26 23:07:40 +01:00
@Component ( {
selector : 'app-root' ,
templateUrl : './app.component.html' ,
styleUrls : [ './app.component.css' ]
} )
2024-01-27 11:07:40 +01:00
export class AppComponent implements OnInit {
2024-01-27 10:34:41 +01:00
openContent : ModelComponentType | undefined = undefined ;
@ViewChild ( 'drawer' ) drawer : MatDrawerContainer | undefined
2024-01-27 11:25:02 +01:00
@ViewChild ( 'editor' ) editor : EditorComponent | undefined
2024-01-27 13:36:12 +01:00
@ViewChild ( 'scriptAccountOverview' ) scriptAccountOverview : ScriptAccountOverviewComponent | undefined
2024-02-06 20:21:52 +01:00
@ViewChild ( 'gamesystemOverview' ) gamesystemOverview : GamescriptOverviewComponent | undefined
2024-01-27 10:34:41 +01:00
2024-01-27 11:07:40 +01:00
gameModel : GameModel | undefined
2024-01-27 13:36:12 +01:00
constructor ( private electronService : ElectronService ,
2024-01-27 15:25:32 +01:00
private zone : NgZone ,
private dialog : MatDialog
2024-01-26 23:07:40 +01:00
) {
console . log ( 'APP_CONFIG' , APP_CONFIG ) ;
2024-03-18 15:58:44 +01:00
if ( this . gameModel == undefined ) {
this . gameModel = new GameModel ( "Unknown GameModel" )
}
2024-01-26 23:07:40 +01:00
if ( electronService . isElectron ) {
console . log ( process . env ) ;
console . log ( 'Run in electron' ) ;
console . log ( 'Electron ipcRenderer' , this . electronService . ipcRenderer ) ;
console . log ( 'NodeJS childProcess' , this . electronService . childProcess ) ;
2024-01-27 13:36:12 +01:00
electronService . ipcRenderer . on ( 'context-menu' , ( event : any , message : string ) = > {
this . zone . run ( ( ) = > {
2024-02-10 10:11:07 +01:00
this . onContextMenuMessageRecieved ( message ) ;
} ) ;
2024-01-27 13:36:12 +01:00
} )
2024-02-16 21:40:21 +01:00
electronService . ipcRenderer . on ( 'get-project-data' , ( event : any , message : string ) = > {
this . zone . run ( ( ) = > {
this . saveGameModel ( ) ;
} )
} )
2024-02-17 08:45:22 +01:00
electronService . ipcRenderer . on ( 'open-project' , ( event : any , loadedProject : LoadedProject ) = > {
this . gameModel = ProcessLoadedProject . processLoadedProject ( loadedProject )
} )
2024-01-26 23:07:40 +01:00
} else {
console . log ( 'Run in browser' ) ;
}
}
2024-01-27 10:34:41 +01:00
2024-02-16 21:40:21 +01:00
saveGameModel() {
2024-02-17 10:13:32 +01:00
const storageModels = StoreProject . storeProject ( this . gameModel ! ) ;
2024-02-16 21:40:21 +01:00
this . electronService . ipcRenderer . send ( 'save-model' , storageModels )
}
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 ! ) ;
this . editor ! . openGameModelComponent ( gamesystem ! ) ;
}
} break
2024-02-10 10:11:07 +01:00
}
}
private onDeleteModelComponent() {
const affectedModelComponent = this . getSelectedModelComponent ( ) ;
2024-03-18 18:12:55 +01:00
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-19 17:03:07 +01:00
this . electronService . ipcRenderer . send ( 'delete-component' , new DeleteModel ( affectedModelComponent . componentName , ModelComponentType . SCRIPTACCOUNT ) )
2024-03-18 18:12:55 +01:00
} else if ( affectedModelComponent instanceof Gamesystem ) {
this . gameModel ! . removeGamesystem ( affectedModelComponent ) ;
this . gamesystemOverview ! . refresh ( )
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
}
}
private onCreateNewScriptAccount() {
const createdScriptAccount = this . gameModel ! . createScriptAccount ( "New ScriptAccount" ) ;
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 ;
}
2024-03-19 08:33:33 +01:00
2024-02-10 10:12:28 +01:00
const createdGamesystem = this . gameModel ! . createGamesystem ( "New Gamesystem" , parentGamesystemName ) ;
if ( createdGamesystem != undefined ) {
this . gamesystemOverview ! . refresh ( ) ;
2024-03-19 08:33:33 +01:00
this . editor ? . openGameModelComponent ( createdGamesystem ) ;
2024-02-10 10:12:28 +01:00
}
2024-02-10 10:11:07 +01:00
}
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 ;
} else {
console . log ( "[WARN] [App.component] ScriptAccountOverview is undefined" )
}
2024-03-18 18:12:55 +01:00
} else if ( this . openContent == ModelComponentType . GAMESYTEM ) {
if ( this . gamesystemOverview != undefined ) {
return this . gamesystemOverview ! . getSelectedGamesystem ( )
} else {
console . log ( "[WARN] [App.component] GamesystemOverview is undefined" )
}
2024-01-27 15:25:32 +01:00
}
return undefined ;
}
2024-01-27 11:07:40 +01:00
ngOnInit() {
2024-02-17 08:45:22 +01:00
/ * t h i s . g a m e M o d e l = n e w G a m e M o d e l ( " N o M o r e " ) ;
2024-02-10 10:11:07 +01:00
this . gameModel . createScriptAccount ( "Temperature" ) ;
this . gameModel . createScriptAccount ( "Luftfeuchtigkeit" ) ;
2024-02-06 20:56:21 +01:00
const weather = new SimpleGamesystem ( "Weather" ) ;
const season = new SimpleGamesystem ( "Season" ) ;
2024-02-10 12:21:31 +01:00
const springState = season . createState ( "Spring" , "Spring, also known as springtime, is one of the four temperate seasons, succeeding winter and preceding summer." ) ;
const summerState = season . createState ( "Summer" , "Summer is the hottest and brightest of the four temperate seasons, occurring after spring and before autumn. " ) ;
2024-02-10 17:07:24 +01:00
const sunnyState = weather . createState ( "Sunny" , "The sun is shining. No clouds, no rain, no storm." ) ;
const rainingState = weather . createState ( "Raining" , "It rains" )
2024-02-10 12:21:31 +01:00
season . createTransition ( springState ! , summerState ! ) ;
2024-02-10 17:07:24 +01:00
weather . createTransition ( sunnyState ! , rainingState ! ) ;
const weather_season = new ProductGamesystem ( "Weather-Season" ) ;
weather_season . addChildGamesystem ( weather ) ;
weather_season . addChildGamesystem ( season ) ;
2024-02-10 17:12:01 +01:00
weather_season . createState ( [ springState ! , sunnyState ! ] ) ;
2024-02-10 11:03:26 +01:00
2024-02-17 08:45:22 +01:00
this . gameModel . addGamesystem ( weather_season ) ; * /
2024-01-27 11:07:40 +01:00
}
2024-01-27 10:34:41 +01:00
openScriptAccountsOverview() {
this . openContent = ModelComponentType . SCRIPTACCOUNT
this . drawer ! . open ( ) ;
}
2024-02-06 20:21:52 +01:00
openGamesystemsOverview() {
this . openContent = ModelComponentType . GAMESYTEM ;
this . drawer ! . open ( ) ;
}
2024-01-27 10:34:41 +01:00
protected readonly ModelComponentType = ModelComponentType ;
closeContentOverview() {
this . drawer ! . close ( ) ;
this . openContent = undefined ;
}
protected readonly ModelComponentTypeUtillities = ModelComponentTypeUtillities ;
2024-01-27 11:25:02 +01:00
openModelComponent ( modelComponent : ModelComponent ) {
if ( this . editor != undefined ) {
this . editor . openGameModelComponent ( modelComponent ) ;
} else {
console . log ( "[WARN] [App.Component] Editor is undefined" )
}
2024-02-09 20:46:00 +01:00
}
2024-01-27 11:25:02 +01:00
2024-02-09 20:46:00 +01:00
onModelNameUpdate() {
if ( this . openContent == ModelComponentType . GAMESYTEM ) {
2024-02-10 10:11:07 +01:00
this . gamesystemOverview ! . refresh ( ) ;
2024-02-09 20:46:00 +01:00
}
2024-01-27 11:25:02 +01:00
}
2024-03-18 17:33:24 +01:00
resetSelection() {
if ( this . gamesystemOverview != undefined ) {
this . gamesystemOverview . resetSelectedGamesystem ( )
}
}
2024-01-26 23:07:40 +01:00
}