-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInterface.js
More file actions
92 lines (78 loc) · 2.8 KB
/
UserInterface.js
File metadata and controls
92 lines (78 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const { app, BrowserWindow, globalShortcut, ipcMain } = require("electron");
const path = require('path');
class GUI {
mainClass
win;
constructor(main) {
this.mainClass = main;
app.on('ready', () => {
this.#createWindow()
});
app.on('window-all-closed', () => {
if( process.platform !== 'darwin') {
app.quit();
}
})
app.on('activate', () => {
if(BrowserWindow.getAllWindows().length === 0) {
this.#createWindow();
}
})
}
async #createWindow() {
this.win = new BrowserWindow({
width: 1280,
height: 720,
frame: false,
webPreferences: {
preload: path.join(app.getAppPath(), 'Interface/preload.js')
//nodeIntegration: true,
//contextIsolation: false
}
})
globalShortcut.register('f5', () => {
console.log('f5 is pressed');
this.win.reload();
});
this.win.loadFile('Interface/GUInterface.html');
this.#ipcHandler();
}
async #ipcHandler() {
ipcMain.on('windowEvent', (event, eventType) => {
switch(eventType) {
case 'exit':
this.win.close()
break;
case 'maximize':
this.win.isMaximized() ? this.win.unmaximize() : this.win.maximize();
break;
case 'minimize':
this.win.minimize();
break;
}
})
let superThis = this;
function sendTurtleList() {
let turtleData = [];
superThis.mainClass.turtles.forEach((turtle) => { turtleData.push({ id: turtle.id, position: turtle.position, dir: turtle.heading }) });
superThis.win.send('turtleData', turtleData);
}
function sendWorldData() {
superThis.win.send('worldData', superThis.mainClass.world);
}
ipcMain.on('dataRequest', (request, requestType) => {
switch(requestType) {
case 'turtleData':
sendTurtleList(request);
case 'worldData':
sendWorldData(request);
}
})
this.mainClass.eventBus.on('turtleListUpdate', () => {sendTurtleList()});
this.mainClass.eventBus.on('worldDataUpdate', () => {sendWorldData()});
this.mainClass.eventBus.on('turtleDataUpdate', (turtle) => {
this.win.send('turtleUpdate', { id: turtle.id, position: turtle.position, dir: turtle.heading});
})
}
}
exports.GUI = GUI;