diff options
-rw-r--r-- | app.js | 24 | ||||
-rw-r--r-- | lang/en.json | 27 | ||||
-rw-r--r-- | online/levels.txt | 200 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | race/cars/car1ai.js | 2 | ||||
-rw-r--r-- | sfx/click.mp3 | bin | 4461 -> 8641 bytes | |||
-rw-r--r-- | sfx/crash.mp3 | bin | 9453 -> 13194 bytes | |||
-rw-r--r-- | sfx/intro.mp3 | bin | 9026 -> 0 bytes | |||
-rw-r--r-- | sfx/last.mp3 | bin | 8168 -> 26670 bytes | |||
-rw-r--r-- | sfx/menu.mp3 | bin | 5037 -> 7561 bytes | |||
-rw-r--r-- | sfx/notification.mp3 | bin | 41006 -> 11425 bytes | |||
-rw-r--r-- | sfx/pass.mp3 | bin | 10884 -> 22309 bytes | |||
-rw-r--r-- | sfx/pause.mp3 | bin | 11565 -> 14353 bytes | |||
-rw-r--r-- | sfx/win.mp3 | bin | 3361 -> 24337 bytes | |||
-rw-r--r-- | signing/sign.js | 4 | ||||
-rw-r--r-- | views/loader.svg | 4 | ||||
-rw-r--r-- | views/loader/back.png | bin | 0 -> 67643 bytes | |||
-rw-r--r-- | views/loader/logo.png | bin | 0 -> 165369 bytes | |||
-rw-r--r-- | views/menu.css | 70 | ||||
-rw-r--r-- | views/menu.html | 34 | ||||
-rw-r--r-- | views/script/core_compatlayer.js | 4 | ||||
-rw-r--r-- | views/script/global_compatlayer.js | 4 | ||||
-rw-r--r-- | views/script/global_levelsapi.js | 47 | ||||
-rw-r--r-- | views/script/loader_global.js | 7 | ||||
-rw-r--r-- | views/script/menu_global.js | 2 | ||||
-rw-r--r-- | views/script/menu_login.js | 155 | ||||
-rw-r--r-- | views/stats.html | 2 |
27 files changed, 564 insertions, 24 deletions
@@ -269,17 +269,29 @@ const { app, BrowserWindow } = require('electron'); win.webContents.send('setmusic', value); } }) - musicIpc.on('prefademusic', (event, value) => { - win.webContents.send('fademusic', value); - }) - musicIpc.on('preunfademusic', (event, value) => { - win.webContents.send('unfademusic', value); - }) + + const LevelsAPI = require('./views/script/global_levelsapi'); + const lvl = new LevelsAPI(); stats = require(homedir + "/.kartik/stats.json"); musicIpc.on('addstats', (event, value) => { stats[value.catalog][value.key] = stats[value.catalog][value.key] + value.add; fs.writeFile(homedir + "/.kartik/stats.json", JSON.stringify(stats), () => {}); + + if (value.key === "laps" && fs.existsSync(homedir + "/.kartik/authentication.json")) { + auth = JSON.parse(fs.readFileSync(homedir + "/.kartik/authentication.json").toString()); + level = lvl.correspond(stats["ingame"]["laps"], "256") - 1 + 1; + + if (level !== auth.level) { + auth.level = level + fs.writeFileSync(homedir + "/.kartik/authentication.json", JSON.stringify(auth)); + if (level < 200) { + win.webContents.send("notification", {title: lang.polymer.levelup[0], message: lang.polymer.levelup[1] + " " + level + " " + lang.polymer.levelup[2]}); + } else { + win.webContents.send("notification", {title: lang.polymer.finished[0], message: lang.polymer.finished[1]}); + } + } + } }) musicIpc.on('addstatsandclose', (event, value) => { stats[value.catalog][value.key] = stats[value.catalog][value.key] + value.add; diff --git a/lang/en.json b/lang/en.json index 6f75c3d..19372a4 100644 --- a/lang/en.json +++ b/lang/en.json @@ -200,5 +200,32 @@ "ingame.laps": "Number of laps you made", "ingame.turns": "Number of rotations you made" } + }, + "polymer": { + "gpu": "GPU Support Status", + "logging": "We are logging you in ; check for your Web browser window and accept the login.", + "loginClose": "You can now close this tab/window and go back to Kartik.", + "gatheringLogin": "We are checking your account ; this may take a while.", + "loginIntro": "Press L to login", + "ktoLevel": "Level", + "ktoMaxLevel": "God", + "error": [ + "Unable to communicate with servers", + "You won't be able to use Kartik Online until we can connect to the servers.", + "Go online to log in" + ], + "updateError": [ + "Unable to check for updates", + "We cannot check for new updates right now, please try again later." + ], + "levelup": [ + "Level up!", + "You have reached level", + "and you're gaining power! Continue and try to reach the maximum level." + ], + "finished": [ + "You've beaten the game!", + "Finished Kartik?! Yes. You've reached the god level!" + ] } } diff --git a/online/levels.txt b/online/levels.txt new file mode 100644 index 0000000..6566fea --- /dev/null +++ b/online/levels.txt @@ -0,0 +1,200 @@ +1:1 +2:2 +3:3 +4:4 +5:5 +6:7 +7:9 +8:11 +9:13 +10:16 +11:19 +12:22 +13:25 +14:29 +15:33 +16:37 +17:41 +18:46 +19:51 +20:56 +21:61 +22:67 +23:73 +24:79 +25:85 +26:92 +27:99 +28:106 +29:113 +30:121 +31:129 +32:137 +33:145 +34:154 +35:163 +36:172 +37:181 +38:191 +39:201 +40:211 +41:221 +42:232 +43:243 +44:254 +45:265 +46:277 +47:289 +48:301 +49:313 +50:326 +51:339 +52:352 +53:365 +54:379 +55:393 +56:407 +57:421 +58:436 +59:451 +60:466 +61:481 +62:497 +63:513 +64:529 +65:545 +66:562 +67:579 +68:596 +69:613 +70:631 +71:649 +72:667 +73:685 +74:704 +75:723 +76:742 +77:761 +78:781 +79:801 +80:821 +81:841 +82:862 +83:883 +84:904 +85:925 +86:947 +87:969 +88:991 +89:1013 +90:1036 +91:1059 +92:1082 +93:1105 +94:1129 +95:1153 +96:1177 +97:1201 +98:1226 +99:1251 +100:1276 +101:1301 +102:1327 +103:1353 +104:1379 +105:1405 +106:1432 +107:1459 +108:1486 +109:1513 +110:1541 +111:1569 +112:1597 +113:1625 +114:1654 +115:1683 +116:1712 +117:1741 +118:1771 +119:1801 +120:1831 +121:1861 +122:1892 +123:1923 +124:1954 +125:1985 +126:2017 +127:2049 +128:2081 +129:2113 +130:2146 +131:2179 +132:2212 +133:2245 +134:2279 +135:2313 +136:2347 +137:2381 +138:2416 +139:2451 +140:2486 +141:2521 +142:2557 +143:2593 +144:2629 +145:2665 +146:2702 +147:2739 +148:2776 +149:2813 +150:2851 +151:2889 +152:2927 +153:2965 +154:3004 +155:3043 +156:3082 +157:3121 +158:3161 +159:3201 +160:3241 +161:3281 +162:3322 +163:3363 +164:3404 +165:3445 +166:3487 +167:3529 +168:3571 +169:3613 +170:3656 +171:3699 +172:3742 +173:3785 +174:3829 +175:3873 +176:3917 +177:3961 +178:4006 +179:4051 +180:4096 +181:4141 +182:4187 +183:4233 +184:4279 +185:4325 +186:4372 +187:4419 +188:4466 +189:4513 +190:4561 +191:4609 +192:4657 +193:4705 +194:4754 +195:4803 +196:4852 +197:4901 +198:4951 +199:5001 +200:5051
\ No newline at end of file diff --git a/package.json b/package.json index 11e0311..93490a9 100644 --- a/package.json +++ b/package.json @@ -1 +1 @@ -{"name":"kartik","version":"a69a90e","channel":"git","description":"A multiplatform 2D karting game","main":"app.js","dependencies":{"@electron/remote":"^1.0.4","discord-rpc":"^3.2.0","electron":"^12.0.1","ini":"^1.3.8","jquery":"^3.6.0","os-locale":"^5.0.0","systeminformation":"^5.7.7","uuid":"^8.3.2","yaml":"^1.10.2"},"scripts":{"test":"node_modules\\electron\\dist\\electron.exe app.js"},"author":"Minteck Projects","license":"GPL-3.0-or-later","serial":"XXX99999999999"}
\ No newline at end of file +{"name":"kartik","version":"83fb25f","channel":"git","description":"A multiplatform 2D karting game","main":"app.js","dependencies":{"@electron/remote":"^1.0.4","discord-rpc":"^3.2.0","electron":"^12.0.1","ini":"^1.3.8","jquery":"^3.6.0","open":"^8.2.1","os-locale":"^5.0.0","systeminformation":"^5.7.7","uuid":"^8.3.2","yaml":"^1.10.2"},"scripts":{"test":"node_modules\\electron\\dist\\electron.exe app.js"},"author":"Minteck Projects","license":"GPL-3.0-or-later","serial":"XXX99999999999"}
\ No newline at end of file diff --git a/race/cars/car1ai.js b/race/cars/car1ai.js index 25e1819..87e5920 100644 --- a/race/cars/car1ai.js +++ b/race/cars/car1ai.js @@ -53,7 +53,7 @@ function enableAI() { } else if (overlap) { car1speed = 9; } else { - car1speed = 10; + car1speed = 16; } carshb = document.getElementById("aibox-far").getBoundingClientRect(); diff --git a/sfx/click.mp3 b/sfx/click.mp3 Binary files differindex 710c85b..20feda0 100644 --- a/sfx/click.mp3 +++ b/sfx/click.mp3 diff --git a/sfx/crash.mp3 b/sfx/crash.mp3 Binary files differindex 1ce02e9..c68bb1f 100644 --- a/sfx/crash.mp3 +++ b/sfx/crash.mp3 diff --git a/sfx/intro.mp3 b/sfx/intro.mp3 Binary files differdeleted file mode 100644 index 5d90f31..0000000 --- a/sfx/intro.mp3 +++ /dev/null diff --git a/sfx/last.mp3 b/sfx/last.mp3 Binary files differindex 2595f73..ff00ddf 100644 --- a/sfx/last.mp3 +++ b/sfx/last.mp3 diff --git a/sfx/menu.mp3 b/sfx/menu.mp3 Binary files differindex f48daa8..626a82e 100644 --- a/sfx/menu.mp3 +++ b/sfx/menu.mp3 diff --git a/sfx/notification.mp3 b/sfx/notification.mp3 Binary files differindex c3dc438..09f548a 100644 --- a/sfx/notification.mp3 +++ b/sfx/notification.mp3 diff --git a/sfx/pass.mp3 b/sfx/pass.mp3 Binary files differindex 04caca0..e4fc004 100644 --- a/sfx/pass.mp3 +++ b/sfx/pass.mp3 diff --git a/sfx/pause.mp3 b/sfx/pause.mp3 Binary files differindex aedcd13..76d0634 100644 --- a/sfx/pause.mp3 +++ b/sfx/pause.mp3 diff --git a/sfx/win.mp3 b/sfx/win.mp3 Binary files differindex 9a7ae56..d3c3b89 100644 --- a/sfx/win.mp3 +++ b/sfx/win.mp3 diff --git a/signing/sign.js b/signing/sign.js index 2e1c23d..bb8d534 100644 --- a/signing/sign.js +++ b/signing/sign.js @@ -9,7 +9,7 @@ global.sdb = { function scan(start) { rt = fs.readdirSync(start); for (file of rt) { - if (file !== ".git" && file !== "build" && file !== "signatures.json" && file !== "staging" && file !== "node_modules" && !file.endsWith(".staging") && !file.endsWith(".old") && file !== "_translate") { + if (file !== ".git" && file !== "build" && file !== "signatures.json" && file !== "staging" && file !== "node_modules" && !file.endsWith(".staging") && !file.endsWith(".old") && file !== "_translate" && file !== "macos") { if (fs.lstatSync(start + "/" + file).isDirectory()) { scan(start + "/" + file); } else { @@ -30,4 +30,4 @@ function scan(start) { } scan(".."); -fs.writeFileSync("../bin/signatures.json", JSON.stringify(sdb));
\ No newline at end of file +fs.writeFileSync("../bin/signatures.json", JSON.stringify(sdb)); diff --git a/views/loader.svg b/views/loader.svg index 77a496e..042b338 100644 --- a/views/loader.svg +++ b/views/loader.svg @@ -115,7 +115,7 @@ <glyph unicode=" " horiz-adv-x="300"/> </font> - <image style="overflow:visible;" width="787" height="443" xlink:href="C:\Users\Minteck\Desktop\loader.png" transform="matrix(0.9974 0 0 0.9977 1 1)"> + <image style="overflow:visible;" width="787" height="443" xlink:href="./loader/back.png" transform="matrix(0.9974 0 0 0.9977 1 1)"> </image> <text transform="matrix(1 0 0 1 59.7305 138.855)" class="st0 st1 st2">Kartik</text> <text transform="matrix(1 0 0 1 61.7622 159.8193)" class="st0 st1 st3">%version%</text> @@ -123,6 +123,6 @@ <rect x="638" y="0" class="st4" width="43.4" height="443"/> <rect x="-709.8" y="0" class="st4" width="711.8" height="443"/> <rect x="-42" y="-441" class="st4" width="711.8" height="443"/> -<image style="overflow:visible;" width="1080" height="1080" xlink:href="C:\Users\Minteck\Desktop\1.png" transform="matrix(4.612159e-02 0 0 4.612159e-02 540.8679 295.5552)"> +<image style="overflow:visible;" width="1080" height="1080" xlink:href="./loader/logo.png" transform="matrix(4.612159e-02 0 0 4.612159e-02 540.8679 295.5552)"> </image> </svg> diff --git a/views/loader/back.png b/views/loader/back.png Binary files differnew file mode 100644 index 0000000..4d268cc --- /dev/null +++ b/views/loader/back.png diff --git a/views/loader/logo.png b/views/loader/logo.png Binary files differnew file mode 100644 index 0000000..09112ca --- /dev/null +++ b/views/loader/logo.png diff --git a/views/menu.css b/views/menu.css index 2c2b94f..ca90e93 100644 --- a/views/menu.css +++ b/views/menu.css @@ -151,4 +151,74 @@ .item-icon { filter: invert(1); vertical-align: middle; +} + +div.services.home { + top: 115px; + padding: 0; + display: flex; + align-items: center; + bottom: 70px; + z-index: 9999; +} + +div.services.home > div.items > ul > li > span.item { + width: 216px; + border-radius: 0; +} + +div.services.home > div.items > ul > li > span.item > a { + margin-left: 10px; + margin-right: 10px; + width: 100%; + display: inline-block; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; +} + +div.services.home > div.items { + width: 256px; +} + +div.services.home > div.items > ul { + padding: 0; +} + +div.services.home > div.items > ul > li { + list-style: none; +} + +div.services.home > div.items > ul > li > span.item { + margin-left: 10vw; + transition: none; +} + +img[alt="full-logo"] { + margin-left: calc(10vw + 37.5px) !important; + margin-top: 55px !important; + height: 56px !important; + z-index: 99999; + position: fixed; +} + +span#copyright { + bottom: 46px; + left: 10vw; + z-index: 9999; + color: rgba(255, 255, 255, 0.75); + right: unset; + width: 227px; + text-align: center; +} + +#services-background { + position: fixed; + top: 0; + bottom: 0; + width: 227px; + z-index: 9; + backdrop-filter: blur(10px); + background: rgba(0, 0, 0, 0.5); + left: 10vw; }
\ No newline at end of file diff --git a/views/menu.html b/views/menu.html index d00107c..26e79db 100644 --- a/views/menu.html +++ b/views/menu.html @@ -11,6 +11,7 @@ <title>Kartik</title> <script src="../crash/client.js"></script> <script src="./script/global_compatlayer.js"></script> + <script src="./script/menu_login.js"></script> <script src="../sfx/sfx.js"></script> <link rel="stylesheet" href="rain/rainstyle.css"> <script> @@ -29,14 +30,16 @@ </script> <div id="box" style="display: none;background:#222;position:fixed;top:0;left:0;right:0;bottom:0;"> + <div id="loggingIn" style="position: fixed;color: white;background: rgba(0, 0, 0, .5);z-index: 999999999999;top: 0;left: 0;right: 0;bottom: 0;display: none;align-items: center;justify-content: center;backdrop-filter: blur(10px);"><script>document.write(lang.polymer.logging);</script></div> + <div class="rain front-row"></div> <div class="rain back-row"></div> - <div style="width: 100%;height: 100%;background-color: #001743;background-image: url('./menu.jpg');background-size: cover;position: fixed;z-index: -1;"> - <img alt="full-logo" src="../logo/full.png" style="margin-left: 50px;margin-top: 30px;height: 96px;"> - </div> + <div style="width: 100%;height: 100%;background-color: #001743;background-image: url('./menu.jpg');background-size: cover;position: fixed;z-index: -1;"></div> + <img alt="full-logo" src="../logo/full.png" style="margin-left: 50px;margin-top: 30px;height: 96px;"> + <div id="services-background"></div> - <div class="services"> + <div class="services home"> <div class="items"> <ul> <li class="selected"><span class="item"><a href="#" id="single"><img class="item-icon" src="../icons/singleplayer.svg"> <script>document.write(lang.menu.titles[0])</script></a></span></li> @@ -57,7 +60,7 @@ </div> </div> - <div style="position: fixed;right: 16px;top: 16px;color: white;background: rgba(0, 0, 0, .5);font-size: 10px;text-align:left;z-index:999999999;padding: 10px;border-radius: 10px;width: 189px;" id="gpuinfo"> + <div style="position: fixed;right: 16px;top: 79px;color: white;background: rgba(0, 0, 0, .5);font-size: 10px;text-align:left;z-index:999999999;padding: 10px;border-radius: 10px;width: 189px;" id="gpuinfo"> <span style="text-align:center;display:block;font-weight: bold;margin-bottom: 5px;">GPU Support Status</span> <div style="margin-bottom: 10px;height: 16px;width: 100%;background: rgba(47, 47, 47, .5);border-radius: 999px;"> <div style="height: 16px;background: rgba(128, 0, 0, .5);border-radius: 999px;width: 0;" id="gpuinfo_progressbar"></div> @@ -82,6 +85,27 @@ </script> </div> + <div style="position: fixed;right: 16px;top: 16px;height:28px;color: white;backdrop-filter:blur(10px);background: rgba(0, 0, 0, .5);font-size: 10px;z-index:999999999;padding: 10px;border-radius: 10px;width: 189px;text-align:center;" id="loginIntro-outer"> + <span id="loginIntro" style="padding-top: 10px;display: inline-block;"><script>document.write(lang.polymer.loginIntro);</script></span> + </div> + + <div style="position: fixed;right: 16px;top: 16px;color: white;background: rgba(0, 0, 0, .5);font-size: 10px;z-index:999999999;padding-left: 10px;border-radius: 10px;width: 199px;text-align:center;display: none;backdrop-filter: blur(10px);grid-template-columns: 1fr 48px;" id="loginUser"><div style=" + text-align: left; + padding-top: 13px; + padding-left: 5px; + font-size: 14px; +"><b id="kto-username">Username</b><br><span><script>document.write(lang.polymer.ktoLevel)</script> <span id="kto-level">0</span></span></div><img style=" + border-bottom-right-radius: 10px; + height: 48px; + background: rgba(0, 0, 0, .25); + display: inline-block; + width: 48px; + border: none; + border-top-right-radius: 10px; + outline: none; +" alt=" " id="kto-picture"> + </div> + <span id="copyright">© <script src="./script/menu_copyright.js"></script></span> </div> 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 diff --git a/views/stats.html b/views/stats.html index dcb4275..018e164 100644 --- a/views/stats.html +++ b/views/stats.html @@ -29,7 +29,7 @@ <div id="box" style="display: none;background:#222;position:fixed;top:0;left:0;right:0;bottom:0;"> <div style="position:fixed;top:0;left:0;right:0;bottom:0;display:flex;align-items:center;justify-content:center;"> <div style="text-align: center;"> - <h2><script>const homedir = require('@electron/remote').getCurrentWindow().homedir;document.write(lang.stats.title);stats=require(homedir + "/.kartik/stats.json")</script></h2> + <h2><script>let homedir = require('@electron/remote').getCurrentWindow().homedir;document.write(lang.stats.title);stats=require(homedir + "/.kartik/stats.json")</script></h2> <div style="display:grid;grid-template-columns: 1fr 1fr;"> <div style="padding:10px;text-align:left;"><b><script>document.write(lang.stats.items['times.single'])</script></b></div> |