From 3bc65751b675d37781bd57a58b197eca15d0c4bb Mon Sep 17 00:00:00 2001 From: Benjamin Marsh Date: Wed, 6 Dec 2023 08:27:28 -0500 Subject: [PATCH] more updates --- index.js | 44 ++++++++++++++++++++---------------- modules/prompt/index.html | 2 +- server/mainpre.js | 1 + server/promptpre.js | 4 ++-- web/javascript/class/game.js | 5 ---- web/javascript/tileEngine.js | 1 + 6 files changed, 30 insertions(+), 27 deletions(-) diff --git a/index.js b/index.js index 00e34af..197e312 100644 --- a/index.js +++ b/index.js @@ -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() }) @@ -31,24 +54,6 @@ 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() @@ -56,7 +61,8 @@ app.whenReady().then(() => { 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]) }) \ No newline at end of file diff --git a/modules/prompt/index.html b/modules/prompt/index.html index ef310fb..e4a4036 100644 --- a/modules/prompt/index.html +++ b/modules/prompt/index.html @@ -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(); } diff --git a/server/mainpre.js b/server/mainpre.js index 3edb88b..ac28202 100644 --- a/server/mainpre.js +++ b/server/mainpre.js @@ -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') } ) diff --git a/server/promptpre.js b/server/promptpre.js index dc7afaf..2097e98 100644 --- a/server/promptpre.js +++ b/server/promptpre.js @@ -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 } ) \ No newline at end of file diff --git a/web/javascript/class/game.js b/web/javascript/class/game.js index c5370df..1cf1bc0 100644 --- a/web/javascript/class/game.js +++ b/web/javascript/class/game.js @@ -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() { diff --git a/web/javascript/tileEngine.js b/web/javascript/tileEngine.js index e5f2461..2909f89 100644 --- a/web/javascript/tileEngine.js +++ b/web/javascript/tileEngine.js @@ -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 })