From 8886d5111aa4ae75f54f46c93f09fa7548979969 Mon Sep 17 00:00:00 2001 From: Minteck <46352972+Minteck@users.noreply.github.com> Date: Fri, 9 Jul 2021 00:37:48 +0200 Subject: Fixes --- views/script/core_notification.js | 13 +++++++++++++ views/script/loader_global.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 views/script/core_notification.js (limited to 'views/script') diff --git a/views/script/core_notification.js b/views/script/core_notification.js new file mode 100644 index 0000000..118d19d --- /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/loader_global.js b/views/script/loader_global.js index 6bde06c..7c89d0f 100644 --- a/views/script/loader_global.js +++ b/views/script/loader_global.js @@ -19,7 +19,7 @@ window.addEventListener('load', () => { document.getElementById('updates').style.backgroundColor = "lightgreen"; document.getElementById('updates').innerText = lang.updates.ok; } else { - document.getElementById('warning').style.opacity = "1"; + 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; } -- cgit From b9e7ec33542bb8041857eb997d17b29ffeae40c8 Mon Sep 17 00:00:00 2001 From: Minteck <46352972+Minteck@users.noreply.github.com> Date: Fri, 9 Jul 2021 00:51:46 +0200 Subject: Add cooldown to rotations This helps fix some bugs such as an out of border usebug and a bug that enables players to count a lap as they die. This also makes the game more realistic by removing the possibility of doing moves that are not supposed to be possible in real life. --- views/script/game_debug.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'views/script') diff --git a/views/script/game_debug.js b/views/script/game_debug.js index edcdc26..1fb2639 100644 --- a/views/script/game_debug.js +++ b/views/script/game_debug.js @@ -194,6 +194,7 @@ setInterval(() => { 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] @@ -212,6 +213,7 @@ setInterval(() => { 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; @@ -252,7 +254,7 @@ setInterval(() => { } catch (e) { console.error(e); } -},1000); +},100); window.addEventListener("load", () => { require('@electron/remote').app.getGPUInfo('complete').then((data) => { -- cgit From c3b756f987ffd8ca981c1e6f23435c74aad36aea Mon Sep 17 00:00:00 2001 From: Minteck <46352972+Minteck@users.noreply.github.com> Date: Sat, 10 Jul 2021 16:03:26 +0200 Subject: Fixes --- views/script/core_compatlayer.js | 4 +- views/script/global_compatlayer.js | 4 +- views/script/global_levelsapi.js | 47 +++++++++++ views/script/loader_global.js | 7 +- views/script/menu_global.js | 2 + views/script/menu_login.js | 155 +++++++++++++++++++++++++++++++++++++ 6 files changed, 213 insertions(+), 6 deletions(-) create mode 100644 views/script/global_levelsapi.js create mode 100644 views/script/menu_login.js (limited to 'views/script') diff --git a/views/script/core_compatlayer.js b/views/script/core_compatlayer.js index 206aa28..c6794f3 100644 --- a/views/script/core_compatlayer.js +++ b/views/script/core_compatlayer.js @@ -76,7 +76,7 @@ window.addEventListener("load", () => { gpuperct = (gpuscore / maxscore) * 100; - if (gpuperct < 50) { + if (gpuperct < 30) { console.warn("Bad GPU support, disabling GPU-accelerated content"); var head = document.getElementsByTagName('HEAD')[0]; var link = document.createElement('link'); @@ -86,4 +86,4 @@ window.addEventListener("load", () => { head.appendChild(link); } } -}) \ No newline at end of file +}) diff --git a/views/script/global_compatlayer.js b/views/script/global_compatlayer.js index 8545a29..7431cea 100644 --- a/views/script/global_compatlayer.js +++ b/views/script/global_compatlayer.js @@ -76,7 +76,7 @@ window.addEventListener("load", () => { gpuperct = (gpuscore / maxscore) * 100; - if (gpuperct < 50) { + if (gpuperct < 30) { console.warn("Bad GPU support, disabling GPU-accelerated content"); var head = document.getElementsByTagName('HEAD')[0]; var link = document.createElement('link'); @@ -86,4 +86,4 @@ window.addEventListener("load", () => { head.appendChild(link); } } -}) \ No newline at end of file +}) diff --git a/views/script/global_levelsapi.js b/views/script/global_levelsapi.js new file mode 100644 index 0000000..ebd969d --- /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 7c89d0f..db70d3b 100644 --- a/views/script/loader_global.js +++ b/views/script/loader_global.js @@ -9,13 +9,13 @@ window.addEventListener('load', () => { 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") { + 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) { + if (b === require('../package.json').version) { document.getElementById('updates').style.backgroundColor = "lightgreen"; document.getElementById('updates').innerText = lang.updates.ok; } else { @@ -42,6 +42,7 @@ window.addEventListener('load', () => { console.warn(e); document.getElementById('updates').style.backgroundColor = "lightcoral"; document.getElementById('updates').innerText = lang.updates.error; + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); setTimeout(() => { document.getElementById('banner').style.width = "380px"; document.getElementById('banner').style.height = "auto"; @@ -61,6 +62,7 @@ window.addEventListener('load', () => { console.warn(e); document.getElementById('updates').style.backgroundColor = "lightcoral"; document.getElementById('updates').innerText = lang.updates.error; + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); setTimeout(() => { document.getElementById('banner').style.width = "380px"; document.getElementById('banner').style.height = "auto"; @@ -80,6 +82,7 @@ window.addEventListener('load', () => { console.warn(e); document.getElementById('updates').style.backgroundColor = "lightcoral"; document.getElementById('updates').innerText = lang.updates.error; + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); setTimeout(() => { document.getElementById('banner').style.width = "380px"; document.getElementById('banner').style.height = "auto"; diff --git a/views/script/menu_global.js b/views/script/menu_global.js index 3713591..8561fe3 100644 --- a/views/script/menu_global.js +++ b/views/script/menu_global.js @@ -11,6 +11,8 @@ window.addEventListener('load', () => { $("body").focus(); keysEnabled = true; $(document).keydown(function(e) { + if (loggingIn) { return; } + if (keysEnabled) { if (e.keyCode === 13 || e.keyCode === 88 || e.keyCode === 32) { // enter if ($(".services").is(":visible")) { diff --git a/views/script/menu_login.js b/views/script/menu_login.js new file mode 100644 index 0000000..b0a31e9 --- /dev/null +++ b/views/script/menu_login.js @@ -0,0 +1,155 @@ +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"; + require('fs').writeFileSync(homedir + "/.kartik/authentication.json", JSON.stringify(playerData)); + 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() { + if (!require('fs').existsSync(homedir + "/.kartik/authentication.json") || !onlineMode) { + $(document).keydown(function(e) { + if (e.keyCode === 76 && !loggingIn && onlineMode) { + startLogin(); + } + }) + } else { + authData = JSON.parse(require('fs').readFileSync(homedir + "/.kartik/authentication.json")); + + 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; + fs.writeFileSync(homedir + "/.kartik/authentication.json", JSON.stringify(authData)); + } + + 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; + } + } +} \ No newline at end of file -- cgit From 0f0e3de9353c06dfaabc00682b4c2fd9c5f48924 Mon Sep 17 00:00:00 2001 From: Minteck <46352972+Minteck@users.noreply.github.com> Date: Wed, 14 Jul 2021 01:12:14 +0200 Subject: Kartik Fox Nest! --- views/script/core_stats.js | 26 --------- views/script/menu_login.js | 10 ++-- views/script/settings_global.js | 119 ++++------------------------------------ views/script/settings_load.js | 2 +- 4 files changed, 17 insertions(+), 140 deletions(-) (limited to 'views/script') diff --git a/views/script/core_stats.js b/views/script/core_stats.js index a49851d..c8d26df 100644 --- a/views/script/core_stats.js +++ b/views/script/core_stats.js @@ -1,31 +1,5 @@ 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; diff --git a/views/script/menu_login.js b/views/script/menu_login.js index b0a31e9..7f50101 100644 --- a/views/script/menu_login.js +++ b/views/script/menu_login.js @@ -53,7 +53,8 @@ function startLogin() { console.log(playerData); loggingIn = false; document.getElementById('loggingIn').style.display = "none"; - require('fs').writeFileSync(homedir + "/.kartik/authentication.json", JSON.stringify(playerData)); + currentNest.auth = playerData; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); keysEnabled = false; require('electron').ipcRenderer.send('prefademusic', ""); $("#box").fadeOut(500); @@ -108,14 +109,14 @@ window.addEventListener('load', () => { }) function postOnlineMode() { - if (!require('fs').existsSync(homedir + "/.kartik/authentication.json") || !onlineMode) { + if (currentNest.auth === null || !onlineMode) { $(document).keydown(function(e) { if (e.keyCode === 76 && !loggingIn && onlineMode) { startLogin(); } }) } else { - authData = JSON.parse(require('fs').readFileSync(homedir + "/.kartik/authentication.json")); + authData = currentNest.auth; document.getElementById('loginIntro').style.display = "none"; document.getElementById('loginUser').style.display = "grid"; @@ -141,7 +142,8 @@ function postOnlineMode() { async: false, error: (e) => { throw e; } }).responseText.trim() - 1 + 1; - fs.writeFileSync(homedir + "/.kartik/authentication.json", JSON.stringify(authData)); + currentNest.auth = authData; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); } document.getElementById('kto-picture').src = authData.picture; diff --git a/views/script/settings_global.js b/views/script/settings_global.js index f224ea9..e284585 100644 --- a/views/script/settings_global.js +++ b/views/script/settings_global.js @@ -45,73 +45,23 @@ $(document).keydown(function(e) { 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"); + currentNest.config.music = false; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); } else { document.getElementById("setting-music").innerText = "1"; - require('fs').writeFileSync(homedir + "/.kartik/config/music.txt", "1"); + currentNest.config.music = true; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); } } 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"); + currentNest.config.music = false; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); } 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; + currentNest.config.music = true; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); } } if (id === "lang") { @@ -135,59 +85,10 @@ $(document).keydown(function(e) { if (ci !== -1 && ni !== -1) { document.getElementById("setting-lang").innerText = slng[slst[ni]]; - require('fs').writeFileSync(homedir + "/.kartik/config/lang.txt", slst[ni]); + currentNest.config.lang = slst[ni]; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); 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 diff --git a/views/script/settings_load.js b/views/script/settings_load.js index 030a7dd..b15b125 100644 --- a/views/script/settings_load.js +++ b/views/script/settings_load.js @@ -9,7 +9,7 @@ if (require('@electron/remote').getCurrentWindow().music) { document.getElementById("setting-music").innerText = "0"; } -if (require('fs').readFileSync(homedir + "/.kartik/config/voice.txt").toString() === "2") { +if (currentNest.config.voice === true) { document.getElementById("setting-voice").innerText = "1"; } else { document.getElementById("setting-voice").innerText = "0"; -- cgit From 44210691ee8444509ac466a362337af77f2bcd49 Mon Sep 17 00:00:00 2001 From: Minteck <46352972+Minteck@users.noreply.github.com> Date: Tue, 20 Jul 2021 01:30:23 +0200 Subject: Commit --- views/script/core_chart.js | 8 ++- views/script/core_crash.js | 21 +++++++ views/script/core_fullscreen.js | 43 ++++++++++++-- views/script/core_stats.js | 64 ++++++++++---------- views/script/core_viewer.js | 42 +++++++------ views/script/loader_global.js | 127 +++++++++++++++++++++------------------- views/script/menu_copyright.js | 4 +- views/script/menu_global.js | 3 + views/script/menu_login.js | 114 ++++++++++++++++++++++++++---------- views/script/settings_global.js | 10 ++-- 10 files changed, 280 insertions(+), 156 deletions(-) create mode 100644 views/script/core_crash.js (limited to 'views/script') diff --git a/views/script/core_chart.js b/views/script/core_chart.js index 059c818..2f8a521 100644 --- a/views/script/core_chart.js +++ b/views/script/core_chart.js @@ -2,7 +2,7 @@ setInterval(() => { try { currentMemory = process.memoryUsage().rss; currentMemoryMib = (((currentMemory)/1024)/1024).toFixed(2); - if ((((currentMemory)/1024)/1024) > 250) { + if ((((currentMemory)/1024)/1024) > ((require('os').totalmem() / 1000000) / 4)) { throw new Error("Out of memory"); } @@ -66,5 +66,9 @@ setInterval(() => { } else { document.title="Kartik"+require('@electron/remote').getCurrentWindow().channel+require('./package.json').version + eaid; } - } catch (e) {} + } catch (e) { + if (e.message === "Out of memory") { + throw e; + } + } }, 1000) \ No newline at end of file diff --git a/views/script/core_crash.js b/views/script/core_crash.js new file mode 100644 index 0000000..d24ec2d --- /dev/null +++ b/views/script/core_crash.js @@ -0,0 +1,21 @@ +global.gameCrashed = false; +crashSound = new Audio("./sfx/gamecrash.wav"); + +function destroy() { + global.gameCrashed = true; + crashSound.play(); + require('@electron/remote').webContents.fromId(webview.getWebContentsId()).forcefullyCrashRenderer(); + try { musicElement.pause(); } catch (e) {} +} + +function spawnError(crashReport) { + document.getElementById("error-outer").style.display = "flex"; + document.getElementById("crash-dump").value = crashReport; + destroy(); +} + +const crashHandler = require('electron').ipcRenderer; + +crashHandler.on('crashreport', (event, args) => { + spawnError(args); +}) \ No newline at end of file diff --git a/views/script/core_fullscreen.js b/views/script/core_fullscreen.js index 69f9e45..f2c540d 100644 --- a/views/script/core_fullscreen.js +++ b/views/script/core_fullscreen.js @@ -1,9 +1,40 @@ -$(document).keydown(function(e) { - if (e.keyCode === 122 || e.keyCode === 121 || e.keyCode === 112) { // F11/F1/F10 - if (!require('@electron/remote').getCurrentWindow().fullScreen && require('@electron/remote').getCurrentWindow().fullScreenable) { - require('@electron/remote').getCurrentWindow().setFullScreen(true); - } else { - require('@electron/remote').getCurrentWindow().setFullScreen(false); +window.addEventListener("load", () => { + require('@electron/remote').getCurrentWindow().show(); + + const Nest = require("./nest/abi"); + + $(document).keydown(function(e) { + if (e.keyCode === 122 || e.keyCode === 121 || e.keyCode === 112) { // F11/F1/F10 + if (!require('@electron/remote').getCurrentWindow().fullScreen && require('@electron/remote').getCurrentWindow().fullScreenable) { + require('@electron/remote').getCurrentWindow().setFullScreen(true); + } else { + require('@electron/remote').getCurrentWindow().setFullScreen(false); + } } + }) + + $(document).keydown(function(e) { + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + + if (e.keyCode === 122 || e.keyCode === 121 || e.keyCode === 112) { + if (currentNest.config.fullscreen) { + currentNest.config.fullscreen = false; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + require('electron').ipcRenderer.send("reloadNest") + } else { + currentNest.config.fullscreen = true; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + require('electron').ipcRenderer.send("reloadNest"); + } + } + }) + + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + if (currentNest.config.fullscreen) { + require('@electron/remote').getCurrentWindow().setFullScreen(true); + } else { + currentNest.config.fullscreen = false; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + require('electron').ipcRenderer.send("reloadNest") } }) \ No newline at end of file diff --git a/views/script/core_stats.js b/views/script/core_stats.js index c8d26df..930c776 100644 --- a/views/script/core_stats.js +++ b/views/script/core_stats.js @@ -6,42 +6,46 @@ timer = null; current = null; webview.addEventListener('dom-ready', () => { - if (webview.getURL() !== current) { - if (session !== null) { - require('electron').ipcRenderer.send('addstats', { catalog: "times", key: session, add: Math.floor((new Date() - timer)/1000) }); + try { + if (webview.getURL() !== current) { + if (session !== null) { + require('electron').ipcRenderer.send('addstats', { catalog: "times", key: session, add: Math.floor((new Date() - timer)/1000) }); - session = null; - timer = null; - current = null; + session = null; + timer = null; + current = null; + } } - } - if (webview.getURL().endsWith("game.html")) { // Local - session = "local"; - timer = new Date(); - current = webview.getURL(); - } - if (webview.getURL().endsWith("game.html?sp")) { // Singleplayer - session = "single"; - timer = new Date(); - current = webview.getURL(); - } - if (webview.getURL().endsWith("game.html?online")) { // Online - session = "online"; - timer = new Date(); - current = webview.getURL(); - } + if (webview.getURL().endsWith("game.html")) { // Local + session = "local"; + timer = new Date(); + current = webview.getURL(); + } + if (webview.getURL().endsWith("game.html?sp")) { // Singleplayer + session = "single"; + timer = new Date(); + current = webview.getURL(); + } + if (webview.getURL().endsWith("game.html?online")) { // Online + session = "online"; + timer = new Date(); + current = webview.getURL(); + } + } catch (e) {} }) window.addEventListener("beforeunload", function(e){ - if (session !== null) { - require('electron').ipcRenderer.send('addstatsandclose', { catalog: "times", key: session, add: Math.floor((new Date() - timer)/1000) }); + try { + if (session !== null) { + require('electron').ipcRenderer.send('addstatsandclose', { catalog: "times", key: session, add: Math.floor((new Date() - timer)/1000) }); - session = null; - timer = null; - current = null; + session = null; + timer = null; + current = null; - e.preventDefault(); - return false; - } + e.preventDefault(); + return false; + } + } catch (e) {} }, false); \ No newline at end of file diff --git a/views/script/core_viewer.js b/views/script/core_viewer.js index 389bf41..eac3766 100644 --- a/views/script/core_viewer.js +++ b/views/script/core_viewer.js @@ -1,24 +1,28 @@ const webview = document.getElementById('wb'); -webview.addEventListener('dom-ready', () => { - document.getElementById('dummyloader').style.display = "none"; - require('@electron/remote').getCurrentWindow().log(" * " + webview.getURL()); - try { - if (require('@electron/remote').getCurrentWindow().debug) { - info("MainWindow", "Opening debugging tools..."); - webview.openDevTools(); - } - } catch (e) {} -}) - -webview.addEventListener('dom-ready', () => { - setInterval(() => { +try { + webview.addEventListener('dom-ready', () => { + document.getElementById('dummyloader').style.display = "none"; + require('@electron/remote').getCurrentWindow().log(" * " + webview.getURL()); + require('@electron/remote').getCurrentWindow().focus(); + webview.focus(); try { - if (webview.isCrashed()) { - require('@electron/remote').getCurrentWindow().log(" * Compositing engine crashed!"); - error("MainWindow", "Subcontainer crashed"); - crash(new Error("Webview crashed")); + if (require('@electron/remote').getCurrentWindow().debug) { + info("MainWindow", "Opening debugging tools..."); + webview.openDevTools(); } } catch (e) {} - }, 2000) -}) \ No newline at end of file + }) + + webview.addEventListener('dom-ready', () => { + setInterval(() => { + try { + if (webview.isCrashed() && !gameCrashed) { + require('@electron/remote').getCurrentWindow().log(" * Compositing engine crashed!"); + error("MainWindow", "Subcontainer crashed"); + crash(new Error("Webview crashed")); + } + } catch (e) {} + }, 2000) + }) +} catch (e) {} \ No newline at end of file diff --git a/views/script/loader_global.js b/views/script/loader_global.js index db70d3b..7543268 100644 --- a/views/script/loader_global.js +++ b/views/script/loader_global.js @@ -3,7 +3,7 @@ window.addEventListener('load', () => { if (native) { setTimeout(() => { setTimeout(() => { - if (native) {global.$ = require('jquery');} else {var script = document.createElement('script');script.src = '../webinit/jquery.js';script.type = 'text/javascript';document.getElementsByTagName('head')[0].appendChild(script);} + $("#progress").fadeOut(500); setTimeout(() => { window.fetch("https://kartik.hopto.org/latest.php?v=" + require('@electron/remote').getCurrentWindow().update).then((data) => { @@ -25,18 +25,19 @@ window.addEventListener('load', () => { } } setTimeout(() => { - document.getElementById('banner').style.width = "380px"; - document.getElementById('banner').style.height = "auto"; - document.getElementById('banner').src = "common/banner.gif"; - introsfx = new Audio("../sfx/newintro.mp3"); - introsfx.play() - introsfx.onended = () => { - $("body").fadeOut(500); - setTimeout(() => { - info("LoadWindow", "Switching control to MenuWindow"); - location.href = "intro.html"; - }, 1000) - } + $("#banner-outer").fadeOut(200); + $("#intro-video").fadeIn(200); + setTimeout(() => { + introsfx = document.getElementById("intro-video"); + introsfx.play() + introsfx.onended = () => { + $("body").fadeOut(500); + setTimeout(() => { + info("LoadWindow", "Switching control to MenuWindow"); + location.href = "intro.html"; + }, 1000) + } + }, 200) }, 2000) }).catch((e) => { console.warn(e); @@ -44,10 +45,31 @@ window.addEventListener('load', () => { document.getElementById('updates').innerText = lang.updates.error; require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); setTimeout(() => { - document.getElementById('banner').style.width = "380px"; - document.getElementById('banner').style.height = "auto"; - document.getElementById('banner').src = "common/banner.gif"; - introsfx = new Audio("../sfx/newintro.mp3"); + $("#banner-outer").fadeOut(200); + $("#intro-video").fadeIn(200); + setTimeout(() => { + introsfx = document.getElementById("intro-video"); + introsfx.play() + introsfx.onended = () => { + $("body").fadeOut(500); + setTimeout(() => { + info("LoadWindow", "Switching control to MenuWindow"); + location.href = "intro.html"; + }, 1000) + } + }, 200) + }, 2000) + }); + }).catch((e) => { + console.warn(e); + document.getElementById('updates').style.backgroundColor = "lightcoral"; + document.getElementById('updates').innerText = lang.updates.error; + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); + setTimeout(() => { + $("#banner-outer").fadeOut(200); + $("#intro-video").fadeIn(200); + setTimeout(() => { + introsfx = document.getElementById("intro-video"); introsfx.play() introsfx.onended = () => { $("body").fadeOut(500); @@ -56,18 +78,19 @@ window.addEventListener('load', () => { location.href = "intro.html"; }, 1000) } - }, 2000) - }); - }).catch((e) => { - console.warn(e); - document.getElementById('updates').style.backgroundColor = "lightcoral"; - document.getElementById('updates').innerText = lang.updates.error; - require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); + }, 200) + }, 2000) + }); + }).catch((e) => { + console.warn(e); + document.getElementById('updates').style.backgroundColor = "lightcoral"; + document.getElementById('updates').innerText = lang.updates.error; + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); + setTimeout(() => { + $("#banner-outer").fadeOut(200); + $("#intro-video").fadeIn(200); setTimeout(() => { - document.getElementById('banner').style.width = "380px"; - document.getElementById('banner').style.height = "auto"; - document.getElementById('banner').src = "common/banner.gif"; - introsfx = new Audio("../sfx/newintro.mp3"); + introsfx = document.getElementById("intro-video"); introsfx.play() introsfx.onended = () => { $("body").fadeOut(500); @@ -76,46 +99,28 @@ window.addEventListener('load', () => { location.href = "intro.html"; }, 1000) } - }, 2000) - }); - }).catch((e) => { - console.warn(e); - document.getElementById('updates').style.backgroundColor = "lightcoral"; - document.getElementById('updates').innerText = lang.updates.error; - require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); - setTimeout(() => { - document.getElementById('banner').style.width = "380px"; - document.getElementById('banner').style.height = "auto"; - document.getElementById('banner').src = "common/banner.gif"; - introsfx = new Audio("../sfx/newintro.mp3"); - introsfx.play() - introsfx.onended = () => { - $("body").fadeOut(500); - setTimeout(() => { - info("LoadWindow", "Switching control to MenuWindow"); - location.href = "intro.html"; - }, 1000) - } + }, 200) }, 2000) }); }, 2000) }, 3000) }, 1000) } else { - if (native) {global.$ = require('jquery');} else {var script = document.createElement('script');script.src = '../webinit/jquery.js';script.type = 'text/javascript';document.getElementsByTagName('head')[0].appendChild(script);} + setTimeout(() => { - document.getElementById('banner').style.width = "380px"; - document.getElementById('banner').style.height = "auto"; - document.getElementById('banner').src = "common/banner.gif"; - introsfx = new Audio("../sfx/newintro.mp3"); - introsfx.play() - introsfx.onended = () => { - $("body").fadeOut(500); - setTimeout(() => { - info("LoadWindow", "Switching control to MenuWindow"); - location.href = "intro.html"; - }, 1000) - } + $("#banner-outer").fadeOut(200); + $("#intro-video").fadeIn(200); + setTimeout(() => { + introsfx = document.getElementById("intro-video"); + introsfx.play() + introsfx.onended = () => { + $("body").fadeOut(500); + setTimeout(() => { + info("LoadWindow", "Switching control to MenuWindow"); + location.href = "intro.html"; + }, 1000) + } + }, 200) }, 5000) } }, 2000) diff --git a/views/script/menu_copyright.js b/views/script/menu_copyright.js index 35b322a..2b38844 100644 --- a/views/script/menu_copyright.js +++ b/views/script/menu_copyright.js @@ -1,5 +1,5 @@ if (new Date().getFullYear() === 2021) { - document.write(new Date().getFullYear() + " Minteck Projects"); + document.write(new Date().getFullYear() + " Minteck"); } else { - document.write("2021-" + new Date().getFullYear() + " Minteck Projects"); + document.write("2021-" + new Date().getFullYear() + " Minteck"); } \ No newline at end of file diff --git a/views/script/menu_global.js b/views/script/menu_global.js index 8561fe3..14a924f 100644 --- a/views/script/menu_global.js +++ b/views/script/menu_global.js @@ -14,6 +14,9 @@ $(document).keydown(function(e) { if (loggingIn) { return; } if (keysEnabled) { + if (e.ctrlKey && e.keyCode === 13) { // ctrl+enter + throw new RangeError("Manually initiated crash"); + } if (e.keyCode === 13 || e.keyCode === 88 || e.keyCode === 32) { // enter if ($(".services").is(":visible")) { selectOption(); diff --git a/views/script/menu_login.js b/views/script/menu_login.js index 7f50101..2af88b2 100644 --- a/views/script/menu_login.js +++ b/views/script/menu_login.js @@ -54,7 +54,7 @@ function startLogin() { loggingIn = false; document.getElementById('loggingIn').style.display = "none"; currentNest.auth = playerData; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") keysEnabled = false; require('electron').ipcRenderer.send('prefademusic', ""); $("#box").fadeOut(500); @@ -109,49 +109,101 @@ window.addEventListener('load', () => { }) function postOnlineMode() { - if (currentNest.auth === null || !onlineMode) { - $(document).keydown(function(e) { - if (e.keyCode === 76 && !loggingIn && onlineMode) { - startLogin(); + try { + if (currentNest.auth === null || !onlineMode) { + $(document).keydown(function(e) { + if (e.keyCode === 76 && !loggingIn && onlineMode) { + startLogin(); + } + }) + } else { + authData = currentNest.auth; + + document.getElementById('loginIntro').style.display = "none"; + document.getElementById('loginUser').style.display = "grid"; + + olevel = $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + authData.token, + async: false, + error: (e) => { throw e; } + }).responseText.trim() - 1 + 1; + + if (authData.level > olevel) { + $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/set.level.php?kartik_online_token=' + authData.token + "&level=" + authData.level, + async: false, + error: (e) => { throw e; } + }); + } else if (authData.level < olevel) { + authData.level = $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + authData.token, + async: false, + error: (e) => { throw e; } + }).responseText.trim() - 1 + 1; + currentNest.auth = authData; + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") } - }) - } else { - authData = currentNest.auth; - document.getElementById('loginIntro').style.display = "none"; - document.getElementById('loginUser').style.display = "grid"; + ostats = JSON.parse($.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/profile.stats.php?kartik_online_token=' + authData.token, + async: false, + error: (e) => { throw e; } + }).responseText.trim()) - olevel = $.ajax({ - type: "GET", - url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + authData.token, - async: false, - error: (e) => { throw e; } - }).responseText.trim() - 1 + 1; + if (ostats === null) { + cstats = currentNest.stats; + } else { + cstats = {}; + + for (group in currentNest.stats) { + cstats[group] = {}; + + for (item in currentNest.stats[group]) { + if (ostats[group][item]) { + if (ostats[group][item] > currentNest.stats[group][item]) { + cstats[group][item] = ostats[group][item]; + } else { + cstats[group][item] = currentNest.stats[group][item]; + } + } else { + cstats[group][item] = currentNest.stats[group][item]; + } + } + } + } - if (authData.level > olevel) { $.ajax({ type: "GET", - url: 'https://kartik.hopto.org/online/ingame/api/set.level.php?kartik_online_token=' + authData.token + "&level=" + authData.level, + url: 'https://kartik.hopto.org/online/ingame/api/set.stats.php?kartik_online_token=' + authData.token + "&stats=" + Buffer.from(JSON.stringify(cstats)).toString("base64"), async: false, error: (e) => { throw e; } }); - } else if (authData.level < olevel) { - authData.level = $.ajax({ + + currentNest.stats = JSON.parse($.ajax({ type: "GET", - url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + authData.token, + url: 'https://kartik.hopto.org/online/ingame/api/profile.stats.php?kartik_online_token=' + authData.token, async: false, error: (e) => { throw e; } - }).responseText.trim() - 1 + 1; - currentNest.auth = authData; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); - } + }).responseText.trim()); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") - document.getElementById('kto-picture').src = authData.picture; - document.getElementById('kto-username').innerText = authData.name; - if (authData.level < 200) { - document.getElementById('kto-level').innerText = authData.level; - } else { - document.getElementById('kto-level').innerText = lang.polymer.ktoMaxLevel; + document.getElementById('kto-picture').src = authData.picture; + document.getElementById('kto-username').innerText = authData.name; + if (authData.level < 200) { + document.getElementById('kto-level').innerText = authData.level; + } else { + document.getElementById('kto-level').innerText = lang.polymer.ktoMaxLevel; + } } + } catch (e) { + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]}); + console.error(e); + onlineMode = false; + document.getElementById("loginIntro").innerText = lang.polymer.error[2]; + document.getElementById("online").parentElement.parentElement.outerHTML = ""; } } \ No newline at end of file diff --git a/views/script/settings_global.js b/views/script/settings_global.js index e284585..90f1f6e 100644 --- a/views/script/settings_global.js +++ b/views/script/settings_global.js @@ -46,22 +46,22 @@ $(document).keydown(function(e) { if (document.getElementById("setting-music").innerText === "1") { document.getElementById("setting-music").innerText = "0"; currentNest.config.music = false; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") } else { document.getElementById("setting-music").innerText = "1"; currentNest.config.music = true; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") } } if (id === "voice") { if (document.getElementById("setting-voice").innerText === "1") { document.getElementById("setting-voice").innerText = "0"; currentNest.config.music = false; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") } else { document.getElementById("setting-voice").innerText = "1"; currentNest.config.music = true; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") } } if (id === "lang") { @@ -86,7 +86,7 @@ $(document).keydown(function(e) { if (ci !== -1 && ni !== -1) { document.getElementById("setting-lang").innerText = slng[slst[ni]]; currentNest.config.lang = slst[ni]; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest") require('@electron/remote').getCurrentWindow().lp = slst[ni]; } } -- cgit From d5a620cf09b835db2bccd99556525c90b458719f Mon Sep 17 00:00:00 2001 From: Minteck Date: Thu, 5 Aug 2021 17:21:23 +0200 Subject: i18n for 21.08 --- views/script/core_compatlayer.js | 178 ++++++------- views/script/core_crash.js | 40 +-- views/script/core_notification.js | 24 +- views/script/core_stats.js | 100 +++---- views/script/game_debug.js | 524 ++++++++++++++++++------------------- views/script/global_compatlayer.js | 178 ++++++------- views/script/global_levelsapi.js | 92 +++---- views/script/loader_global.js | 254 +++++++++--------- views/script/menu_copyright.js | 8 +- views/script/menu_global.js | 252 +++++++++--------- views/script/menu_login.js | 449 ++++++++++++++++--------------- views/script/settings_global.js | 254 +++++++++--------- views/script/settings_load.js | 50 ++-- 13 files changed, 1218 insertions(+), 1185 deletions(-) (limited to 'views/script') 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 = "" + leftparts.join("
") + ""; - - rightparts = (immutableDataRight + "\n" + changedDataRight).split("\n"); - righttext = "" + rightparts.join("
") + ""; - - document.getElementById("debug-left").innerHTML = lefttext.replaceAll("%tps%", tps).replaceAll("%ping%", cping).replaceAll("%false%", "false").replaceAll("%true%", "true"); - 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 = "" + leftparts.join("
") + ""; + + rightparts = (immutableDataRight + "\n" + changedDataRight).split("\n"); + righttext = "" + rightparts.join("
") + ""; + + document.getElementById("debug-left").innerHTML = lefttext.replaceAll("%tps%", tps).replaceAll("%ping%", cping).replaceAll("%false%", "false").replaceAll("%true%", "true"); + 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; +} -- cgit