-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (46 loc) · 1.18 KB
/
index.js
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
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const fs = require('fs')
var selectedCharacter = {}
var win
const createWindow = () => {
win = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
win.loadFile('html/mainMenu.html')
}
app.whenReady().then(() => {
ipcMain.on("loadCharacter", (e, character) => {
console.log(`loading ${character}`)
fs.readFile(`saves/${character}`, (err, data) => {
if (err) {
console.log("Save does not exist")
win.loadFile("html/mainMenu.html")
}
else {
selectedCharacter = JSON.parse(data)
//win.loadFile("html/gameLobby.html")
}
})
})
ipcMain.handle("getSaves", () => {
return fs.promises.readdir('saves/')
})
ipcMain.handle("readCharacter", () => {
if (selectedCharacter && Object.keys(selectedCharacter).length > 0) {
return selectedCharacter
}
else {
win.loadFile("html/mainMenu.html")
return
}
})
createWindow()
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})