diff options
Diffstat (limited to 'views/script')
-rw-r--r-- | views/script/core_compatlayer.js | 178 | ||||
-rw-r--r-- | views/script/core_crash.js | 40 | ||||
-rw-r--r-- | views/script/core_notification.js | 24 | ||||
-rw-r--r-- | views/script/core_stats.js | 100 | ||||
-rw-r--r-- | views/script/game_debug.js | 524 | ||||
-rw-r--r-- | views/script/global_compatlayer.js | 178 | ||||
-rw-r--r-- | views/script/global_levelsapi.js | 92 | ||||
-rw-r--r-- | views/script/loader_global.js | 254 | ||||
-rw-r--r-- | views/script/menu_copyright.js | 8 | ||||
-rw-r--r-- | views/script/menu_global.js | 252 | ||||
-rw-r--r-- | views/script/menu_login.js | 449 | ||||
-rw-r--r-- | views/script/settings_global.js | 254 | ||||
-rw-r--r-- | views/script/settings_load.js | 50 |
13 files changed, 1218 insertions, 1185 deletions
diff --git a/views/script/core_compatlayer.js b/views/script/core_compatlayer.js index c6794f3..74a0962 100644 --- a/views/script/core_compatlayer.js +++ b/views/script/core_compatlayer.js @@ -1,89 +1,89 @@ -window.addEventListener("load", () => { - if (require('os').platform !== "darwin") { - gpuinfo = require('@electron/remote').app.getGPUFeatureStatus(); - gpuscore = 0; - maxscore = 10; - if (gpuinfo['2d_canvas'].startsWith("enabled")) { - if (gpuinfo['2d_canvas'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['gpu_compositing'].startsWith("enabled")) { - if (gpuinfo['gpu_compositing'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['video_decode'].startsWith("enabled")) { - if (gpuinfo['video_decode'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['multiple_raster_threads'].startsWith("enabled")) { - if (gpuinfo['multiple_raster_threads'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['oop_rasterization'].startsWith("enabled")) { - if (gpuinfo['oop_rasterization'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['rasterization'].startsWith("enabled")) { - if (gpuinfo['rasterization'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['opengl'].startsWith("enabled")) { - if (gpuinfo['opengl'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['skia_renderer'].startsWith("enabled")) { - if (gpuinfo['skia_renderer'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['vulkan'].startsWith("enabled")) { - if (gpuinfo['vulkan'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['webgl'].startsWith("enabled")) { - if (gpuinfo['webgl'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - - gpuperct = (gpuscore / maxscore) * 100; - - if (gpuperct < 30) { - console.warn("Bad GPU support, disabling GPU-accelerated content"); - var head = document.getElementsByTagName('HEAD')[0]; - var link = document.createElement('link'); - link.rel = 'stylesheet'; - link.type = 'text/css'; - link.href = './views/common/compatibilityMode.css'; - head.appendChild(link); - } - } -}) +window.addEventListener("load", () => {
+ if (require('os').platform !== "darwin") {
+ gpuinfo = require('@electron/remote').app.getGPUFeatureStatus();
+ gpuscore = 0;
+ maxscore = 10;
+ if (gpuinfo['2d_canvas'].startsWith("enabled")) {
+ if (gpuinfo['2d_canvas'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['gpu_compositing'].startsWith("enabled")) {
+ if (gpuinfo['gpu_compositing'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['video_decode'].startsWith("enabled")) {
+ if (gpuinfo['video_decode'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['multiple_raster_threads'].startsWith("enabled")) {
+ if (gpuinfo['multiple_raster_threads'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['oop_rasterization'].startsWith("enabled")) {
+ if (gpuinfo['oop_rasterization'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['rasterization'].startsWith("enabled")) {
+ if (gpuinfo['rasterization'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['opengl'].startsWith("enabled")) {
+ if (gpuinfo['opengl'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['skia_renderer'].startsWith("enabled")) {
+ if (gpuinfo['skia_renderer'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['vulkan'].startsWith("enabled")) {
+ if (gpuinfo['vulkan'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['webgl'].startsWith("enabled")) {
+ if (gpuinfo['webgl'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+
+ gpuperct = (gpuscore / maxscore) * 100;
+
+ if (gpuperct < 30) {
+ console.warn("Bad GPU support, disabling GPU-accelerated content");
+ var head = document.getElementsByTagName('HEAD')[0];
+ var link = document.createElement('link');
+ link.rel = 'stylesheet';
+ link.type = 'text/css';
+ link.href = './views/common/compatibilityMode.css';
+ head.appendChild(link);
+ }
+ }
+})
diff --git a/views/script/core_crash.js b/views/script/core_crash.js index d24ec2d..1a12230 100644 --- a/views/script/core_crash.js +++ b/views/script/core_crash.js @@ -1,21 +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); +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_notification.js b/views/script/core_notification.js index 118d19d..676b2d0 100644 --- a/views/script/core_notification.js +++ b/views/script/core_notification.js @@ -1,13 +1,13 @@ -var ipcRenderer = require('electron').ipcRenderer; -ipcRenderer.on('notification', function (event, data) { - document.getElementById("notification-title").innerText = data.title; - document.getElementById("notification-message").innerText = data.message; - document.getElementById("notification").style.right = "20px"; - document.getElementById("notification").style.opacity = "1"; - new Audio("./sfx/notification.mp3").play(); - - setTimeout(() => { - document.getElementById("notification").style.right = "-300px"; - document.getElementById("notification").style.opacity = "0"; - }, 5000) +var ipcRenderer = require('electron').ipcRenderer;
+ipcRenderer.on('notification', function (event, data) {
+ document.getElementById("notification-title").innerText = data.title;
+ document.getElementById("notification-message").innerText = data.message;
+ document.getElementById("notification").style.right = "20px";
+ document.getElementById("notification").style.opacity = "1";
+ new Audio("./sfx/notification.mp3").play();
+
+ setTimeout(() => {
+ document.getElementById("notification").style.right = "-300px";
+ document.getElementById("notification").style.opacity = "0";
+ }, 5000)
});
\ No newline at end of file diff --git a/views/script/core_stats.js b/views/script/core_stats.js index 930c776..124f5fe 100644 --- a/views/script/core_stats.js +++ b/views/script/core_stats.js @@ -1,51 +1,51 @@ -const fs = require('fs'); -const homedir = require('@electron/remote').getCurrentWindow().homedir; - -session = null; -timer = null; -current = null; - -webview.addEventListener('dom-ready', () => { - 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; - } - } - - 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){ - 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; - - e.preventDefault(); - return false; - } - } catch (e) {} +const fs = require('fs');
+const homedir = require('@electron/remote').getCurrentWindow().homedir;
+
+session = null;
+timer = null;
+current = null;
+
+webview.addEventListener('dom-ready', () => {
+ 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;
+ }
+ }
+
+ 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){
+ 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;
+
+ e.preventDefault();
+ return false;
+ }
+ } catch (e) {}
}, false);
\ No newline at end of file diff --git a/views/script/game_debug.js b/views/script/game_debug.js index 1fb2639..dee421b 100644 --- a/views/script/game_debug.js +++ b/views/script/game_debug.js @@ -1,263 +1,263 @@ -global.debugshow = false; - -function oil(id) { - return "\nO" + id +": " + document.getElementById('oil' + id + '').style.left.split("px")[0] + " " + document.getElementById('oil' + id + '').style.top.split("px")[0] + " / " + document.getElementById('oil' + id + '').style.transform.split("rotate(")[1].split("deg)")[0]; -} - -$(document).keydown((e) => { - if (e.keyCode === 114) { // F3 - if (debugshow) { - global.debugshow = false; - document.getElementById("debug").style.display = "none"; - } else { - global.debugshow = true; - document.getElementById("debug").style.display = ""; - } - } -}) - -if (require('os').platform() !== "darwin") { - gpuinfo = require('@electron/remote').app.getGPUFeatureStatus(); - gpuscore = 0; - maxscore = 10; - if (gpuinfo['2d_canvas'].startsWith("enabled")) { - if (gpuinfo['2d_canvas'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['gpu_compositing'].startsWith("enabled")) { - if (gpuinfo['gpu_compositing'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['video_decode'].startsWith("enabled")) { - if (gpuinfo['video_decode'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['multiple_raster_threads'].startsWith("enabled")) { - if (gpuinfo['multiple_raster_threads'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['oop_rasterization'].startsWith("enabled")) { - if (gpuinfo['oop_rasterization'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['rasterization'].startsWith("enabled")) { - if (gpuinfo['rasterization'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['opengl'].startsWith("enabled")) { - if (gpuinfo['opengl'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['skia_renderer'].startsWith("enabled")) { - if (gpuinfo['skia_renderer'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['vulkan'].startsWith("enabled")) { - if (gpuinfo['vulkan'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['webgl'].startsWith("enabled")) { - if (gpuinfo['webgl'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - - gpuperct = (gpuscore/maxscore)*100; -} else { - gpuperct = 100; -} - -pubver = require('../package.json').version; -pvpart = pubver.split("."); -if (pvpart.length === 3) { - intver = pvpart[0] + "." + pvpart[1]; -} else { - intver = "unknown"; -} - -if (require('@electron/remote').getCurrentWindow().mods.length > 0) { - release = "mods+" + require('@electron/remote').getCurrentWindow().mods.length; -} else { - release = "official"; -} - -if (gpuperct < 25) { - perf = "fast"; -} else if (gpuperct < 50) { - perf = "fancy"; -} else { - perf = "fabulous"; -} - -if (location.search === "") { - game = "Local multiplayer game"; -} else if (location.search === "?sp") { - game = "Singleplayer game"; -} else if (location.search === "?online") { - game = require("../online/server.json").hostname + ":" + require("../online/server.json").port; -} - -tps = -1; -cping = -1; -changedDataLeft = "playing: %false%" -changedDataRight = "" -immutableDataLeft = "Kartik " + pubver + " (" + intver + "/" + require('../package.json').channel + "+" + release + ")\n%tps% tps T:" + perf + ";vsync\n" + game + " @ %ping% ms ticks"; -immutableDataRight = "Electron: " + process.versions.electron + " " + process.arch; - -credits = "Debug: start runtime with debug argument\nFor help: https://kartik.hopto.org" - -setInterval(() => { - if (!debugshow) { return; } - - - leftparts = (immutableDataLeft + "\n" + changedDataLeft + "\n\n" + credits).split("\n"); - lefttext = "<span style='background:rgba(101,101,101,0.75);font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;padding:1px;'>" + leftparts.join("</span><br><span style='background:rgba(101,101,101,0.75);font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;padding:1px;'>") + "</span>"; - - rightparts = (immutableDataRight + "\n" + changedDataRight).split("\n"); - righttext = "<span style='background:rgba(101,101,101,0.75);font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;padding:1px;'>" + rightparts.join("</span><br><span style='background:rgba(101,101,101,0.75);font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;padding:1px;'>") + "</span>"; - - document.getElementById("debug-left").innerHTML = lefttext.replaceAll("%tps%", tps).replaceAll("%ping%", cping).replaceAll("%false%", "<span style='color:red;font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;'>false</span>").replaceAll("%true%", "<span style='color:green;font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;'>true</span>"); - document.getElementById("debug-right").innerHTML = righttext; -}, 100) - -var filterStrength = 20; -var frameTime = 0, lastLoop = new Date, thisLoop; - -setInterval(() => { - if (!debugshow) { return; } - - var thisFrameTime = (thisLoop=new Date) - lastLoop; - frameTime+= (thisFrameTime - frameTime) / filterStrength; - lastLoop = thisLoop; -}, 50) - -require('systeminformation').graphics().then((data) => { - global.gpudata = data; -}); - -setInterval(() => { - if (!debugshow) { return; } - - tps = (1000/frameTime).toFixed(1); - - if (typeof ping === "number") { - cping = ping; - } else { - cping = 0; - } - - if (started) { - changedDataLeft = "playing: %true%"; - changedDataLeft += "\n\n0$: XY: " + document.getElementById('car0').style.left.split("px")[0] + " / " + document.getElementById('car0').style.top.split("px")[0] - - c0rotate = document.getElementById('car0').style.transform.split("rotate(")[1].split("deg)")[0]; - if (c0rotate === "90") { - changedDataLeft += "\n0$: Facing: south (Towards negative Y)"; - } else if (c0rotate === "-90") { - changedDataLeft += "\n0$: Facing: north (Towards negative Y)"; - } else if (c0rotate === "0") { - changedDataLeft += "\n0$: Facing: east (Towards positive X)"; - } else if (c0rotate === "180") { - changedDataLeft += "\n0$: Facing: west (Towards negative X)"; - } - - changedDataLeft += "\n0$: Speed: A: " + car0cspeed.toFixed(2) + " R: " + (car0speed - car0cspeed).toFixed(2) + " M: " + car0speed.toFixed(2); - - changedDataLeft += "\n0$: Laps: " + document.getElementById('laps-car0').innerText + "/5"; - changedDataLeft += "\n0$: Model: " + selectedModel0; - changedDataLeft += "\n0$: Collision: " + (car0collisionon ? "%true%" : "%false%"); - - changedDataLeft += "\n\n1$: XY: " + document.getElementById('car1').style.left.split("px")[0] + " / " + document.getElementById('car1').style.top.split("px")[0] - - c0rotate = document.getElementById('car1').style.transform.split("rotate(")[1].split("deg)")[0]; - if (c0rotate === "90") { - changedDataLeft += "\n1$: Facing: south (Towards negative Y)"; - } else if (c0rotate === "-90") { - changedDataLeft += "\n1$: Facing: north (Towards negative Y)"; - } else if (c0rotate === "0") { - changedDataLeft += "\n1$: Facing: east (Towards positive X)"; - } else if (c0rotate === "180") { - changedDataLeft += "\n1$: Facing: west (Towards negative X)"; - } - - changedDataLeft += "\n1$: Speed: A: " + car1cspeed.toFixed(2) + " R: " + (car1speed - car1cspeed).toFixed(2) + " M: " + car1speed.toFixed(2); - - changedDataLeft += "\n1$: Laps: " + document.getElementById('laps-car1').innerText + "/5"; - changedDataLeft += "\n1$: Model: " + selectedModel1; - changedDataLeft += "\n1$: Collision: " + (car1collisionon ? "%true%" : "%false%"); - changedDataLeft += "\n" + oil(0) + oil(1) + oil(2) + oil(3) + oil(4); - changedDataLeft += "\n\nMusic: " + i; - changedDataLeft += "\nCircuit: " + rand; - - } else { - changedDataLeft = "playing: %false%" - } - - usedMem = (process.memoryUsage().heapUsed / 1000000).toFixed(2); - totalMem = (process.memoryUsage().heapTotal / 1000000).toFixed(2); - percMem = Math.round((process.memoryUsage().heapUsed / process.memoryUsage().heapTotal)*100); - allocateMem = (process.memoryUsage().rss / 1000000).toFixed(2); - - changedDataRight = "Mem: " + percMem + "% " + usedMem + "/" + totalMem + "MB" - changedDataRight += "\nAllocated: " + allocateMem + "MB" - changedDataRight += "\n\nCPU: (" + process.getCPUUsage().percentCPUUsage.toFixed(2) + "%) " + require('os').cpus().length + "x " + require('os').cpus()[0].model.trim() + " @ " + (require('os').cpus()[0].speed/1000).toFixed(2) + "GHz" - - try { - changedDataRight += "\n\nDisplay: " + window.innerWidth + "x" + window.innerHeight + " (" + gpudata.controllers[0].vendor + ")"; - changedDataRight += "\n" + gpudata.controllers[0].model; - - try { - if (gpudriverdata.gpuDevice[0].driverVendor !== undefined) { - dvendor = gpudriverdata.gpuDevice[0].driverVendor; - } else { - dvendor = "<Unknown>"; - } - if (gpudriverdata.gpuDevice[0].driverVersion !== undefined) { - dversion = gpudriverdata.gpuDevice[0].driverVersion; - } else { - dversion = "<Unknown>"; - } - } catch (e) { - dvendor = "<Unknown>"; - dversion = "<Unknown>"; - } - changedDataRight += "\n" + dvendor + " - " + dversion; - } catch (e) { - console.error(e); - } -},100); - -window.addEventListener("load", () => { - require('@electron/remote').app.getGPUInfo('complete').then((data) => { - global.gpudriverdata = data; - }); +global.debugshow = false;
+
+function oil(id) {
+ return "\nO" + id +": " + document.getElementById('oil' + id + '').style.left.split("px")[0] + " " + document.getElementById('oil' + id + '').style.top.split("px")[0] + " / " + document.getElementById('oil' + id + '').style.transform.split("rotate(")[1].split("deg)")[0];
+}
+
+$(document).keydown((e) => {
+ if (e.keyCode === 114) { // F3
+ if (debugshow) {
+ global.debugshow = false;
+ document.getElementById("debug").style.display = "none";
+ } else {
+ global.debugshow = true;
+ document.getElementById("debug").style.display = "";
+ }
+ }
+})
+
+if (require('os').platform() !== "darwin") {
+ gpuinfo = require('@electron/remote').app.getGPUFeatureStatus();
+ gpuscore = 0;
+ maxscore = 10;
+ if (gpuinfo['2d_canvas'].startsWith("enabled")) {
+ if (gpuinfo['2d_canvas'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['gpu_compositing'].startsWith("enabled")) {
+ if (gpuinfo['gpu_compositing'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['video_decode'].startsWith("enabled")) {
+ if (gpuinfo['video_decode'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['multiple_raster_threads'].startsWith("enabled")) {
+ if (gpuinfo['multiple_raster_threads'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['oop_rasterization'].startsWith("enabled")) {
+ if (gpuinfo['oop_rasterization'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['rasterization'].startsWith("enabled")) {
+ if (gpuinfo['rasterization'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['opengl'].startsWith("enabled")) {
+ if (gpuinfo['opengl'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['skia_renderer'].startsWith("enabled")) {
+ if (gpuinfo['skia_renderer'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['vulkan'].startsWith("enabled")) {
+ if (gpuinfo['vulkan'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['webgl'].startsWith("enabled")) {
+ if (gpuinfo['webgl'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+
+ gpuperct = (gpuscore/maxscore)*100;
+} else {
+ gpuperct = 100;
+}
+
+pubver = require('../package.json').version;
+pvpart = pubver.split(".");
+if (pvpart.length === 3) {
+ intver = pvpart[0] + "." + pvpart[1];
+} else {
+ intver = "unknown";
+}
+
+if (require('@electron/remote').getCurrentWindow().mods.length > 0) {
+ release = "mods+" + require('@electron/remote').getCurrentWindow().mods.length;
+} else {
+ release = "official";
+}
+
+if (gpuperct < 25) {
+ perf = "fast";
+} else if (gpuperct < 50) {
+ perf = "fancy";
+} else {
+ perf = "fabulous";
+}
+
+if (location.search === "") {
+ game = "Local multiplayer game";
+} else if (location.search === "?sp") {
+ game = "Singleplayer game";
+} else if (location.search === "?online") {
+ game = require("../online/server.json").hostname + ":" + require("../online/server.json").port;
+}
+
+tps = -1;
+cping = -1;
+changedDataLeft = "playing: %false%"
+changedDataRight = ""
+immutableDataLeft = "Kartik " + pubver + " (" + intver + "/" + require('../package.json').channel + "+" + release + ")\n%tps% tps T:" + perf + ";vsync\n" + game + " @ %ping% ms ticks";
+immutableDataRight = "Electron: " + process.versions.electron + " " + process.arch;
+
+credits = "Debug: start runtime with debug argument\nFor help: https://kartik.hopto.org"
+
+setInterval(() => {
+ if (!debugshow) { return; }
+
+
+ leftparts = (immutableDataLeft + "\n" + changedDataLeft + "\n\n" + credits).split("\n");
+ lefttext = "<span style='background:rgba(101,101,101,0.75);font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;padding:1px;'>" + leftparts.join("</span><br><span style='background:rgba(101,101,101,0.75);font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;padding:1px;'>") + "</span>";
+
+ rightparts = (immutableDataRight + "\n" + changedDataRight).split("\n");
+ righttext = "<span style='background:rgba(101,101,101,0.75);font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;padding:1px;'>" + rightparts.join("</span><br><span style='background:rgba(101,101,101,0.75);font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;padding:1px;'>") + "</span>";
+
+ document.getElementById("debug-left").innerHTML = lefttext.replaceAll("%tps%", tps).replaceAll("%ping%", cping).replaceAll("%false%", "<span style='color:red;font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;'>false</span>").replaceAll("%true%", "<span style='color:green;font-family: 'Source Code Pro', 'JetBrains Mono', 'Ubuntu Mono', 'Consolas', 'Lucida Console', 'Courier New', monospace;'>true</span>");
+ document.getElementById("debug-right").innerHTML = righttext;
+}, 100)
+
+var filterStrength = 20;
+var frameTime = 0, lastLoop = new Date, thisLoop;
+
+setInterval(() => {
+ if (!debugshow) { return; }
+
+ var thisFrameTime = (thisLoop=new Date) - lastLoop;
+ frameTime+= (thisFrameTime - frameTime) / filterStrength;
+ lastLoop = thisLoop;
+}, 50)
+
+require('systeminformation').graphics().then((data) => {
+ global.gpudata = data;
+});
+
+setInterval(() => {
+ if (!debugshow) { return; }
+
+ tps = (1000/frameTime).toFixed(1);
+
+ if (typeof ping === "number") {
+ cping = ping;
+ } else {
+ cping = 0;
+ }
+
+ if (started) {
+ changedDataLeft = "playing: %true%";
+ changedDataLeft += "\n\n0$: XY: " + document.getElementById('car0').style.left.split("px")[0] + " / " + document.getElementById('car0').style.top.split("px")[0]
+
+ c0rotate = document.getElementById('car0').style.transform.split("rotate(")[1].split("deg)")[0];
+ if (c0rotate === "90") {
+ changedDataLeft += "\n0$: Facing: south (Towards negative Y)";
+ } else if (c0rotate === "-90") {
+ changedDataLeft += "\n0$: Facing: north (Towards negative Y)";
+ } else if (c0rotate === "0") {
+ changedDataLeft += "\n0$: Facing: east (Towards positive X)";
+ } else if (c0rotate === "180") {
+ changedDataLeft += "\n0$: Facing: west (Towards negative X)";
+ }
+
+ changedDataLeft += "\n0$: Speed: A: " + car0cspeed.toFixed(2) + " R: " + (car0speed - car0cspeed).toFixed(2) + " M: " + car0speed.toFixed(2);
+
+ changedDataLeft += "\n0$: Laps: " + document.getElementById('laps-car0').innerText + "/5";
+ changedDataLeft += "\n0$: Model: " + selectedModel0;
+ changedDataLeft += "\n0$: Collision: " + (car0collisionon ? "%true%" : "%false%");
+
+ changedDataLeft += "\n\n1$: XY: " + document.getElementById('car1').style.left.split("px")[0] + " / " + document.getElementById('car1').style.top.split("px")[0]
+
+ c0rotate = document.getElementById('car1').style.transform.split("rotate(")[1].split("deg)")[0];
+ if (c0rotate === "90") {
+ changedDataLeft += "\n1$: Facing: south (Towards negative Y)";
+ } else if (c0rotate === "-90") {
+ changedDataLeft += "\n1$: Facing: north (Towards negative Y)";
+ } else if (c0rotate === "0") {
+ changedDataLeft += "\n1$: Facing: east (Towards positive X)";
+ } else if (c0rotate === "180") {
+ changedDataLeft += "\n1$: Facing: west (Towards negative X)";
+ }
+
+ changedDataLeft += "\n1$: Speed: A: " + car1cspeed.toFixed(2) + " R: " + (car1speed - car1cspeed).toFixed(2) + " M: " + car1speed.toFixed(2);
+
+ changedDataLeft += "\n1$: Laps: " + document.getElementById('laps-car1').innerText + "/5";
+ changedDataLeft += "\n1$: Model: " + selectedModel1;
+ changedDataLeft += "\n1$: Collision: " + (car1collisionon ? "%true%" : "%false%");
+ changedDataLeft += "\n" + oil(0) + oil(1) + oil(2) + oil(3) + oil(4);
+ changedDataLeft += "\n\nMusic: " + i;
+ changedDataLeft += "\nCircuit: " + rand;
+
+ } else {
+ changedDataLeft = "playing: %false%"
+ }
+
+ usedMem = (process.memoryUsage().heapUsed / 1000000).toFixed(2);
+ totalMem = (process.memoryUsage().heapTotal / 1000000).toFixed(2);
+ percMem = Math.round((process.memoryUsage().heapUsed / process.memoryUsage().heapTotal)*100);
+ allocateMem = (process.memoryUsage().rss / 1000000).toFixed(2);
+
+ changedDataRight = "Mem: " + percMem + "% " + usedMem + "/" + totalMem + "MB"
+ changedDataRight += "\nAllocated: " + allocateMem + "MB"
+ changedDataRight += "\n\nCPU: (" + process.getCPUUsage().percentCPUUsage.toFixed(2) + "%) " + require('os').cpus().length + "x " + require('os').cpus()[0].model.trim() + " @ " + (require('os').cpus()[0].speed/1000).toFixed(2) + "GHz"
+
+ try {
+ changedDataRight += "\n\nDisplay: " + window.innerWidth + "x" + window.innerHeight + " (" + gpudata.controllers[0].vendor + ")";
+ changedDataRight += "\n" + gpudata.controllers[0].model;
+
+ try {
+ if (gpudriverdata.gpuDevice[0].driverVendor !== undefined) {
+ dvendor = gpudriverdata.gpuDevice[0].driverVendor;
+ } else {
+ dvendor = "<Unknown>";
+ }
+ if (gpudriverdata.gpuDevice[0].driverVersion !== undefined) {
+ dversion = gpudriverdata.gpuDevice[0].driverVersion;
+ } else {
+ dversion = "<Unknown>";
+ }
+ } catch (e) {
+ dvendor = "<Unknown>";
+ dversion = "<Unknown>";
+ }
+ changedDataRight += "\n" + dvendor + " - " + dversion;
+ } catch (e) {
+ console.error(e);
+ }
+},100);
+
+window.addEventListener("load", () => {
+ require('@electron/remote').app.getGPUInfo('complete').then((data) => {
+ global.gpudriverdata = data;
+ });
})
\ No newline at end of file diff --git a/views/script/global_compatlayer.js b/views/script/global_compatlayer.js index 7431cea..9ef86ed 100644 --- a/views/script/global_compatlayer.js +++ b/views/script/global_compatlayer.js @@ -1,89 +1,89 @@ -window.addEventListener("load", () => { - if (require('os').platform !== "darwin") { - gpuinfo = require('@electron/remote').app.getGPUFeatureStatus(); - gpuscore = 0; - maxscore = 10; - if (gpuinfo['2d_canvas'].startsWith("enabled")) { - if (gpuinfo['2d_canvas'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['gpu_compositing'].startsWith("enabled")) { - if (gpuinfo['gpu_compositing'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['video_decode'].startsWith("enabled")) { - if (gpuinfo['video_decode'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['multiple_raster_threads'].startsWith("enabled")) { - if (gpuinfo['multiple_raster_threads'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['oop_rasterization'].startsWith("enabled")) { - if (gpuinfo['oop_rasterization'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['rasterization'].startsWith("enabled")) { - if (gpuinfo['rasterization'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['opengl'].startsWith("enabled")) { - if (gpuinfo['opengl'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['skia_renderer'].startsWith("enabled")) { - if (gpuinfo['skia_renderer'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['vulkan'].startsWith("enabled")) { - if (gpuinfo['vulkan'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - if (gpuinfo['webgl'].startsWith("enabled")) { - if (gpuinfo['webgl'] === "enabled") { - gpuscore++; - } else { - gpuscore += 0.5; - } - } - - gpuperct = (gpuscore / maxscore) * 100; - - if (gpuperct < 30) { - console.warn("Bad GPU support, disabling GPU-accelerated content"); - var head = document.getElementsByTagName('HEAD')[0]; - var link = document.createElement('link'); - link.rel = 'stylesheet'; - link.type = 'text/css'; - link.href = './common/compatibilityMode.css'; - head.appendChild(link); - } - } -}) +window.addEventListener("load", () => {
+ if (require('os').platform !== "darwin") {
+ gpuinfo = require('@electron/remote').app.getGPUFeatureStatus();
+ gpuscore = 0;
+ maxscore = 10;
+ if (gpuinfo['2d_canvas'].startsWith("enabled")) {
+ if (gpuinfo['2d_canvas'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['gpu_compositing'].startsWith("enabled")) {
+ if (gpuinfo['gpu_compositing'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['video_decode'].startsWith("enabled")) {
+ if (gpuinfo['video_decode'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['multiple_raster_threads'].startsWith("enabled")) {
+ if (gpuinfo['multiple_raster_threads'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['oop_rasterization'].startsWith("enabled")) {
+ if (gpuinfo['oop_rasterization'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['rasterization'].startsWith("enabled")) {
+ if (gpuinfo['rasterization'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['opengl'].startsWith("enabled")) {
+ if (gpuinfo['opengl'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['skia_renderer'].startsWith("enabled")) {
+ if (gpuinfo['skia_renderer'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['vulkan'].startsWith("enabled")) {
+ if (gpuinfo['vulkan'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+ if (gpuinfo['webgl'].startsWith("enabled")) {
+ if (gpuinfo['webgl'] === "enabled") {
+ gpuscore++;
+ } else {
+ gpuscore += 0.5;
+ }
+ }
+
+ gpuperct = (gpuscore / maxscore) * 100;
+
+ if (gpuperct < 30) {
+ console.warn("Bad GPU support, disabling GPU-accelerated content");
+ var head = document.getElementsByTagName('HEAD')[0];
+ var link = document.createElement('link');
+ link.rel = 'stylesheet';
+ link.type = 'text/css';
+ link.href = './common/compatibilityMode.css';
+ head.appendChild(link);
+ }
+ }
+})
diff --git a/views/script/global_levelsapi.js b/views/script/global_levelsapi.js index ebd969d..45a74d2 100644 --- a/views/script/global_levelsapi.js +++ b/views/script/global_levelsapi.js @@ -1,47 +1,47 @@ -module.exports = class LevelsAPI { - - associates; - - constructor() { - - let assocs_raw; - let assocs_lines; - let assocs_base; - let assocs; - let score; - let cline; - let line; - let clvl; - - assocs_raw = require('fs').readFileSync("./online/levels.txt"); - assocs_lines = assocs_raw.toString().split("\n"); - assocs_base = {}; - - for (line of assocs_lines) { - cline = line.split(":"); - assocs_base[cline[1].trim()] = cline[0].trim() - 1 + 1; - } - - assocs = {}; - - clvl = 0; - for (let c = 0; c <= 5051; c++) { - if (assocs_base[c.toString()] !== undefined) { - clvl = assocs_base[c.toString()]; - } - assocs[c.toString()] = clvl.toString() - } - - this.associates = assocs; - - } - - correspond(score, god) { - if (score <= 5051) { - return this.associates[score].toString(); - } else { - return god; - } - } - +module.exports = class LevelsAPI {
+
+ associates;
+
+ constructor() {
+
+ let assocs_raw;
+ let assocs_lines;
+ let assocs_base;
+ let assocs;
+ let score;
+ let cline;
+ let line;
+ let clvl;
+
+ assocs_raw = require('fs').readFileSync("./online/levels.txt");
+ assocs_lines = assocs_raw.toString().split("\n");
+ assocs_base = {};
+
+ for (line of assocs_lines) {
+ cline = line.split(":");
+ assocs_base[cline[1].trim()] = cline[0].trim() - 1 + 1;
+ }
+
+ assocs = {};
+
+ clvl = 0;
+ for (let c = 0; c <= 5051; c++) {
+ if (assocs_base[c.toString()] !== undefined) {
+ clvl = assocs_base[c.toString()];
+ }
+ assocs[c.toString()] = clvl.toString()
+ }
+
+ this.associates = assocs;
+
+ }
+
+ correspond(score, god) {
+ if (score <= 5051) {
+ return this.associates[score].toString();
+ } else {
+ return god;
+ }
+ }
+
}
\ No newline at end of file diff --git a/views/script/loader_global.js b/views/script/loader_global.js index 7543268..3a35d54 100644 --- a/views/script/loader_global.js +++ b/views/script/loader_global.js @@ -1,127 +1,127 @@ -window.addEventListener('load', () => { - setTimeout(() => { - if (native) { - setTimeout(() => { - setTimeout(() => { - - $("#progress").fadeOut(500); - setTimeout(() => { - window.fetch("https://kartik.hopto.org/latest.php?v=" + require('@electron/remote').getCurrentWindow().update).then((data) => { - data.blob().then((a) => { - a.text().then((b) => { - if (require('@electron/remote').getCurrentWindow().update === "git") { - document.getElementById('updates').style.backgroundColor = "lightsalmon"; - document.getElementById('updates').innerText = lang.updates.git; - } else { - console.log(b); - console.log(require('../package.json').version); - if (b === require('../package.json').version) { - document.getElementById('updates').style.backgroundColor = "lightgreen"; - document.getElementById('updates').innerText = lang.updates.ok; - } else { - require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.updates.warn[0], message: lang.updates.warn[1]}); - document.getElementById('updates').style.backgroundColor = "lightyellow"; - document.getElementById('updates').innerText = lang.updates.available; - } - } - setTimeout(() => { - $("#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); - 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); - 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); - setTimeout(() => { - info("LoadWindow", "Switching control to MenuWindow"); - location.href = "intro.html"; - }, 1000) - } - }, 200) - }, 2000) - }); - }, 2000) - }, 3000) - }, 1000) - } else { - - setTimeout(() => { - $("#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) -}) +window.addEventListener('load', () => {
+ setTimeout(() => {
+ if (native) {
+ setTimeout(() => {
+ setTimeout(() => {
+
+ $("#progress").fadeOut(500);
+ setTimeout(() => {
+ window.fetch("https://kartik.hopto.org/latest.php?v=" + require('@electron/remote').getCurrentWindow().update).then((data) => {
+ data.blob().then((a) => {
+ a.text().then((b) => {
+ if (require('@electron/remote').getCurrentWindow().update === "git") {
+ document.getElementById('updates').style.backgroundColor = "lightsalmon";
+ document.getElementById('updates').innerText = lang.updates.git;
+ } else {
+ console.log(b);
+ console.log(require('../package.json').version);
+ if (b === require('../package.json').version) {
+ document.getElementById('updates').style.backgroundColor = "lightgreen";
+ document.getElementById('updates').innerText = lang.updates.ok;
+ } else {
+ require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.updates.warn[0], message: lang.updates.warn[1]});
+ document.getElementById('updates').style.backgroundColor = "lightyellow";
+ document.getElementById('updates').innerText = lang.updates.available;
+ }
+ }
+ setTimeout(() => {
+ $("#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);
+ 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);
+ 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);
+ setTimeout(() => {
+ info("LoadWindow", "Switching control to MenuWindow");
+ location.href = "intro.html";
+ }, 1000)
+ }
+ }, 200)
+ }, 2000)
+ });
+ }, 2000)
+ }, 3000)
+ }, 1000)
+ } else {
+
+ setTimeout(() => {
+ $("#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 2b38844..49ed8a5 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"); -} else { - document.write("2021-" + new Date().getFullYear() + " Minteck"); +if (new Date().getFullYear() === 2021) {
+ document.write(new Date().getFullYear() + " Minteck");
+} else {
+ 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 14a924f..a16d3d1 100644 --- a/views/script/menu_global.js +++ b/views/script/menu_global.js @@ -1,127 +1,127 @@ -let menuOpen = true; - -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);} -$("#box").fadeOut(0); -window.addEventListener('load', () => { - setTimeout(() => { - $("#box").fadeIn(500); - }, 1000) -}) - -$("body").focus(); -keysEnabled = true; -$(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(); - } else { - $(".services").show(); - } - menuOpen = !menuOpen; - } - if (e.keyCode === 38 || e.keyCode === 90) { // up - Sound.menu(); - var selected = $(".selected"); - $(".services li").removeClass("selected"); - if (selected.prev().length === 0) { - selected.siblings().last().addClass("selected"); - } else { - selected.prev().addClass("selected"); - } - } - if (e.keyCode === 40 || e.keyCode === 83) { // down - Sound.menu(); - var selected = $(".selected"); - $(".services li").removeClass("selected"); - if (selected.next().length === 0) { - selected.siblings().first().addClass("selected"); - } else { - selected.next().addClass("selected"); - } - } - if (e.keyCode === 27 || e.keyCode === 8) { // esc - keysEnabled = false; - Sound.click(); - setTimeout(() => { - require('@electron/remote').getCurrentWindow().close(); - }, 250) - } - } -}); - -function selectOption() { - item = document.querySelector(".selected a").id; - Sound.click(); - - switch (item) { - case 'single': - scenar("start", "happy"); - keysEnabled = false; - require('electron').ipcRenderer.send('prefademusic', ""); - $("#box").fadeOut(500); - setTimeout(() => { - info("MenuWindow", "Switching control to GameWindow"); - location.href = "game.html?sp"; - }, 1000) - break; - case 'online': - keysEnabled = false; - require('electron').ipcRenderer.send('prefademusic', ""); - $("#box").fadeOut(500); - setTimeout(() => { - info("MenuWindow", "Switching control to GameWindow"); - location.href = "game.html?online"; - }, 1000) - break; - case 'play': - keysEnabled = false; - require('electron').ipcRenderer.send('prefademusic', ""); - $("#box").fadeOut(500); - setTimeout(() => { - info("MenuWindow", "Switching control to GameWindow"); - location.href = "game.html"; - }, 1000) - break; - case 'settings': - keysEnabled = false; - $("#box").fadeOut(500); - setTimeout(() => { - info("MenuWindow", "Switching control to OptnWindow"); - location.href = "settings.html"; - }, 1000) - break; - case 'stats': - keysEnabled = false; - require('electron').ipcRenderer.send('prefademusic', ""); - $("#box").fadeOut(500); - setTimeout(() => { - info("MenuWindow", "Switching control to OptnWindow"); - location.href = "stats.html"; - }, 1000) - break; - case 'credits': - keysEnabled = false; - require('electron').ipcRenderer.send('prefademusic', ""); - $("#box").fadeOut(500); - setTimeout(() => { - info("MenuWindow", "Switching control to OptnWindow"); - location.href = "credits.html"; - }, 1000) - break; - case 'quit': - keysEnabled = false; - require('electron').ipcRenderer.send('prefademusic', ""); - info("MenuWindow", "Quitting game"); - Sound.click(); - setTimeout(() => { - require('@electron/remote').getCurrentWindow().close(); - }, 250) - break; - } +let menuOpen = true;
+
+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);}
+$("#box").fadeOut(0);
+window.addEventListener('load', () => {
+ setTimeout(() => {
+ $("#box").fadeIn(500);
+ }, 1000)
+})
+
+$("body").focus();
+keysEnabled = true;
+$(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();
+ } else {
+ $(".services").show();
+ }
+ menuOpen = !menuOpen;
+ }
+ if (e.keyCode === 38 || e.keyCode === 90) { // up
+ Sound.menu();
+ var selected = $(".selected");
+ $(".services li").removeClass("selected");
+ if (selected.prev().length === 0) {
+ selected.siblings().last().addClass("selected");
+ } else {
+ selected.prev().addClass("selected");
+ }
+ }
+ if (e.keyCode === 40 || e.keyCode === 83) { // down
+ Sound.menu();
+ var selected = $(".selected");
+ $(".services li").removeClass("selected");
+ if (selected.next().length === 0) {
+ selected.siblings().first().addClass("selected");
+ } else {
+ selected.next().addClass("selected");
+ }
+ }
+ if (e.keyCode === 27 || e.keyCode === 8) { // esc
+ keysEnabled = false;
+ Sound.click();
+ setTimeout(() => {
+ require('@electron/remote').getCurrentWindow().close();
+ }, 250)
+ }
+ }
+});
+
+function selectOption() {
+ item = document.querySelector(".selected a").id;
+ Sound.click();
+
+ switch (item) {
+ case 'single':
+ scenar("start", "happy");
+ keysEnabled = false;
+ require('electron').ipcRenderer.send('prefademusic', "");
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ info("MenuWindow", "Switching control to GameWindow");
+ location.href = "game.html?sp";
+ }, 1000)
+ break;
+ case 'online':
+ keysEnabled = false;
+ require('electron').ipcRenderer.send('prefademusic', "");
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ info("MenuWindow", "Switching control to GameWindow");
+ location.href = "game.html?online";
+ }, 1000)
+ break;
+ case 'play':
+ keysEnabled = false;
+ require('electron').ipcRenderer.send('prefademusic', "");
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ info("MenuWindow", "Switching control to GameWindow");
+ location.href = "game.html";
+ }, 1000)
+ break;
+ case 'settings':
+ keysEnabled = false;
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ info("MenuWindow", "Switching control to OptnWindow");
+ location.href = "settings.html";
+ }, 1000)
+ break;
+ case 'stats':
+ keysEnabled = false;
+ require('electron').ipcRenderer.send('prefademusic', "");
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ info("MenuWindow", "Switching control to OptnWindow");
+ location.href = "stats.html";
+ }, 1000)
+ break;
+ case 'credits':
+ keysEnabled = false;
+ require('electron').ipcRenderer.send('prefademusic', "");
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ info("MenuWindow", "Switching control to OptnWindow");
+ location.href = "credits.html";
+ }, 1000)
+ break;
+ case 'quit':
+ keysEnabled = false;
+ require('electron').ipcRenderer.send('prefademusic', "");
+ info("MenuWindow", "Quitting game");
+ Sound.click();
+ setTimeout(() => {
+ require('@electron/remote').getCurrentWindow().close();
+ }, 250)
+ break;
+ }
}
\ No newline at end of file diff --git a/views/script/menu_login.js b/views/script/menu_login.js index 2af88b2..f2d7c7e 100644 --- a/views/script/menu_login.js +++ b/views/script/menu_login.js @@ -1,209 +1,242 @@ -global.loggingIn = false; -homedir = require('@electron/remote').getCurrentWindow().homedir; - -function startLogin() { - loggingIn = true; - - document.getElementById('loggingIn').style.display = "flex"; - var http = require('http'); - - reqid = 0; - - var server = http.createServer(function (req, res) { - - const queryObject = require('querystring').parse(req.url,true); - token = queryObject[Object.keys(queryObject)[0]]; - res.end(lang.polymer.loginClose); - reqid++; - - if (reqid === 1) { - document.getElementById("loggingIn").innerText = lang.polymer.gatheringLogin - require('@electron/remote').getCurrentWindow().focus(); - server.close(); - - playerData = { - "picture": null, - "name": null, - "level": -1, - "token": token - }; - - playerData.picture = $.ajax({ - type: "GET", - url: 'https://kartik.hopto.org/online/ingame/api/profile.picture.php?kartik_online_token=' + token, - async: false, - error: (e) => { throw e; } - }).responseText.trim(); - - playerData.name = $.ajax({ - type: "GET", - url: 'https://kartik.hopto.org/online/ingame/api/profile.name.php?kartik_online_token=' + token, - async: false, - error: (e) => { throw e; } - }).responseText.trim(); - - playerData.level = $.ajax({ - type: "GET", - url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + token, - async: false, - error: (e) => { throw e; } - }).responseText.trim() - 1 + 1; - - if (playerData.level >= 0 && playerData.name !== null && playerData.picture !== null) { - console.log(playerData); - loggingIn = false; - document.getElementById('loggingIn').style.display = "none"; - currentNest.auth = playerData; - Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") - keysEnabled = false; - require('electron').ipcRenderer.send('prefademusic', ""); - $("#box").fadeOut(500); - setTimeout(() => { - location.href = "menu.html"; - }, 1000) - } else { - throw new Error("Incomplete information received"); - } - } - - }); - - server.listen(14552); - - console.log('Waiting for login requests on port 14552') - require('open')("https://kartik.hopto.org/online/ingame"); -} - -window.addEventListener('load', () => { - onlineMode = false; - - window.fetch("https://kartik.hopto.org/latest.php?v=" + require('@electron/remote').getCurrentWindow().update).then((data) => { - data.blob().then((a) => { - a.text().then((b) => { - onlineMode = true; - postOnlineMode(); - }).catch((e) => { - require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]}); - console.error(e); - onlineMode = false; - postOnlineMode(); - document.getElementById("loginIntro").innerText = lang.polymer.error[2]; - document.getElementById("online").parentElement.parentElement.outerHTML = ""; - }) - }).catch((e) => { - require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]}); - console.error(e); - onlineMode = false; - postOnlineMode(); - document.getElementById("loginIntro").innerText = lang.polymer.error[2]; - document.getElementById("online").parentElement.parentElement.outerHTML = ""; - }) - }).catch((e) => { - require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]}); - console.error(e); - onlineMode = false; - postOnlineMode(); - document.getElementById("loginIntro").innerText = lang.polymer.error[2]; - document.getElementById("online").parentElement.parentElement.outerHTML = ""; - }) -}) - -function postOnlineMode() { - 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") - } - - 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()) - - 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]; - } - } - } - } - - $.ajax({ - type: "GET", - 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; } - }); - - currentNest.stats = 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()); - 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; - } - } - } 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 = ""; - } +global.loggingIn = false;
+homedir = require('@electron/remote').getCurrentWindow().homedir;
+
+function startLogin() {
+ loggingIn = true;
+
+ document.getElementById('loggingIn').style.display = "flex";
+ var http = require('http');
+
+ reqid = 0;
+
+ var server = http.createServer(function (req, res) {
+
+ const queryObject = require('querystring').parse(req.url,true);
+ token = queryObject[Object.keys(queryObject)[0]];
+ res.end(lang.polymer.loginClose);
+ reqid++;
+
+ if (reqid === 1) {
+ document.getElementById("loggingIn").innerText = lang.polymer.gatheringLogin
+ require('@electron/remote').getCurrentWindow().focus();
+ server.close();
+
+ playerData = {
+ "picture": null,
+ "name": null,
+ "level": -1,
+ "token": token
+ };
+
+ playerData.picture = $.ajax({
+ type: "GET",
+ url: 'https://kartik.hopto.org/online/ingame/api/profile.picture.php?kartik_online_token=' + token,
+ async: false,
+ error: (e) => { throw e; }
+ }).responseText.trim();
+
+ playerData.name = $.ajax({
+ type: "GET",
+ url: 'https://kartik.hopto.org/online/ingame/api/profile.name.php?kartik_online_token=' + token,
+ async: false,
+ error: (e) => { throw e; }
+ }).responseText.trim();
+
+ playerData.level = $.ajax({
+ type: "GET",
+ url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + token,
+ async: false,
+ error: (e) => { throw e; }
+ }).responseText.trim() - 1 + 1;
+
+ if (playerData.level >= 0 && playerData.name !== null && playerData.picture !== null) {
+ console.log(playerData);
+ loggingIn = false;
+ document.getElementById('loggingIn').style.display = "none";
+ currentNest.auth = playerData;
+ Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest")
+ keysEnabled = false;
+ require('electron').ipcRenderer.send('prefademusic', "");
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ location.href = "menu.html";
+ }, 1000)
+ } else {
+ throw new Error("Incomplete information received");
+ }
+ }
+
+ });
+
+ server.listen(14552);
+
+ console.log('Waiting for login requests on port 14552')
+ require('open')("https://kartik.hopto.org/online/ingame");
+}
+
+window.addEventListener('load', () => {
+ onlineMode = false;
+
+ window.fetch("https://kartik.hopto.org/latest.php?v=" + require('@electron/remote').getCurrentWindow().update).then((data) => {
+ data.blob().then((a) => {
+ a.text().then((b) => {
+ onlineMode = true;
+ postOnlineMode();
+ }).catch((e) => {
+ require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]});
+ console.error(e);
+ onlineMode = false;
+ postOnlineMode();
+ document.getElementById("loginIntro").innerText = lang.polymer.error[2];
+ document.getElementById("online").parentElement.parentElement.outerHTML = "";
+ })
+ }).catch((e) => {
+ require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]});
+ console.error(e);
+ onlineMode = false;
+ postOnlineMode();
+ document.getElementById("loginIntro").innerText = lang.polymer.error[2];
+ document.getElementById("online").parentElement.parentElement.outerHTML = "";
+ })
+ }).catch((e) => {
+ require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]});
+ console.error(e);
+ onlineMode = false;
+ postOnlineMode();
+ document.getElementById("loginIntro").innerText = lang.polymer.error[2];
+ document.getElementById("online").parentElement.parentElement.outerHTML = "";
+ })
+})
+
+function logout() {
+ $.ajax({
+ type: "GET",
+ url: 'https://kartik.hopto.org/online/ingame/api/profile.logout.php?kartik_online_token=' + currentNest.auth.token,
+ async: false,
+ error: (e) => { throw e; }
+ }).responseText.trim();
+ currentNest.auth = null;
+ Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest")
+}
+
+function postOnlineMode() {
+ try {
+ if (currentNest.auth !== null) {
+ console.log(currentNest.auth);
+ tokenvalidity = $.ajax({
+ type: "GET",
+ url: 'https://kartik.hopto.org/online/ingame/api/profile.token.php?kartik_online_token=' + currentNest.auth.token,
+ async: false,
+ error: (e) => { throw e; }
+ }).responseText.trim();
+
+ if (tokenvalidity !== "true") {
+ require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.token[0], message: lang.polymer.token[1]});
+ logout();
+ }
+ }
+
+ if (currentNest.auth === null || !onlineMode) {
+ $(document).keydown(function(e) {
+ if (e.keyCode === 76 && !loggingIn && onlineMode) {
+ startLogin();
+ }
+ })
+ } else {
+ $(document).keydown(function(e) {
+ if (e.keyCode === 76 && !loggingIn && onlineMode) {
+ logout();
+ location.reload();
+ }
+ })
+
+ 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")
+ }
+
+ 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())
+
+ 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];
+ }
+ }
+ }
+ }
+
+ $.ajax({
+ type: "GET",
+ 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; }
+ });
+
+ currentNest.stats = 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());
+ 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;
+ }
+ }
+ } 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 90f1f6e..047967a 100644 --- a/views/script/settings_global.js +++ b/views/script/settings_global.js @@ -1,127 +1,127 @@ -let menuOpen = true; - -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);} -$("#box").fadeOut(0); -setTimeout(() => { - $("#box").fadeIn(500); -}, 200) - -$("body").focus(); -keysEnabled = true; -$(document).keydown(function(e) { - if (keysEnabled) { - if (e.keyCode === 13 || e.keyCode === 88 || e.keyCode === 32) { // enter - if ($(".services").is(":visible")) { - selectOption(); - } else { - $(".services").show(); - } - } - if (e.keyCode === 38 || e.keyCode === 90) { // up - Sound.menu(); - var selected = $(".selected"); - $(".services li").removeClass("selected"); - if (selected.prev().length === 0) { - selected.siblings().last().addClass("selected"); - } else { - selected.prev().addClass("selected"); - } - } - if (e.keyCode === 40 || e.keyCode === 83) { // down - Sound.menu(); - var selected = $(".selected"); - $(".services li").removeClass("selected"); - if (selected.next().length === 0) { - selected.siblings().first().addClass("selected"); - } else { - selected.next().addClass("selected"); - } - } - if (e.keyCode === 68 || e.keyCode === 39 || e.keyCode === 81 || e.keyCode === 37) { // right/left - Sound.menu(); - var selected = $(".selected"); - var id = $(".selected")[0].children[0].children[0].id; - - if (id === "musicb") { - if (document.getElementById("setting-music").innerText === "1") { - document.getElementById("setting-music").innerText = "0"; - currentNest.config.music = false; - 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);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);require('electron').ipcRenderer.send("reloadNest") - } else { - document.getElementById("setting-voice").innerText = "1"; - currentNest.config.music = true; - Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") - } - } - if (id === "lang") { - lang = document.getElementById("setting-lang").innerText; - slng = require('../lang/languages.json'); - slst = Object.keys(slng); - maxl = slst.length - 1; - - ci = -1; - ni = -1; - slst.forEach((key, index) => { - if (slng[key] === lang) { - ci = index; - if (index + 1 > maxl) { - ni = 0; - } else { - ni = index + 1; - } - } - }) - - 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);require('electron').ipcRenderer.send("reloadNest") - require('@electron/remote').getCurrentWindow().lp = slst[ni]; - } - } - } - if (e.keyCode === 27 || e.keyCode === 8) { // esc - keysEnabled = false; - Sound.click(); - $("#box").fadeOut(500); - setTimeout(() => { - info("OptnWindow", "Switching control to MenuWindow"); - location.href = "menu.html"; - }, 1000) - } - } -}); - -function selectOption() { - item = document.querySelector(".selected a").id; - Sound.click(); - - switch (item) { - case 'back': - $("#box").fadeOut(500); - setTimeout(() => { - info("OptnWindow", "Switching control to MenuWindow"); - location.href = "menu.html?noreset"; - }, 1000) - break; - case 'credits': - require('electron').ipcRenderer.send('prefademusic', ""); - $("#box").fadeOut(500); - setTimeout(() => { - info("OptnWindow", "Switching control to MenuWindow"); - location.href = "credits.html"; - }, 1000) - break; - } -} +let menuOpen = true;
+
+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);}
+$("#box").fadeOut(0);
+setTimeout(() => {
+ $("#box").fadeIn(500);
+}, 200)
+
+$("body").focus();
+keysEnabled = true;
+$(document).keydown(function(e) {
+ if (keysEnabled) {
+ if (e.keyCode === 13 || e.keyCode === 88 || e.keyCode === 32) { // enter
+ if ($(".services").is(":visible")) {
+ selectOption();
+ } else {
+ $(".services").show();
+ }
+ }
+ if (e.keyCode === 38 || e.keyCode === 90) { // up
+ Sound.menu();
+ var selected = $(".selected");
+ $(".services li").removeClass("selected");
+ if (selected.prev().length === 0) {
+ selected.siblings().last().addClass("selected");
+ } else {
+ selected.prev().addClass("selected");
+ }
+ }
+ if (e.keyCode === 40 || e.keyCode === 83) { // down
+ Sound.menu();
+ var selected = $(".selected");
+ $(".services li").removeClass("selected");
+ if (selected.next().length === 0) {
+ selected.siblings().first().addClass("selected");
+ } else {
+ selected.next().addClass("selected");
+ }
+ }
+ if (e.keyCode === 68 || e.keyCode === 39 || e.keyCode === 81 || e.keyCode === 37) { // right/left
+ Sound.menu();
+ var selected = $(".selected");
+ var id = $(".selected")[0].children[0].children[0].id;
+
+ if (id === "musicb") {
+ if (document.getElementById("setting-music").innerText === "1") {
+ document.getElementById("setting-music").innerText = "0";
+ currentNest.config.music = false;
+ 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);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);require('electron').ipcRenderer.send("reloadNest")
+ } else {
+ document.getElementById("setting-voice").innerText = "1";
+ currentNest.config.music = true;
+ Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest")
+ }
+ }
+ if (id === "lang") {
+ lang = document.getElementById("setting-lang").innerText;
+ slng = require('../lang/languages.json');
+ slst = Object.keys(slng);
+ maxl = slst.length - 1;
+
+ ci = -1;
+ ni = -1;
+ slst.forEach((key, index) => {
+ if (slng[key] === lang) {
+ ci = index;
+ if (index + 1 > maxl) {
+ ni = 0;
+ } else {
+ ni = index + 1;
+ }
+ }
+ })
+
+ 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);require('electron').ipcRenderer.send("reloadNest")
+ require('@electron/remote').getCurrentWindow().lp = slst[ni];
+ }
+ }
+ }
+ if (e.keyCode === 27 || e.keyCode === 8) { // esc
+ keysEnabled = false;
+ Sound.click();
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ info("OptnWindow", "Switching control to MenuWindow");
+ location.href = "menu.html";
+ }, 1000)
+ }
+ }
+});
+
+function selectOption() {
+ item = document.querySelector(".selected a").id;
+ Sound.click();
+
+ switch (item) {
+ case 'back':
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ info("OptnWindow", "Switching control to MenuWindow");
+ location.href = "menu.html?noreset";
+ }, 1000)
+ break;
+ case 'credits':
+ require('electron').ipcRenderer.send('prefademusic', "");
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ info("OptnWindow", "Switching control to MenuWindow");
+ location.href = "credits.html";
+ }, 1000)
+ break;
+ }
+}
diff --git a/views/script/settings_load.js b/views/script/settings_load.js index b15b125..e2bad80 100644 --- a/views/script/settings_load.js +++ b/views/script/settings_load.js @@ -1,25 +1,25 @@ -info("OptnWindow", "Restoring settings..."); - -if (require('@electron/remote').getCurrentWindow().music) { - if (location.search === "?credits") { - require('electron').ipcRenderer.send('newmusic', kresources.music['title'].file); - } - document.getElementById("setting-music").innerText = "1"; -} else { - document.getElementById("setting-music").innerText = "0"; -} - -if (currentNest.config.voice === true) { - document.getElementById("setting-voice").innerText = "1"; -} else { - document.getElementById("setting-voice").innerText = "0"; -} - -slang = require('@electron/remote').getCurrentWindow().lp; -langs = require('../lang/languages.json'); - -if (Object.keys(langs).includes(slang)) { - document.getElementById("setting-lang").innerText = langs[slang]; -} else { - document.getElementById("setting-lang").innerText = slang; -} +info("OptnWindow", "Restoring settings...");
+
+if (require('@electron/remote').getCurrentWindow().music) {
+ if (location.search === "?credits") {
+ require('electron').ipcRenderer.send('newmusic', kresources.music['title'].file);
+ }
+ document.getElementById("setting-music").innerText = "1";
+} else {
+ document.getElementById("setting-music").innerText = "0";
+}
+
+if (currentNest.config.voice === true) {
+ document.getElementById("setting-voice").innerText = "1";
+} else {
+ document.getElementById("setting-voice").innerText = "0";
+}
+
+slang = require('@electron/remote').getCurrentWindow().lp;
+langs = require('../lang/languages.json');
+
+if (Object.keys(langs).includes(slang)) {
+ document.getElementById("setting-lang").innerText = langs[slang];
+} else {
+ document.getElementById("setting-lang").innerText = slang;
+}
|