Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
therealbenpai committed Dec 6, 2023
1 parent 705f639 commit 3bc6575
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
44 changes: 25 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
const { app, BrowserWindow, MessageChannelMain } = require('electron')
const path = require('path')

function generateSeedWindow(channel) {
const win = new BrowserWindow({
width: 360,
height: 120,
parent: BrowserWindow.getFocusedWindow(),
modal: true,
alwaysOnTop: true,
title: 'Enter A Seed',
autoHideMenuBar: true,
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
sandbox: false,
preload: path.join(__dirname, 'server', 'promptpre.js')
}
})

win.loadURL(path.join(__dirname, "modules", "prompt", "index.html"))

win.webContents.postMessage('port', '*', [channel])
return win
}

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
Expand Down Expand Up @@ -31,32 +54,15 @@ app.whenReady().then(() => {

mainWin.loadFile('web/index.html')

const promptWindow = new BrowserWindow({
width: 360,
height: 120,
parent: BrowserWindow.getFocusedWindow(),
modal: true,
alwaysOnTop: true,
title: 'Enter A Seed',
autoHideMenuBar: true,
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
sandbox: false,
preload: path.join(__dirname, 'server', 'promptpre.js')
}
})

promptWindow.loadURL(path.join(__dirname, "modules", "prompt", "index.html"))

const mainWinMessager = new MessageChannelMain()
const pWinMgr = mainWinMessager.port1
pWinMgr.start()
const mWinMgr = mainWinMessager.port2
mWinMgr.start()

mainWin.webContents.ipc.handle('web:close', _ => mainWin.close())
mainWin.webContents.ipc.handle('web:reseed', _ => generateSeedWindow(pWinMgr))

promptWindow.webContents.postMessage('port', '*', [pWinMgr])
generateSeedWindow(pWinMgr)
mainWin.webContents.postMessage('port', '*', [mWinMgr])
})
2 changes: 1 addition & 1 deletion modules/prompt/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}

function response() {
window.port.postMessage({env: 'seed', seed: document.getElementById("data").value})
port.postMessage({env: 'seed', seed: document.getElementById("data").value})
this.close();
}

Expand Down
1 change: 1 addition & 0 deletions server/mainpre.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ipcRenderer.on(
globalThis.port = e.ports[0]
globalThis.ipc = ipcRenderer
globalThis.close = () => ipcRenderer.invoke('web:close')
globalThis.reseed = () => ipcRenderer.invoke('web:reseed')
}
)

4 changes: 2 additions & 2 deletions server/promptpre.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { ipcRenderer } = require('electron');
ipcRenderer.on(
'port',
e => {
window.port = e.ports[0]
window.ipc = ipcRenderer
globalThis.port = e.ports[0]
globalThis.ipc = ipcRenderer
}
)
5 changes: 0 additions & 5 deletions web/javascript/class/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ module.exports = class Game {
hillExtreme: 4
};
this.switchCamCoolDown = 0;
this.basedist = new ranjs.dist.Normal(0, 1)
this.basedist.seed(seed)
this.teraindist = new ranjs.dist.Normal(-1, 1)
this.teraindist.seed(seed)
ranjs.core.seed(seed)
}

generateTerrain() {
Expand Down
1 change: 1 addition & 0 deletions web/javascript/tileEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ port

document.addEventListener('keydown', function (event) {
if (event.code === 'Escape') close()
if (event.code === 'KeyM') reseed()
if (event.code === 'KeyR') {
game.generateTerrain()
game.player.position = Object.assign(game.player.position, { x: 100, y: 3000 })
Expand Down

0 comments on commit 3bc6575

Please sign in to comment.