aboutsummaryrefslogtreecommitdiff
path: root/views/script
diff options
context:
space:
mode:
Diffstat (limited to 'views/script')
-rw-r--r--views/script/core_chart.js8
-rw-r--r--views/script/core_compatlayer.js178
-rw-r--r--views/script/core_crash.js21
-rw-r--r--views/script/core_fullscreen.js43
-rw-r--r--views/script/core_notification.js13
-rw-r--r--views/script/core_stats.js122
-rw-r--r--views/script/core_viewer.js42
-rw-r--r--views/script/game_debug.js522
-rw-r--r--views/script/global_compatlayer.js178
-rw-r--r--views/script/global_levelsapi.js47
-rw-r--r--views/script/loader_global.js246
-rw-r--r--views/script/menu_copyright.js8
-rw-r--r--views/script/menu_global.js247
-rw-r--r--views/script/menu_login.js242
-rw-r--r--views/script/settings_global.js353
-rw-r--r--views/script/settings_load.js50
16 files changed, 1288 insertions, 1032 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_compatlayer.js b/views/script/core_compatlayer.js
index 206aa28..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 < 50) {
- 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);
- }
- }
-}) \ No newline at end of file
+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
new file mode 100644
index 0000000..1a12230
--- /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_notification.js b/views/script/core_notification.js
new file mode 100644
index 0000000..676b2d0
--- /dev/null
+++ b/views/script/core_notification.js
@@ -0,0 +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)
+}); \ No newline at end of file
diff --git a/views/script/core_stats.js b/views/script/core_stats.js
index a49851d..124f5fe 100644
--- a/views/script/core_stats.js
+++ b/views/script/core_stats.js
@@ -1,73 +1,51 @@
-const fs = require('fs');
-const homedir = require('@electron/remote').getCurrentWindow().homedir;
-const defaultStats = {
- times: {
- single: 0,
- local: 0,
- online: 0
- },
- results: {
- wins: 0,
- loses: 0
- },
- ingame: {
- walls: 0,
- laps: 0,
- turns: 0
- }
-}
-
-if (!fs.existsSync(homedir + "/.kartik/stats.json")) {
- fs.writeFileSync(homedir + "/.kartik/stats.json", JSON.stringify(defaultStats));
-} else {
- try {
- JSON.parse(fs.readFileSync(homedir + "/.kartik/stats.json").toString());
- } catch (e) {
- fs.writeFileSync(homedir + "/.kartik/stats.json", JSON.stringify(defaultStats));
- }
-}
-
-session = null;
-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) });
-
- 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();
- }
-})
-
-window.addEventListener("beforeunload", function(e){
- 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;
- }
+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/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/game_debug.js b/views/script/game_debug.js
index edcdc26..dee421b 100644
--- a/views/script/game_debug.js
+++ b/views/script/game_debug.js
@@ -1,261 +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: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, monospace;padding:1px;'>" + leftparts.join("</span><br><span style='background:rgba(101,101,101,0.75);font-family: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, monospace;padding:1px;'>") + "</span>";
-
- rightparts = (immutableDataRight + "\n" + changedDataRight).split("\n");
- righttext = "<span style='background:rgba(101,101,101,0.75);font-family: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, monospace;padding:1px;'>" + rightparts.join("</span><br><span style='background:rgba(101,101,101,0.75);font-family: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, monospace;padding:1px;'>") + "</span>";
-
- document.getElementById("debug-left").innerHTML = lefttext.replaceAll("%tps%", tps).replaceAll("%ping%", cping).replaceAll("%false%", "<span style='color:red;font-family: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, monospace;'>false</span>").replaceAll("%true%", "<span style='color:green;font-family: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, 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 += "\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 += "\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 = "&lt;Unknown&gt;";
- }
- if (gpudriverdata.gpuDevice[0].driverVersion !== undefined) {
- dversion = gpudriverdata.gpuDevice[0].driverVersion;
- } else {
- dversion = "&lt;Unknown&gt;";
- }
- } catch (e) {
- dvendor = "&lt;Unknown&gt;";
- dversion = "&lt;Unknown&gt;";
- }
- changedDataRight += "\n" + dvendor + " - " + dversion;
- } catch (e) {
- console.error(e);
- }
-},1000);
-
-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: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, monospace;padding:1px;'>" + leftparts.join("</span><br><span style='background:rgba(101,101,101,0.75);font-family: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, monospace;padding:1px;'>") + "</span>";
+
+ rightparts = (immutableDataRight + "\n" + changedDataRight).split("\n");
+ righttext = "<span style='background:rgba(101,101,101,0.75);font-family: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, monospace;padding:1px;'>" + rightparts.join("</span><br><span style='background:rgba(101,101,101,0.75);font-family: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, monospace;padding:1px;'>") + "</span>";
+
+ document.getElementById("debug-left").innerHTML = lefttext.replaceAll("%tps%", tps).replaceAll("%ping%", cping).replaceAll("%false%", "<span style='color:red;font-family: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, monospace;'>false</span>").replaceAll("%true%", "<span style='color:green;font-family: &apos;Source Code Pro&apos;, &apos;JetBrains Mono&apos;, &apos;Ubuntu Mono&apos;, &apos;Consolas&apos;, &apos;Lucida Console&apos;, &apos;Courier New&apos;, 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 = "&lt;Unknown&gt;";
+ }
+ if (gpudriverdata.gpuDevice[0].driverVersion !== undefined) {
+ dversion = gpudriverdata.gpuDevice[0].driverVersion;
+ } else {
+ dversion = "&lt;Unknown&gt;";
+ }
+ } catch (e) {
+ dvendor = "&lt;Unknown&gt;";
+ dversion = "&lt;Unknown&gt;";
+ }
+ 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 8545a29..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 < 50) {
- 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);
- }
- }
-}) \ No newline at end of file
+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
new file mode 100644
index 0000000..45a74d2
--- /dev/null
+++ b/views/script/global_levelsapi.js
@@ -0,0 +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;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/views/script/loader_global.js b/views/script/loader_global.js
index 6bde06c..3a35d54 100644
--- a/views/script/loader_global.js
+++ b/views/script/loader_global.js
@@ -1,119 +1,127 @@
-window.addEventListener('load', () => {
- setTimeout(() => {
- 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) => {
- 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 {
- document.getElementById('warning').style.opacity = "1";
- document.getElementById('updates').style.backgroundColor = "lightyellow";
- document.getElementById('updates').innerText = lang.updates.available;
- }
- }
- 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)
- }
- }, 2000)
- }).catch((e) => {
- console.warn(e);
- document.getElementById('updates').style.backgroundColor = "lightcoral";
- document.getElementById('updates').innerText = lang.updates.error;
- 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)
- }
- }, 2000)
- });
- }).catch((e) => {
- console.warn(e);
- document.getElementById('updates').style.backgroundColor = "lightcoral";
- document.getElementById('updates').innerText = lang.updates.error;
- 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)
- }
- }, 2000)
- });
- }).catch((e) => {
- console.warn(e);
- document.getElementById('updates').style.backgroundColor = "lightcoral";
- document.getElementById('updates').innerText = lang.updates.error;
- 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)
- }
- }, 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)
- }
- }, 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 35b322a..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 Projects");
-} else {
- document.write("2021-" + new Date().getFullYear() + " Minteck Projects");
+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 3713591..a16d3d1 100644
--- a/views/script/menu_global.js
+++ b/views/script/menu_global.js
@@ -1,122 +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 (keysEnabled) {
- 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
new file mode 100644
index 0000000..f2d7c7e
--- /dev/null
+++ b/views/script/menu_login.js
@@ -0,0 +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 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 f224ea9..047967a 100644
--- a/views/script/settings_global.js
+++ b/views/script/settings_global.js
@@ -1,226 +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";
- require('fs').writeFileSync(homedir + "/.kartik/config/music.txt", "0");
- } else {
- document.getElementById("setting-music").innerText = "1";
- require('fs').writeFileSync(homedir + "/.kartik/config/music.txt", "1");
- }
- }
- if (id === "voice") {
- if (document.getElementById("setting-voice").innerText === "1") {
- document.getElementById("setting-voice").innerText = "0";
- require('fs').writeFileSync(homedir + "/.kartik/config/voice.txt", "0");
- } else {
- document.getElementById("setting-voice").innerText = "1";
- require('fs').writeFileSync(homedir + "/.kartik/config/voice.txt", "2");
- }
- }
- if (id === "zoom") {
- zoom = document.getElementById("setting-zoom").innerText;
-
- switch (zoom) {
- case "0.9":
- document.getElementById("setting-zoom").innerText = "1";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "1");
- break;
- case "1":
- document.getElementById("setting-zoom").innerText = "1.1";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "1.1");
- break;
- case "1.1":
- document.getElementById("setting-zoom").innerText = "1.2";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "1.2");
- break;
- case "1.2":
- document.getElementById("setting-zoom").innerText = "1.3";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "1.3");
- break;
- case "1.3":
- document.getElementById("setting-zoom").innerText = "1.4";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "1.4");
- break;
- case "1.4":
- document.getElementById("setting-zoom").innerText = "1.5";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "1.5");
- break;
- case "1.5":
- document.getElementById("setting-zoom").innerText = "1.6";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "1.6");
- break;
- case "1.6":
- document.getElementById("setting-zoom").innerText = "1.7";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "1.7");
- break;
- case "1.7":
- document.getElementById("setting-zoom").innerText = "1.8";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "1.8");
- break;
- case "1.8":
- document.getElementById("setting-zoom").innerText = "1.9";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "1.9");
- break;
- case "1.9":
- document.getElementById("setting-zoom").innerText = "2";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "2");
- break;
- case "2":
- document.getElementById("setting-zoom").innerText = "0.9";
- require('fs').writeFileSync(homedir + "/.kartik/config/scale.txt", "0.9");
- break;
- }
- }
- 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]];
- require('fs').writeFileSync(homedir + "/.kartik/config/lang.txt", slst[ni]);
- require('@electron/remote').getCurrentWindow().lp = slst[ni];
- }
-
- /*switch (lang) {
- case "Français":
- document.getElementById("setting-lang").innerText = "English";
- require('fs').writeFileSync(homedir + "/.kartik/config/lang.txt", "en");
- require('@electron/remote').getCurrentWindow().lp = "en";
- break;
-
- case "English":
- document.getElementById("setting-lang").innerText = "Español";
- require('fs').writeFileSync(homedir + "/.kartik/config/lang.txt", "es");
- require('@electron/remote').getCurrentWindow().lp = "es";
- break;
-
- case "Español":
- document.getElementById("setting-lang").innerText = "中国人";
- require('fs').writeFileSync(homedir + "/.kartik/config/lang.txt", "zh");
- require('@electron/remote').getCurrentWindow().lp = "zh";
- break;
-
- case "中国人":
- document.getElementById("setting-lang").innerText = "日本語";
- require('fs').writeFileSync(homedir + "/.kartik/config/lang.txt", "jp");
- require('@electron/remote').getCurrentWindow().lp = "jp";
- break;
-
- case "日本語":
- document.getElementById("setting-lang").innerText = "русский";
- require('fs').writeFileSync(homedir + "/.kartik/config/lang.txt", "ru");
- require('@electron/remote').getCurrentWindow().lp = "ru";
- break;
-
- case "русский":
- document.getElementById("setting-lang").innerText = "Deutsche";
- require('fs').writeFileSync(homedir + "/.kartik/config/lang.txt", "de");
- require('@electron/remote').getCurrentWindow().lp = "de";
- break;
-
- case "Deutsche":
- document.getElementById("setting-lang").innerText = "Nederlands";
- require('fs').writeFileSync(homedir + "/.kartik/config/lang.txt", "nl");
- require('@electron/remote').getCurrentWindow().lp = "nl";
- break;
-
- case "Nederlands":
- document.getElementById("setting-lang").innerText = "Français";
- require('fs').writeFileSync(homedir + "/.kartik/config/lang.txt", "fr");
- require('@electron/remote').getCurrentWindow().lp = "fr";
- break;
- }*/
- }
- }
- 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 030a7dd..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 (require('fs').readFileSync(homedir + "/.kartik/config/voice.txt").toString() === "2") {
- 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;
+}