From 2a5eadc8cf14dd7432bc9f9e8d2b19682208ef9f Mon Sep 17 00:00:00 2001 From: choelzl Date: Tue, 8 Feb 2022 15:59:11 +0100 Subject: [PATCH] WIP --- twitch/chatguessr.js | 7 +++- web/chatguessr/{SRC_CG.js => SRC} | 26 ++++++++++++-- web/chatguessr/index.html | 4 +-- web/chatguessr/index.js | 60 +++++++------------------------ web/js/socketWrapper.js | 2 +- 5 files changed, 46 insertions(+), 53 deletions(-) rename web/chatguessr/{SRC_CG.js => SRC} (97%) diff --git a/twitch/chatguessr.js b/twitch/chatguessr.js index 3f5f9a4..fec3bb2 100644 --- a/twitch/chatguessr.js +++ b/twitch/chatguessr.js @@ -16,7 +16,7 @@ function DBAddG(user,position) { if(guesses[user] && guesses[user].length > 0){ - }else{ + }else if(isCoordinates(position)){ guesses[user] = position; $.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses)); sendData('guesses',guesses); @@ -31,6 +31,11 @@ })); } + function isCoordinates(coordinates) { + const regex = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/g; + return regex.test(coordinates); + }; + $.bind('command', function(event) { const sender = "" + event.getSender().toLowerCase(), diff --git a/web/chatguessr/SRC_CG.js b/web/chatguessr/SRC similarity index 97% rename from web/chatguessr/SRC_CG.js rename to web/chatguessr/SRC index 0b50d24..0c9f640 100644 --- a/web/chatguessr/SRC_CG.js +++ b/web/chatguessr/SRC @@ -28,7 +28,7 @@ class GameHandler { // Browser Listening this.win.webContents.on("did-navigate-in-page", (e, url) => { - if (GameHelper.isGameURL(url)) { + if (isGameURL(url)) { game.start(url, settings.isMultiGuess).then(() => { this.win.webContents.send("game-started", game.isMultiGuess); TMI.action(`${game.round == 1 ? "🌎 A new seed of " + game.mapName : "🌎 Round " + game.round} has started`); @@ -111,7 +111,11 @@ window.addEventListener("DOMContentLoaded", () => { const head = document.getElementsByTagName("head")[0]; - + const styles = document.createElement("link"); + styles.rel = "stylesheet"; + styles.type = "text/css"; + styles.href = `${path.join(__dirname, "./public/styles.css")}`; + head.appendChild(styles); const scoreboardContainer = document.createElement("div"); scoreboardContainer.setAttribute("id", "scoreboardContainer"); @@ -140,7 +144,25 @@ window.addEventListener("DOMContentLoaded", () => { `; document.body.appendChild(scoreboardContainer); + const flagIcon = document.createElement("link"); + flagIcon.rel = "stylesheet"; + flagIcon.type = "text/css"; + flagIcon.href = `${path.join(__dirname, "./public/flag-icon.min.css")}`; + head.appendChild(flagIcon); + const jqueryUI = document.createElement("script"); + jqueryUI.type = "text/javascript"; + jqueryUI.src = `${path.join(__dirname, "./public/jquery-ui.min.js")}`; + jqueryUI.addEventListener("load", () => loadDatatables()); + document.body.appendChild(jqueryUI); + + const loadDatatables = () => { + const datatables = document.createElement("script"); + datatables.type = "text/javascript"; + datatables.src = `${path.join(__dirname, "./public/datatables.bundle.min.js")}`; + datatables.addEventListener("load", () => init()); + document.body.appendChild(datatables); + }; const init = () => { const markerRemover = document.createElement("style"); diff --git a/web/chatguessr/index.html b/web/chatguessr/index.html index d416c05..846180a 100644 --- a/web/chatguessr/index.html +++ b/web/chatguessr/index.html @@ -13,13 +13,13 @@ -
+
-
+
diff --git a/web/chatguessr/index.js b/web/chatguessr/index.js index 3caa3e6..a71db44 100644 --- a/web/chatguessr/index.js +++ b/web/chatguessr/index.js @@ -43,26 +43,6 @@ $(function () { } const refreshUI = () => { - // if(queryMap.getOrElse('single',false)){ - // $('#all').show(); $('#timer').hide(); $('#goal').hide(); - // $('#follow').parent().closest('div').hide(); $('#subscribe').parent().closest('div').hide(); $('#donate').parent().closest('div').hide(); - // if(queryMap.getOrElse('follow',false)) $('#follow').parent().closest('div').show(); - // if(queryMap.getOrElse('subscribe',false)) $('#subscribe').parent().closest('div').show(); - // if(queryMap.getOrElse('donate',false)) $('#donate').parent().closest('div').show(); - // }else if(queryMap.getOrElse('goal',false)){ - // $('#all').hide(); $('#timer').hide(); $('#goal').show(); - // $('#cfollow').parent().closest('div').hide(); $('#csubscribe').parent().closest('div').hide(); - // if(queryMap.getOrElse('follow',false)) $('#cfollow').parent().closest('div').show(); - // if(queryMap.getOrElse('subscribe',false)) $('#csubscribe').parent().closest('div').show(); - // } - - // $('#follow').text(lastFollow); - // $('#subscribe').text(lastSub); - // $('#donate').text(lastDonator); - // $('#cfollow').parent().closest('div').progressbar({ value : countFollow/parseInt(queryMap.getOrElse('follow',9999))*100 }); - // $('#csubscribe').parent().closest('div').progressbar({ value : countSub/parseInt(queryMap.getOrElse('subscribe',9999))*100}); - // $('#cfollow').text(`${countFollow} / ${queryMap.getOrElse('follow',9999)}`); - // $('#csubscribe').text(`${countSub} / ${queryMap.getOrElse('subscribe',9999)}`); } const handleSocketMessage = (e)=>{ @@ -76,15 +56,7 @@ $(function () { console.log(message.eventType, message.data) if(message.eventType == 'follow') { - lastFollow = message.data || lastFollow; - countFollow++; } else if(message.eventType == 'subscribe') { - lastSub = message.data || lastSub; - countSub++; - } else if(message.eventType == 'donation') { - lastDonator = message.data || lastDonator; - } else if(message.eventType == 'timer') { - console.log("New timer !! ", message.data) } refreshUI(); } catch (ex) { @@ -101,26 +73,20 @@ $(function () { while(socket.getReadyState() === 0){ await new Promise(r => setTimeout(r, 500)); } - // socket.getDBValue("get_current_stream_info_lastFollow", 'streamInfo', 'lastFollow', (response)=>{ - // if(response.streamInfo) lastFollow = response.streamInfo || lastFollow; - // refreshUI(); - // }) - // socket.getDBValue("get_current_stream_info_lastSub", 'streamInfo', 'lastSub', (response)=>{ - // if(response.streamInfo) lastSub = response.streamInfo || lastSub; - // refreshUI(); - // }) - // socket.getDBValue("get_current_stream_info_lastDonator", 'streamInfo', 'lastDonator', (response)=>{ - // if(response.streamInfo) lastDonator = response.streamInfo || lastDonator; - // refreshUI(); - // }) - // socket.getDBValue('get_current_stream_info_counts', 'panelData', 'stream', (e)=>{ - // let data = JSON.parse(e.panelData); - // countFollow = data.followers || countFollow; - // countSub = 0; - // refreshUI(); - // }) } }catch(e) {console.log(e)} }) -}); \ No newline at end of file +}); + +const calculateScale = (bounds) => haversineDistance({ lat: bounds.min.lat, lng: bounds.min.lng }, { lat: bounds.max.lat, lng: bounds.max.lng }) / 7.458421; +const haversineDistance = (mk1, mk2) => { + const R = 6371.071; + const rlat1 = mk1.lat * (Math.PI / 180); + const rlat2 = mk2.lat * (Math.PI / 180); + const difflat = rlat2 - rlat1; + const difflon = (mk2.lng - mk1.lng) * (Math.PI / 180); + const km = 2 * R * Math.asin(Math.sqrt(Math.sin(difflat / 2) * Math.sin(difflat / 2) + Math.cos(rlat1) * Math.cos(rlat2) * Math.sin(difflon / 2) * Math.sin(difflon / 2))); + return km; +}; +const calculateScore = (distance, scale) => Math.round(5000 * Math.pow(0.99866017, (distance * 1000) / scale)); \ No newline at end of file diff --git a/web/js/socketWrapper.js b/web/js/socketWrapper.js index fa6c78d..4af6132 100644 --- a/web/js/socketWrapper.js +++ b/web/js/socketWrapper.js @@ -58,7 +58,7 @@ $(function() { - var webSocket = new ReconnectingWebSocket((getProtocol() === 'https://' || window.location.protocol === 'https:' ? 'wss://' : 'ws://') + window.location.host + '/ws/panel', null, { reconnectInterval: 500 }), + var webSocket = new ReconnectingWebSocket((getProtocol() === 'https://' || window.location.protocol === 'https:' ? 'wss://' : 'ws://') + 'twitchbot.helcel.net' + '/ws/panel', null, { reconnectInterval: 500 }), callbacks = [], listeners = [], familyHandlers = {},
#UserDistanceScore