diff options
Diffstat (limited to 'views/script')
-rw-r--r-- | views/script/core_chart.js | 8 | ||||
-rw-r--r-- | views/script/core_crash.js | 21 | ||||
-rw-r--r-- | views/script/core_fullscreen.js | 43 | ||||
-rw-r--r-- | views/script/core_stats.js | 64 | ||||
-rw-r--r-- | views/script/core_viewer.js | 42 | ||||
-rw-r--r-- | views/script/loader_global.js | 127 | ||||
-rw-r--r-- | views/script/menu_copyright.js | 4 | ||||
-rw-r--r-- | views/script/menu_global.js | 3 | ||||
-rw-r--r-- | views/script/menu_login.js | 114 | ||||
-rw-r--r-- | views/script/settings_global.js | 10 |
10 files changed, 280 insertions, 156 deletions
diff --git a/views/script/core_chart.js b/views/script/core_chart.js index 059c818..2f8a521 100644 --- a/views/script/core_chart.js +++ b/views/script/core_chart.js @@ -2,7 +2,7 @@ setInterval(() => { try { currentMemory = process.memoryUsage().rss; currentMemoryMib = (((currentMemory)/1024)/1024).toFixed(2); - if ((((currentMemory)/1024)/1024) > 250) { + if ((((currentMemory)/1024)/1024) > ((require('os').totalmem() / 1000000) / 4)) { throw new Error("Out of memory"); } @@ -66,5 +66,9 @@ setInterval(() => { } else { document.title="Kartik"+require('@electron/remote').getCurrentWindow().channel+require('./package.json').version + eaid; } - } catch (e) {} + } catch (e) { + if (e.message === "Out of memory") { + throw e; + } + } }, 1000)
\ No newline at end of file diff --git a/views/script/core_crash.js b/views/script/core_crash.js new file mode 100644 index 0000000..d24ec2d --- /dev/null +++ b/views/script/core_crash.js @@ -0,0 +1,21 @@ +global.gameCrashed = false; +crashSound = new Audio("./sfx/gamecrash.wav"); + +function destroy() { + global.gameCrashed = true; + crashSound.play(); + require('@electron/remote').webContents.fromId(webview.getWebContentsId()).forcefullyCrashRenderer(); + try { musicElement.pause(); } catch (e) {} +} + +function spawnError(crashReport) { + document.getElementById("error-outer").style.display = "flex"; + document.getElementById("crash-dump").value = crashReport; + destroy(); +} + +const crashHandler = require('electron').ipcRenderer; + +crashHandler.on('crashreport', (event, args) => { + spawnError(args); +})
\ No newline at end of file diff --git a/views/script/core_fullscreen.js b/views/script/core_fullscreen.js index 69f9e45..f2c540d 100644 --- a/views/script/core_fullscreen.js +++ b/views/script/core_fullscreen.js @@ -1,9 +1,40 @@ -$(document).keydown(function(e) { - if (e.keyCode === 122 || e.keyCode === 121 || e.keyCode === 112) { // F11/F1/F10 - if (!require('@electron/remote').getCurrentWindow().fullScreen && require('@electron/remote').getCurrentWindow().fullScreenable) { - require('@electron/remote').getCurrentWindow().setFullScreen(true); - } else { - require('@electron/remote').getCurrentWindow().setFullScreen(false); +window.addEventListener("load", () => { + require('@electron/remote').getCurrentWindow().show(); + + const Nest = require("./nest/abi"); + + $(document).keydown(function(e) { + if (e.keyCode === 122 || e.keyCode === 121 || e.keyCode === 112) { // F11/F1/F10 + if (!require('@electron/remote').getCurrentWindow().fullScreen && require('@electron/remote').getCurrentWindow().fullScreenable) { + require('@electron/remote').getCurrentWindow().setFullScreen(true); + } else { + require('@electron/remote').getCurrentWindow().setFullScreen(false); + } } + }) + + $(document).keydown(function(e) { + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + + if (e.keyCode === 122 || e.keyCode === 121 || e.keyCode === 112) { + if (currentNest.config.fullscreen) { + currentNest.config.fullscreen = false; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + require('electron').ipcRenderer.send("reloadNest") + } else { + currentNest.config.fullscreen = true; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + require('electron').ipcRenderer.send("reloadNest"); + } + } + }) + + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + if (currentNest.config.fullscreen) { + require('@electron/remote').getCurrentWindow().setFullScreen(true); + } else { + currentNest.config.fullscreen = false; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + require('electron').ipcRenderer.send("reloadNest") } })
\ No newline at end of file diff --git a/views/script/core_stats.js b/views/script/core_stats.js index c8d26df..930c776 100644 --- a/views/script/core_stats.js +++ b/views/script/core_stats.js @@ -6,42 +6,46 @@ timer = null; current = null; webview.addEventListener('dom-ready', () => { - if (webview.getURL() !== current) { - if (session !== null) { - require('electron').ipcRenderer.send('addstats', { catalog: "times", key: session, add: Math.floor((new Date() - timer)/1000) }); + try { + if (webview.getURL() !== current) { + if (session !== null) { + require('electron').ipcRenderer.send('addstats', { catalog: "times", key: session, add: Math.floor((new Date() - timer)/1000) }); - session = null; - timer = null; - current = null; + session = null; + timer = null; + current = null; + } } - } - if (webview.getURL().endsWith("game.html")) { // Local - session = "local"; - timer = new Date(); - current = webview.getURL(); - } - if (webview.getURL().endsWith("game.html?sp")) { // Singleplayer - session = "single"; - timer = new Date(); - current = webview.getURL(); - } - if (webview.getURL().endsWith("game.html?online")) { // Online - session = "online"; - timer = new Date(); - current = webview.getURL(); - } + if (webview.getURL().endsWith("game.html")) { // Local + session = "local"; + timer = new Date(); + current = webview.getURL(); + } + if (webview.getURL().endsWith("game.html?sp")) { // Singleplayer + session = "single"; + timer = new Date(); + current = webview.getURL(); + } + if (webview.getURL().endsWith("game.html?online")) { // Online + session = "online"; + timer = new Date(); + current = webview.getURL(); + } + } catch (e) {} }) window.addEventListener("beforeunload", function(e){ - if (session !== null) { - require('electron').ipcRenderer.send('addstatsandclose', { catalog: "times", key: session, add: Math.floor((new Date() - timer)/1000) }); + try { + if (session !== null) { + require('electron').ipcRenderer.send('addstatsandclose', { catalog: "times", key: session, add: Math.floor((new Date() - timer)/1000) }); - session = null; - timer = null; - current = null; + session = null; + timer = null; + current = null; - e.preventDefault(); - return false; - } + e.preventDefault(); + return false; + } + } catch (e) {} }, false);
\ No newline at end of file diff --git a/views/script/core_viewer.js b/views/script/core_viewer.js index 389bf41..eac3766 100644 --- a/views/script/core_viewer.js +++ b/views/script/core_viewer.js @@ -1,24 +1,28 @@ const webview = document.getElementById('wb'); -webview.addEventListener('dom-ready', () => { - document.getElementById('dummyloader').style.display = "none"; - require('@electron/remote').getCurrentWindow().log(" * " + webview.getURL()); - try { - if (require('@electron/remote').getCurrentWindow().debug) { - info("MainWindow", "Opening debugging tools..."); - webview.openDevTools(); - } - } catch (e) {} -}) - -webview.addEventListener('dom-ready', () => { - setInterval(() => { +try { + webview.addEventListener('dom-ready', () => { + document.getElementById('dummyloader').style.display = "none"; + require('@electron/remote').getCurrentWindow().log(" * " + webview.getURL()); + require('@electron/remote').getCurrentWindow().focus(); + webview.focus(); try { - if (webview.isCrashed()) { - require('@electron/remote').getCurrentWindow().log(" * Compositing engine crashed!"); - error("MainWindow", "Subcontainer crashed"); - crash(new Error("Webview crashed")); + if (require('@electron/remote').getCurrentWindow().debug) { + info("MainWindow", "Opening debugging tools..."); + webview.openDevTools(); } } catch (e) {} - }, 2000) -})
\ No newline at end of file + }) + + webview.addEventListener('dom-ready', () => { + setInterval(() => { + try { + if (webview.isCrashed() && !gameCrashed) { + require('@electron/remote').getCurrentWindow().log(" * Compositing engine crashed!"); + error("MainWindow", "Subcontainer crashed"); + crash(new Error("Webview crashed")); + } + } catch (e) {} + }, 2000) + }) +} catch (e) {}
\ No newline at end of file diff --git a/views/script/loader_global.js b/views/script/loader_global.js index db70d3b..7543268 100644 --- a/views/script/loader_global.js +++ b/views/script/loader_global.js @@ -3,7 +3,7 @@ window.addEventListener('load', () => { if (native) { setTimeout(() => { setTimeout(() => { - if (native) {global.$ = require('jquery');} else {var script = document.createElement('script');script.src = '../webinit/jquery.js';script.type = 'text/javascript';document.getElementsByTagName('head')[0].appendChild(script);} + $("#progress").fadeOut(500); setTimeout(() => { window.fetch("https://kartik.hopto.org/latest.php?v=" + require('@electron/remote').getCurrentWindow().update).then((data) => { @@ -25,18 +25,19 @@ window.addEventListener('load', () => { } } setTimeout(() => { - document.getElementById('banner').style.width = "380px"; - document.getElementById('banner').style.height = "auto"; - document.getElementById('banner').src = "common/banner.gif"; - introsfx = new Audio("../sfx/newintro.mp3"); - introsfx.play() - introsfx.onended = () => { - $("body").fadeOut(500); - setTimeout(() => { - info("LoadWindow", "Switching control to MenuWindow"); - location.href = "intro.html"; - }, 1000) - } + $("#banner-outer").fadeOut(200); + $("#intro-video").fadeIn(200); + setTimeout(() => { + introsfx = document.getElementById("intro-video"); + introsfx.play() + introsfx.onended = () => { + $("body").fadeOut(500); + setTimeout(() => { + info("LoadWindow", "Switching control to MenuWindow"); + location.href = "intro.html"; + }, 1000) + } + }, 200) }, 2000) }).catch((e) => { console.warn(e); @@ -44,10 +45,31 @@ window.addEventListener('load', () => { document.getElementById('updates').innerText = lang.updates.error; require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); setTimeout(() => { - document.getElementById('banner').style.width = "380px"; - document.getElementById('banner').style.height = "auto"; - document.getElementById('banner').src = "common/banner.gif"; - introsfx = new Audio("../sfx/newintro.mp3"); + $("#banner-outer").fadeOut(200); + $("#intro-video").fadeIn(200); + setTimeout(() => { + introsfx = document.getElementById("intro-video"); + introsfx.play() + introsfx.onended = () => { + $("body").fadeOut(500); + setTimeout(() => { + info("LoadWindow", "Switching control to MenuWindow"); + location.href = "intro.html"; + }, 1000) + } + }, 200) + }, 2000) + }); + }).catch((e) => { + console.warn(e); + document.getElementById('updates').style.backgroundColor = "lightcoral"; + document.getElementById('updates').innerText = lang.updates.error; + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); + setTimeout(() => { + $("#banner-outer").fadeOut(200); + $("#intro-video").fadeIn(200); + setTimeout(() => { + introsfx = document.getElementById("intro-video"); introsfx.play() introsfx.onended = () => { $("body").fadeOut(500); @@ -56,18 +78,19 @@ window.addEventListener('load', () => { location.href = "intro.html"; }, 1000) } - }, 2000) - }); - }).catch((e) => { - console.warn(e); - document.getElementById('updates').style.backgroundColor = "lightcoral"; - document.getElementById('updates').innerText = lang.updates.error; - require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); + }, 200) + }, 2000) + }); + }).catch((e) => { + console.warn(e); + document.getElementById('updates').style.backgroundColor = "lightcoral"; + document.getElementById('updates').innerText = lang.updates.error; + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); + setTimeout(() => { + $("#banner-outer").fadeOut(200); + $("#intro-video").fadeIn(200); setTimeout(() => { - document.getElementById('banner').style.width = "380px"; - document.getElementById('banner').style.height = "auto"; - document.getElementById('banner').src = "common/banner.gif"; - introsfx = new Audio("../sfx/newintro.mp3"); + introsfx = document.getElementById("intro-video"); introsfx.play() introsfx.onended = () => { $("body").fadeOut(500); @@ -76,46 +99,28 @@ window.addEventListener('load', () => { location.href = "intro.html"; }, 1000) } - }, 2000) - }); - }).catch((e) => { - console.warn(e); - document.getElementById('updates').style.backgroundColor = "lightcoral"; - document.getElementById('updates').innerText = lang.updates.error; - require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); - setTimeout(() => { - document.getElementById('banner').style.width = "380px"; - document.getElementById('banner').style.height = "auto"; - document.getElementById('banner').src = "common/banner.gif"; - introsfx = new Audio("../sfx/newintro.mp3"); - introsfx.play() - introsfx.onended = () => { - $("body").fadeOut(500); - setTimeout(() => { - info("LoadWindow", "Switching control to MenuWindow"); - location.href = "intro.html"; - }, 1000) - } + }, 200) }, 2000) }); }, 2000) }, 3000) }, 1000) } else { - if (native) {global.$ = require('jquery');} else {var script = document.createElement('script');script.src = '../webinit/jquery.js';script.type = 'text/javascript';document.getElementsByTagName('head')[0].appendChild(script);} + setTimeout(() => { - document.getElementById('banner').style.width = "380px"; - document.getElementById('banner').style.height = "auto"; - document.getElementById('banner').src = "common/banner.gif"; - introsfx = new Audio("../sfx/newintro.mp3"); - introsfx.play() - introsfx.onended = () => { - $("body").fadeOut(500); - setTimeout(() => { - info("LoadWindow", "Switching control to MenuWindow"); - location.href = "intro.html"; - }, 1000) - } + $("#banner-outer").fadeOut(200); + $("#intro-video").fadeIn(200); + setTimeout(() => { + introsfx = document.getElementById("intro-video"); + introsfx.play() + introsfx.onended = () => { + $("body").fadeOut(500); + setTimeout(() => { + info("LoadWindow", "Switching control to MenuWindow"); + location.href = "intro.html"; + }, 1000) + } + }, 200) }, 5000) } }, 2000) diff --git a/views/script/menu_copyright.js b/views/script/menu_copyright.js index 35b322a..2b38844 100644 --- a/views/script/menu_copyright.js +++ b/views/script/menu_copyright.js @@ -1,5 +1,5 @@ if (new Date().getFullYear() === 2021) { - document.write(new Date().getFullYear() + " Minteck Projects"); + document.write(new Date().getFullYear() + " Minteck"); } else { - document.write("2021-" + new Date().getFullYear() + " Minteck Projects"); + document.write("2021-" + new Date().getFullYear() + " Minteck"); }
\ No newline at end of file diff --git a/views/script/menu_global.js b/views/script/menu_global.js index 8561fe3..14a924f 100644 --- a/views/script/menu_global.js +++ b/views/script/menu_global.js @@ -14,6 +14,9 @@ $(document).keydown(function(e) { if (loggingIn) { return; } if (keysEnabled) { + if (e.ctrlKey && e.keyCode === 13) { // ctrl+enter + throw new RangeError("Manually initiated crash"); + } if (e.keyCode === 13 || e.keyCode === 88 || e.keyCode === 32) { // enter if ($(".services").is(":visible")) { selectOption(); diff --git a/views/script/menu_login.js b/views/script/menu_login.js index 7f50101..2af88b2 100644 --- a/views/script/menu_login.js +++ b/views/script/menu_login.js @@ -54,7 +54,7 @@ function startLogin() { loggingIn = false; document.getElementById('loggingIn').style.display = "none"; currentNest.auth = playerData; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") keysEnabled = false; require('electron').ipcRenderer.send('prefademusic', ""); $("#box").fadeOut(500); @@ -109,49 +109,101 @@ window.addEventListener('load', () => { }) function postOnlineMode() { - if (currentNest.auth === null || !onlineMode) { - $(document).keydown(function(e) { - if (e.keyCode === 76 && !loggingIn && onlineMode) { - startLogin(); + try { + if (currentNest.auth === null || !onlineMode) { + $(document).keydown(function(e) { + if (e.keyCode === 76 && !loggingIn && onlineMode) { + startLogin(); + } + }) + } else { + authData = currentNest.auth; + + document.getElementById('loginIntro').style.display = "none"; + document.getElementById('loginUser').style.display = "grid"; + + olevel = $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + authData.token, + async: false, + error: (e) => { throw e; } + }).responseText.trim() - 1 + 1; + + if (authData.level > olevel) { + $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/set.level.php?kartik_online_token=' + authData.token + "&level=" + authData.level, + async: false, + error: (e) => { throw e; } + }); + } else if (authData.level < olevel) { + authData.level = $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + authData.token, + async: false, + error: (e) => { throw e; } + }).responseText.trim() - 1 + 1; + currentNest.auth = authData; + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") } - }) - } else { - authData = currentNest.auth; - document.getElementById('loginIntro').style.display = "none"; - document.getElementById('loginUser').style.display = "grid"; + ostats = JSON.parse($.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/profile.stats.php?kartik_online_token=' + authData.token, + async: false, + error: (e) => { throw e; } + }).responseText.trim()) - olevel = $.ajax({ - type: "GET", - url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + authData.token, - async: false, - error: (e) => { throw e; } - }).responseText.trim() - 1 + 1; + if (ostats === null) { + cstats = currentNest.stats; + } else { + cstats = {}; + + for (group in currentNest.stats) { + cstats[group] = {}; + + for (item in currentNest.stats[group]) { + if (ostats[group][item]) { + if (ostats[group][item] > currentNest.stats[group][item]) { + cstats[group][item] = ostats[group][item]; + } else { + cstats[group][item] = currentNest.stats[group][item]; + } + } else { + cstats[group][item] = currentNest.stats[group][item]; + } + } + } + } - if (authData.level > olevel) { $.ajax({ type: "GET", - url: 'https://kartik.hopto.org/online/ingame/api/set.level.php?kartik_online_token=' + authData.token + "&level=" + authData.level, + url: 'https://kartik.hopto.org/online/ingame/api/set.stats.php?kartik_online_token=' + authData.token + "&stats=" + Buffer.from(JSON.stringify(cstats)).toString("base64"), async: false, error: (e) => { throw e; } }); - } else if (authData.level < olevel) { - authData.level = $.ajax({ + + currentNest.stats = JSON.parse($.ajax({ type: "GET", - url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + authData.token, + url: 'https://kartik.hopto.org/online/ingame/api/profile.stats.php?kartik_online_token=' + authData.token, async: false, error: (e) => { throw e; } - }).responseText.trim() - 1 + 1; - currentNest.auth = authData; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); - } + }).responseText.trim()); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") - document.getElementById('kto-picture').src = authData.picture; - document.getElementById('kto-username').innerText = authData.name; - if (authData.level < 200) { - document.getElementById('kto-level').innerText = authData.level; - } else { - document.getElementById('kto-level').innerText = lang.polymer.ktoMaxLevel; + document.getElementById('kto-picture').src = authData.picture; + document.getElementById('kto-username').innerText = authData.name; + if (authData.level < 200) { + document.getElementById('kto-level').innerText = authData.level; + } else { + document.getElementById('kto-level').innerText = lang.polymer.ktoMaxLevel; + } } + } catch (e) { + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]}); + console.error(e); + onlineMode = false; + document.getElementById("loginIntro").innerText = lang.polymer.error[2]; + document.getElementById("online").parentElement.parentElement.outerHTML = ""; } }
\ No newline at end of file diff --git a/views/script/settings_global.js b/views/script/settings_global.js index e284585..90f1f6e 100644 --- a/views/script/settings_global.js +++ b/views/script/settings_global.js @@ -46,22 +46,22 @@ $(document).keydown(function(e) { if (document.getElementById("setting-music").innerText === "1") { document.getElementById("setting-music").innerText = "0"; currentNest.config.music = false; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") } else { document.getElementById("setting-music").innerText = "1"; currentNest.config.music = true; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") } } if (id === "voice") { if (document.getElementById("setting-voice").innerText === "1") { document.getElementById("setting-voice").innerText = "0"; currentNest.config.music = false; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") } else { document.getElementById("setting-voice").innerText = "1"; currentNest.config.music = true; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") } } if (id === "lang") { @@ -86,7 +86,7 @@ $(document).keydown(function(e) { if (ci !== -1 && ni !== -1) { document.getElementById("setting-lang").innerText = slng[slst[ni]]; currentNest.config.lang = slst[ni]; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") require('@electron/remote').getCurrentWindow().lp = slst[ni]; } } |