diff --git a/fx.bundle.js b/fx.bundle.js index ea6d056..790a094 100644 --- a/fx.bundle.js +++ b/fx.bundle.js @@ -1,2 +1,2 @@ const dictionary = {"gIsTeamGame":"iN","game":"a1","playerId":"e2","playerData":"aV","playerNames":"a1G","gameState":"v9","fontSize":"fontSize","x":"eP","y":"eR","canvas":"h1","gHumans":"jN","playerStates":"yb","fontGeneratorFunction":"b2.ow.q5","rawPlayerNames":"w2","playerBalances":"gK","playerTerritories":"g6","gIsSingleplayer":"jn","gLobbyMaxJoin":"st","SingleplayerMenu":"aO","getSingleplayerPlayerCount":"zd","gMaxPlayers":"eF","gBots":"jk","strs":"a5M","uiSizes":"bR","gap":"gap","i":"z"}; -(()=>{"use strict";function e(e){const t=document.createElement("p");t.innerText="Attack Percentage Keybinds";const n=document.createElement("div");n.className="arrayinput";const o=document.createElement("button");return o.innerText="Add",e.append(t,n,o),this.container=n,this.keys=["key","type","value"],this.objectArray=[],this.addObject=function(){this.objectArray.push({key:"",type:"absolute",value:.8}),this.displayObjects(),o.scrollIntoView(!1)},this.update=function(e){this.objectArray=e.attackPercentageKeybinds,this.displayObjects()},o.addEventListener("click",this.addObject.bind(this)),this.displayObjects=function(){if(this.container.innerHTML="",0===this.objectArray.length)return this.container.innerText="No custom attack percentage keybinds added";for(var e=0;eAbsolute',o.addEventListener("change",this.updateObject.bind(this,e,n));else if("key"===n)o.type="text",o.setAttribute("readonly",""),o.setAttribute("placeholder","No key set"),o.addEventListener("click",this.startKeyInput.bind(this,e,n));else{const t="absolute"===this.objectArray[e].type;o.type=t?"text":"number",t?o.addEventListener("click",this.convertIntoNumberInput.bind(this,e,n),{once:!0}):o.setAttribute("step","0.1"),o.addEventListener("input",this.updateObject.bind(this,e,n))}"value"===n&&"absolute"===this.objectArray[e].type?o.value=100*this.objectArray[e][n]+"%":o.value=this.objectArray[e][n],t.appendChild(o)}),this);var n=document.createElement("button");n.textContent="Delete",n.addEventListener("click",this.deleteObject.bind(this,e)),t.appendChild(n),this.container.appendChild(t)}},this.startKeyInput=function(e,t,n){n.target.value="Press any key";const o=this.updateObject.bind(this,e,t);n.target.addEventListener("keydown",o,{once:!0}),n.target.addEventListener("blur",(()=>{n.target.removeEventListener("keydown",o),n.target.value=this.objectArray[e][t]}),{once:!0})},this.convertIntoNumberInput=function(e,t,n){n.target.value=n.target.value.slice(0,-1),n.target.type="number",n.target.addEventListener("blur",(()=>{this.displayObjects()}),{once:!0})},this.updateObject=function(e,t,n){if(e>=this.objectArray.length)return;const o="value"===t?"absolute"===this.objectArray[e].type?parseFloat(n.target.value)/100:parseFloat(n.target.value):"key"===t?n.key:n.target.value;this.objectArray[e][t]=o,"key"===t&&this.displayObjects()},this.deleteObject=function(e){this.objectArray.splice(e,1),this.displayObjects()},this}const t={count:0,removeWins:function(){confirm("Do you really want to reset your wins?")&&(t.count=0,localStorage.removeItem("fx_winCount"),alert("Successfully reset wins"))}};null!==localStorage.getItem("fx_winCount")&&(t.count=localStorage.getItem("fx_winCount"));const n=t;var o={};const a=document.getElementById("windowContainer");function i(e){o[e.name]=e,o[e.name].isOpen=!1}function s(e){!1!==o[e].isOpen&&(o[e].isOpen=!1,o[e].element.style.display="none",void 0!==o[e].onClose&&o[e].onClose())}function l(){Object.values(o).forEach((function(e){!1!==e.closable&&s(e.name)}))}document.addEventListener("mousedown",(e=>{a.contains(e.target)||l()}),{passive:!0,capture:!0}),document.getElementById("canvasA").addEventListener("touchstart",l,{passive:!0}),document.addEventListener("keydown",(e=>{"Escape"===e.key&&l()}));const r={create:function(e){const t=document.createElement("div");return e.element=t,t.className="window"+(void 0!==e.classes?" "+e.classes:" scrollable selectable"),t.style.display="none",a.appendChild(t),i(e),t},add:i,openWindow:function(e,...t){!0!==o[e].isOpen&&(void 0!==o[e].beforeOpen&&o[e].beforeOpen(...t),o[e].isOpen=!0,o[e].element.style.display=null)},closeWindow:s,closeAll:l};window.__fx=window.__fx||{};const c=window.__fx;var d={displayWinCounter:!0,useFullscreenMode:!1,hoveringTooltip:!0,realisticNames:!1,showPlayerDensity:!0,coloredDensity:!0,densityDisplayStyle:"percentage",highlightClanSpawns:!1,customBackgroundUrl:"",attackPercentageKeybinds:[]};c.settings=d;const u=["hideAllLinks","fontName"];c.makeMainMenuTransparent=!1;const h=new function(){const t=[{for:"displayWinCounter",type:"checkbox",label:"Display win counter",note:"The win counter tracks multiplayer solo wins (not in team games)"},{type:"button",text:"Reset win counter",action:n.removeWins},{for:"useFullscreenMode",type:"checkbox",label:"Use fullscreen mode",note:"Note: fullscreen mode will trigger after you click anywhere on the page due to browser policy restrictions."},{for:"hoveringTooltip",type:"checkbox",label:"Hovering tooltip",note:"Display map territory info constantly (on mouse hover) instead of only when right clicking on the map"},{for:"realisticNames",type:"checkbox",label:"Realistic Bot Names"},{for:"showPlayerDensity",type:"checkbox",label:"Show player density"},{for:"coloredDensity",type:"checkbox",label:"Colored density",note:"Display the density with a color between red and green depending on the density value"},{for:"densityDisplayStyle",type:"selectMenu",label:"Density value display style:",tooltip:"Controls how the territorial density value should be rendered",options:[{value:"percentage",label:"Percentage"},{value:"absoluteQuotient",label:"Value from 0 to 150 (BetterTT style)"}]},{for:"highlightClanSpawns",type:"checkbox",label:"Highlight clan spawnpoints",note:"Increases the spawnpoint glow size for members of your clan"},{for:"customBackgroundUrl",type:"textInput",label:"Custom main menu background:",placeholder:"Enter an image URL here",tooltip:"A custom image to be shown as the main menu background instead of the currently selected map."},e],o=document.querySelector(".settings .scrollable");var a={},i={},s=[];t.forEach((e=>{if("function"==typeof e){const t=document.createElement("div");return s.push(new e(t)),o.append(t)}const t=document.createElement("label");e.tooltip&&(t.title=e.tooltip);const n=e.type.endsWith("Input"),l=document.createElement(n||"checkbox"===e.type?"input":"selectMenu"===e.type?"select":"button");if("textInput"===e.type&&(l.type="text"),e.placeholder&&(l.placeholder=e.placeholder),(n||"selectMenu"===e.type)&&(a[e.for]=l),e.text&&(l.innerText=e.text),e.action&&l.addEventListener("click",e.action),e.label&&t.append(e.label+" "),e.note){const n=document.createElement("small");n.innerText=e.note,t.append(document.createElement("br"),n)}if(e.options&&e.options.forEach((e=>{const t=document.createElement("option");t.setAttribute("value",e.value),t.innerText=e.label,l.append(t)})),t.append(l),"checkbox"===e.type){l.type="checkbox";const n=document.createElement("span");n.className="checkmark",t.className="checkbox",t.append(n),i[e.for]=l}else t.append(document.createElement("br"));o.append(t,document.createElement("br"))})),this.save=function(){Object.keys(a).forEach((function(e){d[e]=a[e].value.trim()})),Object.keys(i).forEach((function(e){d[e]=i[e].checked})),this.applySettings(),r.closeWindow("settings"),u.forEach((e=>delete d[e])),localStorage.setItem("fx_settings",JSON.stringify(d)),window.location.reload()};const l=document.createElement("input");function h(e){const t=e.target,n=t.files[0];if(!n)return;if(t.removeEventListener("change",h),t.value="",!n.name.endsWith(".json"))return alert("Invalid file format");const o=new FileReader;o.onload=function(){let e;try{e=JSON.parse(o.result),confirm('Warning: This will override all current settings, click "OK" to confirm')&&(c.settings=d=e),localStorage.setItem("fx_settings",JSON.stringify(d)),window.location.reload()}catch(e){alert("Error\n"+e)}},o.readAsText(n)}l.type="file",this.importFromFile=function(){l.click(),l.addEventListener("change",h)},this.exportToFile=function(){var e,t,n;e=JSON.stringify(d),t=document.createElement("a"),n=new Blob([e],{type:"application/json"}),t.href=URL.createObjectURL(n),t.download="FX_client_settings.json",t.click(),URL.revokeObjectURL(t.href)},this.syncFields=function(){Object.keys(a).forEach((function(e){a[e].value=d[e]})),Object.keys(i).forEach((function(e){i[e].checked=d[e]})),s.forEach((e=>e.update(d)))},this.resetAll=function(){confirm("Are you Really SURE you want to RESET ALL SETTINGS back to the default?")&&(localStorage.removeItem("fx_settings"),window.location.reload())},this.applySettings=function(){if(d.useFullscreenMode&&document.fullscreenEnabled){function e(){null===document.fullscreenElement&&document.documentElement.requestFullscreen({navigationUI:"hide"}).then((()=>{console.log("Fullscreen mode activated")})).catch((e=>{console.warn("Could not enter fullscreen mode:",e)}))}document.addEventListener("mousedown",e,{once:!0}),document.addEventListener("click",e,{once:!0})}""!==d.customBackgroundUrl&&(document.body.style.backgroundImage="url("+d.customBackgroundUrl+")",document.body.style.backgroundSize="cover",document.body.style.backgroundPosition="center"),c.makeMainMenuTransparent=""!==d.customBackgroundUrl}};r.add({name:"settings",element:document.querySelector(".settings"),beforeOpen:function(){h.syncFields()}}),null!==localStorage.getItem("fx_settings")&&(c.settings=d={...d,...JSON.parse(localStorage.getItem("fx_settings"))}),h.applySettings();const p=h;function y(){return d}const m=["playerTerritories","playerBalances","rawPlayerNames"],b=["playerId","gIsTeamGame","gHumans","gLobbyMaxJoin","gameState","gIsSingleplayer"],f=e=>m.includes(e)?window[dictionary.playerData]?.[dictionary[e]]:b.includes(e)?window[dictionary.game]?.[dictionary[e]]:window[dictionary[e]],g=new function(){this.playersToInclude=[],this.tabLabels=["ALL","CLAN"],this.filteredLeaderboard=[],this.tabBarOffset=0,this.windowWidth=0,this.verticalClickThreshold=1e3,this.hoveringOverTabs=!1,this.scrollToTop=()=>{},this.repaintLeaderboard=()=>{},this.setUpdateFlag=()=>{},this.parseClanFromPlayerName=()=>{console.warn("parse function not set")},this.selectedTab=0,this.tabHovering=-1,this.enabled=!1,this.drawTabs=function(e,t,n,o){e.textBaseline="middle",e.textAlign="center";const a=t/this.tabLabels.length,i=n+this.tabBarOffset/2;this.tabLabels.forEach(((t,s)=>{0!==s&&e.fillRect(a*s,n,1,this.tabBarOffset),this.selectedTab===s&&(e.fillStyle=o,e.fillRect(a*s,n,a,this.tabBarOffset),e.fillStyle="rgb(255,255,255)"),this.tabHovering===s&&(e.fillStyle="rgba(255,255,255,0.3)",e.fillRect(a*s,n,a,this.tabBarOffset),e.fillStyle="rgb(255,255,255)"),e.fillText(t,a*s+a/2,i)}))},this.setHovering=(e,t)=>{let n=!1;if(e){const e=Math.floor(t/(this.windowWidth/this.tabLabels.length));this.tabHovering!==e&&(this.tabHovering=e,n=!0)}return e!==this.hoveringOverTabs&&(this.hoveringOverTabs=e,!1===e&&(this.tabHovering=-1),e||(n=!0)),n&&this.repaintLeaderboard(),e},this.handleMouseDown=e=>{const t=Math.floor(e/(this.windowWidth/this.tabLabels.length));return this.selectedTab!==t&&(this.selectedTab=t,0===this.selectedTab?this.clearFilter():1===this.selectedTab&&(this.filterByOwnClan(),this.setUpdateFlag()),this.repaintLeaderboard()),!0},this.filterByOwnClan=()=>{this.playersToInclude=[];const e=f("playerId"),t=this.parseClanFromPlayerName(f("rawPlayerNames")[e]);f("rawPlayerNames").forEach(((n,o)=>{o!==e&&this.parseClanFromPlayerName(n)!==t||this.playersToInclude.push(o)})),this.enabled=!0,this.scrollToTop()},this.clearFilter=()=>{this.enabled=!1},this.reset=()=>{this.enabled=!1,this.selectedTab=0,v.refresh()}},v=new function(){this.inOwnClan=new Array(512),this.inOwnClan.fill(!1),this.refresh=()=>{const e=f("gHumans"),t=g.parseClanFromPlayerName(f("rawPlayerNames")[f("playerId")]);null===t?this.inOwnClan.fill(!1):f("rawPlayerNames").forEach(((n,o)=>{this.inOwnClan[o]=o/g,">").replace(/"/g,""").replace(/'/g,"'")}r.add({name:"donationHistory",element:document.querySelector("#donationhistory"),beforeOpen:function(e){document.getElementById("donationhistory_note").style.display="none"},onClose:function(){E.openedWindowPlayerID=null}});const E=new function(){function e(e,t,n,o){const a=f("rawPlayerNames"),i=document.createElement("tr");o&&i.setAttribute("class","new");let s=`${t}. `;return n===e[1]?s+=`Received ${e[2]} resources from ${w(a[e[0]])}`:s+=`Sent ${e[2]} resources to ${w(a[e[1]])}`,s+="",i.innerHTML=s,i}this.openedWindowPlayerID=null,this.contentElement=document.querySelector("#donationhistory_content"),this.donationHistory=Array(512),this.getHistoryOf=function(e){return this.donationHistory[e].toReversed()},this.reset=function(){for(var e=0;e<512;e++)this.donationHistory[e]=[]},this.logDonation=function(t,n,o){const a=[t,n,o];if(this.donationHistory[n].push(a),this.donationHistory[t].push(a),this.openedWindowPlayerID===t||this.openedWindowPlayerID===n){const o=this.donationHistory[this.openedWindowPlayerID===t?t:n].length;this.contentElement.prepend(e(a,o,this.openedWindowPlayerID,!0))}},this.displayHistory=function(t,n=f("rawPlayerNames"),o=f("gIsSingleplayer")){var a=E.getHistoryOf(t);console.log("History for "+n[t]+":"),console.log(a),document.querySelector("#donationhistory h1").innerHTML="Donation history for "+w(n[t]),this.contentElement.innerHTML="",a.length>0?a.forEach(((n,o)=>{this.contentElement.appendChild(e(n,a.length-o,t))})):this.contentElement.innerText="Nothing to display",this.openedWindowPlayerID=t,r.openWindow("donationHistory",o)}},k=E,L=new function(){const e=document.createElement("img");e.setAttribute("src","assets/players_icon.png"),document.getElementById("playerlist_content").addEventListener("click",(e=>{const t=e.target.closest("tr[data-player-id]")?.getAttribute("data-player-id");t&&f("gIsTeamGame")&&(r.closeWindow("playerList"),k.displayHistory(t))})),this.display=function(e){const t=f("gHumans"),n=f("gLobbyMaxJoin");let o=`

Players (${t})

`;for(let a=0;aBots (${n-t})`),o+=`${a+1}. ${w(e[a])}`;document.getElementById("playerlist_content").innerHTML=o,document.getElementById("playerlist_content").setAttribute("class",f("gIsTeamGame")?"clickable":""),r.openWindow("playerList")},this.hoveringOverButton=!1,this.drawButton=(t,n,o,a)=>{t.fillRect(n,o,a,a),t.fillStyle=this.hoveringOverButton?"#aaaaaaaa":"#000000aa",t.clearRect(n+1,o+1,a-2,a-2),t.fillRect(n+1,o+1,a-2,a-2),t.fillStyle="#ffffff",t.imageSmoothingEnabled=!0,t.drawImage(e,n+2,o+2,a-4,a-4),t.imageSmoothingEnabled=!1}};r.add({name:"playerList",element:document.getElementById("playerlist")});const x=L,T=new function(){this.getMaxTroops=function(e,t){return(150*e[t]).toString()},this.getDensity=function(e,t=f("playerBalances"),n=f("playerTerritories")){return"percentage"===y().densityDisplayStyle?(t[e]/(150*(0===n[e]?1:n[e]))*100).toFixed(1)+"%":(t[e]/(0===n[e]?1:n[e])).toFixed(1)},this.isPointInRectangle=function(e,t,n,o,a,i){return e>=n&&e<=n+a&&t>=o&&t<=o+i},this.fillTextMultiline=function(e,t,n,o,a){const i=parseInt(e.font.split(" ").find((e=>e.endsWith("px"))).slice(0,-2));t.split("\n").forEach(((t,s)=>e.fillText(t,n,o+s*i,a)))},this.textStyleBasedOnDensity=function(e){const t=f("playerBalances"),n=f("playerTerritories");return`hsl(${t[e]/(1.5*n[e])}, 100%, 50%, 1)`}},S=new function(){let e=!1;function t(t){if(!y().hoveringTooltip||!f("gameState")||e)return;let n,o;if(t.type.includes("touch")){const{touches:e,changedTouches:a}=t.originalEvent??t,i=e[0]??a[0];n=i.pageX,o=i.pageY}else t.type.includes("mouse")&&(n=t.clientX,o=t.clientY);e=!0;try{this.display(this.canvasPixelScale*n,this.canvasPixelScale*o)}catch(t){console.error(t)}setTimeout((()=>e=!1),100)}this.display=()=>{},this.canvasPixelScale=1,document.getElementById("canvasA").addEventListener("mousemove",t.bind(this)),document.getElementById("canvasA").addEventListener("touchstart",t.bind(this))},I={setAbsolute:()=>{},setRelative:()=>{}};let O=!1,A="",C=()=>{},B=()=>{},j=(e,t)=>{};const N=new TextEncoder,P=new TextDecoder;r.add({name:"lobbyJoinMenu",element:document.getElementById("customLobbyJoinMenu")});const M=r.create({name:"customLobby",classes:"scrollable selectable flex-column text-align-center",closable:!1}),F=document.createElement("h2");F.textContent="Custom Lobby";const H=document.createElement("div");H.className="customlobby-main";const W=document.createElement("div"),D=document.createElement("p");D.textContent="0 Players";const _=document.createElement("div");W.append(D,_);const R=document.createElement("div"),U=document.createElement("select");G([{value:0,label:"2 Teams"},{value:1,label:"3 Teams"},{value:2,label:"4 Teams"},{value:3,label:"5 Teams"},{value:4,label:"6 Teams"},{value:5,label:"7 Teams"},{value:6,label:"8 Teams"},{value:7,label:"Battle Royale"},{value:10,label:"No Fullsend Battle Royale"},{value:9,label:"Zombie mode"}],U),U.value="7";const J=document.createElement("select");U.addEventListener("change",(e=>X("options",["mode",parseInt(e.target.value)]))),J.addEventListener("change",(e=>X("options",["map",parseInt(e.target.value)]))),R.append("Mode: ",U,document.createElement("br"),"Map: ",J,document.createElement("br")),H.append(W,R);const $=document.createElement("footer");$.style.marginTop="10px";const q=document.createElement("button"),K=document.createElement("button");function G(e,t){e.forEach((e=>{const n=document.createElement("option");n.setAttribute("value",e.value),n.textContent=e.label,t.append(n)}))}function X(e,t){const n=void 0!==t?{t:e,d:t}:{t:e},o=N.encode(JSON.stringify(n)),a=new ArrayBuffer(o.length+1);new DataView(a).setUint8(0,120),new Uint8Array(a,1).set(o),j(1,a)}q.textContent="Start game",K.textContent="Leave lobby",q.addEventListener("click",(function(){r.closeWindow("customLobby"),X("startGame")})),K.addEventListener("click",(()=>B())),$.append(K,q),M.append(F,H,$),document.getElementById("lobbyCode").addEventListener("input",(({target:e})=>{5===e.value.length&&(A=e.value.toLowerCase(),e.value="",r.closeWindow("lobbyJoinMenu"),O=!0,C())})),document.getElementById("createLobbyButton").addEventListener("click",(()=>{A="",r.closeWindow("lobbyJoinMenu"),O=!0,C()}));let V=[];function z(e){const t=document.createElement("div");t.className="lobby-player",t.textContent=e.name,_.append(t),V.push(t),Y()}function Y(){D.textContent=`${V.length} Player${1===V.length?"":"s"}`}const Q={showJoinPrompt:function(){r.openWindow("lobbyJoinMenu")},isCustomMessage:function(e){if(120!==e[0])return!1;if(1===e.length)return!0;const t=new Uint8Array(e.buffer,1),n=JSON.parse(P.decode(t)),{t:o,d:a}=n;if("lobby"===o)r.openWindow("customLobby"),F.textContent="Custom Lobby "+a.code,A=a.code,U.value=a.options.mode.toString(),J.value=a.options.map.toString(),i=a.players,V=[],_.innerHTML="",i.forEach(z),Y();else if("addPlayer"===o)z(a);else if("removePlayer"===o){const e=a;V[e].remove(),V.splice(e,1),Y()}else if("options"===o){console.log(a);const[e,t]=a;"mode"===e?U.value=t.toString():"map"===e&&(J.value=t.toString())}var i;return!0},getSocketURL:function(){return"wss://fx.peshomir.workers.dev/"+(""===A?"create":"join?"+A)},setJoinFunction:function(e){C=e},setLeaveFunction:function(e){B=e},setSendFunction:function(e){j=e},setMapInfo:function(e){setTimeout((()=>G(e.map(((e,t)=>({value:t.toString(),label:e.name}))),J)),0)},isActive:()=>O,setActive:function(e){O=e,!1===e&&r.closeWindow("customLobby")}};window.__fx=window.__fx||{};const Z=window.__fx;Z.version="0.6.6.2 Oct 15",Z.settingsManager=p,Z.leaderboardFilter=g,Z.utils=T,Z.WindowManager=r,Z.keybindFunctions=I,Z.keybindHandler=e=>{const t=y().attackPercentageKeybinds.find((t=>t.key===e));return void 0!==t&&("absolute"===t.type?I.setAbsolute(t.value):I.setRelative(t.value),!0)},Z.donationsTracker=k,Z.playerList=x,Z.hoveringTooltip=S,Z.clanFilter=v,Z.wins=n,Z.customLobby=Q,console.log("Successfully loaded FX Client")})(); \ No newline at end of file +(()=>{"use strict";function e(e){const t=document.createElement("p");t.innerText="Attack Percentage Keybinds";const n=document.createElement("div");n.className="arrayinput";const o=document.createElement("button");return o.innerText="Add",e.append(t,n,o),this.container=n,this.keys=["key","type","value"],this.objectArray=[],this.addObject=function(){this.objectArray.push({key:"",type:"absolute",value:.8}),this.displayObjects(),o.scrollIntoView(!1)},this.update=function(e){this.objectArray=e.attackPercentageKeybinds,this.displayObjects()},o.addEventListener("click",this.addObject.bind(this)),this.displayObjects=function(){if(this.container.innerHTML="",0===this.objectArray.length)return this.container.innerText="No custom attack percentage keybinds added";for(var e=0;eAbsolute',o.addEventListener("change",this.updateObject.bind(this,e,n));else if("key"===n)o.type="text",o.setAttribute("readonly",""),o.setAttribute("placeholder","No key set"),o.addEventListener("click",this.startKeyInput.bind(this,e,n));else{const t="absolute"===this.objectArray[e].type;o.type=t?"text":"number",t?o.addEventListener("click",this.convertIntoNumberInput.bind(this,e,n),{once:!0}):o.setAttribute("step","0.1"),o.addEventListener("input",this.updateObject.bind(this,e,n))}"value"===n&&"absolute"===this.objectArray[e].type?o.value=100*this.objectArray[e][n]+"%":o.value=this.objectArray[e][n],t.appendChild(o)}),this);var n=document.createElement("button");n.textContent="Delete",n.addEventListener("click",this.deleteObject.bind(this,e)),t.appendChild(n),this.container.appendChild(t)}},this.startKeyInput=function(e,t,n){n.target.value="Press any key";const o=this.updateObject.bind(this,e,t);n.target.addEventListener("keydown",o,{once:!0}),n.target.addEventListener("blur",(()=>{n.target.removeEventListener("keydown",o),n.target.value=this.objectArray[e][t]}),{once:!0})},this.convertIntoNumberInput=function(e,t,n){n.target.value=n.target.value.slice(0,-1),n.target.type="number",n.target.addEventListener("blur",(()=>{this.displayObjects()}),{once:!0})},this.updateObject=function(e,t,n){if(e>=this.objectArray.length)return;const o="value"===t?"absolute"===this.objectArray[e].type?parseFloat(n.target.value)/100:parseFloat(n.target.value):"key"===t?n.key:n.target.value;this.objectArray[e][t]=o,"key"===t&&this.displayObjects()},this.deleteObject=function(e){this.objectArray.splice(e,1),this.displayObjects()},this}const t={count:0,removeWins:function(){confirm("Do you really want to reset your wins?")&&(t.count=0,localStorage.removeItem("fx_winCount"),alert("Successfully reset wins"))}};null!==localStorage.getItem("fx_winCount")&&(t.count=localStorage.getItem("fx_winCount"));const n=t;var o={};const a=document.getElementById("windowContainer");function s(e){o[e.name]=e,o[e.name].isOpen=!1}function i(e){!1!==o[e].isOpen&&(o[e].isOpen=!1,o[e].element.style.display="none",void 0!==o[e].onClose&&o[e].onClose())}function l(){Object.values(o).forEach((function(e){!1!==e.closable&&i(e.name)}))}document.addEventListener("mousedown",(e=>{a.contains(e.target)||l()}),{passive:!0,capture:!0}),document.getElementById("canvasA").addEventListener("touchstart",l,{passive:!0}),document.addEventListener("keydown",(e=>{"Escape"===e.key&&l()}));const r={create:function(e){const t=document.createElement("div");return e.element=t,t.className="window"+(void 0!==e.classes?" "+e.classes:" scrollable selectable"),t.style.display="none",a.appendChild(t),s(e),t},add:s,openWindow:function(e,...t){!0!==o[e].isOpen&&(void 0!==o[e].beforeOpen&&o[e].beforeOpen(...t),o[e].isOpen=!0,o[e].element.style.display=null)},closeWindow:i,closeAll:l};window.__fx=window.__fx||{};const c=window.__fx;var d={displayWinCounter:!0,useFullscreenMode:!1,hoveringTooltip:!0,realisticNames:!1,showPlayerDensity:!0,coloredDensity:!0,densityDisplayStyle:"percentage",highlightClanSpawns:!1,customBackgroundUrl:"",attackPercentageKeybinds:[]};c.settings=d;const u=["hideAllLinks","fontName"];c.makeMainMenuTransparent=!1;const h=new function(){const t=[{for:"displayWinCounter",type:"checkbox",label:"Display win counter",note:"The win counter tracks multiplayer solo wins (not in team games)"},{type:"button",text:"Reset win counter",action:n.removeWins},{for:"useFullscreenMode",type:"checkbox",label:"Use fullscreen mode",note:"Note: fullscreen mode will trigger after you click anywhere on the page due to browser policy restrictions."},{for:"hoveringTooltip",type:"checkbox",label:"Hovering tooltip",note:"Display map territory info constantly (on mouse hover) instead of only when right clicking on the map"},{for:"realisticNames",type:"checkbox",label:"Realistic Bot Names"},{for:"showPlayerDensity",type:"checkbox",label:"Show player density"},{for:"coloredDensity",type:"checkbox",label:"Colored density",note:"Display the density with a color between red and green depending on the density value"},{for:"densityDisplayStyle",type:"selectMenu",label:"Density value display style:",tooltip:"Controls how the territorial density value should be rendered",options:[{value:"percentage",label:"Percentage"},{value:"absoluteQuotient",label:"Value from 0 to 150 (BetterTT style)"}]},{for:"highlightClanSpawns",type:"checkbox",label:"Highlight clan spawnpoints",note:"Increases the spawnpoint glow size for members of your clan"},{for:"customBackgroundUrl",type:"textInput",label:"Custom main menu background:",placeholder:"Enter an image URL here",tooltip:"A custom image to be shown as the main menu background instead of the currently selected map."},e],o=document.querySelector(".settings .scrollable");var a={},s={},i=[];t.forEach((e=>{if("function"==typeof e){const t=document.createElement("div");return i.push(new e(t)),o.append(t)}const t=document.createElement("label");e.tooltip&&(t.title=e.tooltip);const n=e.type.endsWith("Input"),l=document.createElement(n||"checkbox"===e.type?"input":"selectMenu"===e.type?"select":"button");if("textInput"===e.type&&(l.type="text"),e.placeholder&&(l.placeholder=e.placeholder),(n||"selectMenu"===e.type)&&(a[e.for]=l),e.text&&(l.innerText=e.text),e.action&&l.addEventListener("click",e.action),e.label&&t.append(e.label+" "),e.note){const n=document.createElement("small");n.innerText=e.note,t.append(document.createElement("br"),n)}if(e.options&&e.options.forEach((e=>{const t=document.createElement("option");t.setAttribute("value",e.value),t.innerText=e.label,l.append(t)})),t.append(l),"checkbox"===e.type){l.type="checkbox";const n=document.createElement("span");n.className="checkmark",t.className="checkbox",t.append(n),s[e.for]=l}else t.append(document.createElement("br"));o.append(t,document.createElement("br"))})),this.save=function(){Object.keys(a).forEach((function(e){d[e]=a[e].value.trim()})),Object.keys(s).forEach((function(e){d[e]=s[e].checked})),this.applySettings(),r.closeWindow("settings"),u.forEach((e=>delete d[e])),localStorage.setItem("fx_settings",JSON.stringify(d)),window.location.reload()};const l=document.createElement("input");function h(e){const t=e.target,n=t.files[0];if(!n)return;if(t.removeEventListener("change",h),t.value="",!n.name.endsWith(".json"))return alert("Invalid file format");const o=new FileReader;o.onload=function(){let e;try{e=JSON.parse(o.result),confirm('Warning: This will override all current settings, click "OK" to confirm')&&(c.settings=d=e),localStorage.setItem("fx_settings",JSON.stringify(d)),window.location.reload()}catch(e){alert("Error\n"+e)}},o.readAsText(n)}l.type="file",this.importFromFile=function(){l.click(),l.addEventListener("change",h)},this.exportToFile=function(){var e,t,n;e=JSON.stringify(d),t=document.createElement("a"),n=new Blob([e],{type:"application/json"}),t.href=URL.createObjectURL(n),t.download="FX_client_settings.json",t.click(),URL.revokeObjectURL(t.href)},this.syncFields=function(){Object.keys(a).forEach((function(e){a[e].value=d[e]})),Object.keys(s).forEach((function(e){s[e].checked=d[e]})),i.forEach((e=>e.update(d)))},this.resetAll=function(){confirm("Are you Really SURE you want to RESET ALL SETTINGS back to the default?")&&(localStorage.removeItem("fx_settings"),window.location.reload())},this.applySettings=function(){if(d.useFullscreenMode&&document.fullscreenEnabled){function e(){null===document.fullscreenElement&&document.documentElement.requestFullscreen({navigationUI:"hide"}).then((()=>{console.log("Fullscreen mode activated")})).catch((e=>{console.warn("Could not enter fullscreen mode:",e)}))}document.addEventListener("mousedown",e,{once:!0}),document.addEventListener("click",e,{once:!0})}""!==d.customBackgroundUrl&&(document.body.style.backgroundImage="url("+d.customBackgroundUrl+")",document.body.style.backgroundSize="cover",document.body.style.backgroundPosition="center"),c.makeMainMenuTransparent=""!==d.customBackgroundUrl}};r.add({name:"settings",element:document.querySelector(".settings"),beforeOpen:function(){h.syncFields()}}),null!==localStorage.getItem("fx_settings")&&(c.settings=d={...d,...JSON.parse(localStorage.getItem("fx_settings"))}),h.applySettings();const p=h;function y(){return d}const m=["playerTerritories","playerBalances","rawPlayerNames"],b=["playerId","gIsTeamGame","gHumans","gLobbyMaxJoin","gameState","gIsSingleplayer"],f=e=>m.includes(e)?window[dictionary.playerData]?.[dictionary[e]]:b.includes(e)?window[dictionary.game]?.[dictionary[e]]:window[dictionary[e]],g=new function(){this.playersToInclude=[],this.tabLabels=["ALL","CLAN"],this.filteredLeaderboard=[],this.tabBarOffset=0,this.windowWidth=0,this.verticalClickThreshold=1e3,this.hoveringOverTabs=!1,this.scrollToTop=()=>{},this.repaintLeaderboard=()=>{},this.setUpdateFlag=()=>{},this.parseClanFromPlayerName=()=>{console.warn("parse function not set")},this.selectedTab=0,this.tabHovering=-1,this.enabled=!1,this.drawTabs=function(e,t,n,o){e.textBaseline="middle",e.textAlign="center";const a=t/this.tabLabels.length,s=n+this.tabBarOffset/2;this.tabLabels.forEach(((t,i)=>{0!==i&&e.fillRect(a*i,n,1,this.tabBarOffset),this.selectedTab===i&&(e.fillStyle=o,e.fillRect(a*i,n,a,this.tabBarOffset),e.fillStyle="rgb(255,255,255)"),this.tabHovering===i&&(e.fillStyle="rgba(255,255,255,0.3)",e.fillRect(a*i,n,a,this.tabBarOffset),e.fillStyle="rgb(255,255,255)"),e.fillText(t,a*i+a/2,s)}))},this.setHovering=(e,t)=>{let n=!1;if(e){const e=Math.floor(t/(this.windowWidth/this.tabLabels.length));this.tabHovering!==e&&(this.tabHovering=e,n=!0)}return e!==this.hoveringOverTabs&&(this.hoveringOverTabs=e,!1===e&&(this.tabHovering=-1),e||(n=!0)),n&&this.repaintLeaderboard(),e},this.handleMouseDown=e=>{const t=Math.floor(e/(this.windowWidth/this.tabLabels.length));return this.selectedTab!==t&&(this.selectedTab=t,0===this.selectedTab?this.clearFilter():1===this.selectedTab&&(this.filterByOwnClan(),this.setUpdateFlag()),this.repaintLeaderboard()),!0},this.filterByOwnClan=()=>{this.playersToInclude=[];const e=f("playerId"),t=this.parseClanFromPlayerName(f("rawPlayerNames")[e]);f("rawPlayerNames").forEach(((n,o)=>{o!==e&&this.parseClanFromPlayerName(n)!==t||this.playersToInclude.push(o)})),this.enabled=!0,this.scrollToTop()},this.clearFilter=()=>{this.enabled=!1},this.reset=()=>{this.enabled=!1,this.selectedTab=0,v.refresh()}},v=new function(){this.inOwnClan=new Array(512),this.inOwnClan.fill(!1),this.refresh=()=>{const e=f("gHumans"),t=g.parseClanFromPlayerName(f("rawPlayerNames")[f("playerId")]);null===t?this.inOwnClan.fill(!1):f("rawPlayerNames").forEach(((n,o)=>{this.inOwnClan[o]=o/g,">").replace(/"/g,""").replace(/'/g,"'")}r.add({name:"donationHistory",element:document.querySelector("#donationhistory"),beforeOpen:function(e){document.getElementById("donationhistory_note").style.display="none"},onClose:function(){E.openedWindowPlayerID=null}});const E=new function(){function e(e,t,n,o){const a=f("rawPlayerNames"),s=document.createElement("tr");o&&s.setAttribute("class","new");let i=`${t}. `;return n===e[1]?i+=`Received ${e[2]} resources from ${w(a[e[0]])}`:i+=`Sent ${e[2]} resources to ${w(a[e[1]])}`,i+="",s.innerHTML=i,s}this.openedWindowPlayerID=null,this.contentElement=document.querySelector("#donationhistory_content"),this.donationHistory=Array(512),this.getHistoryOf=function(e){return this.donationHistory[e].toReversed()},this.reset=function(){for(var e=0;e<512;e++)this.donationHistory[e]=[]},this.logDonation=function(t,n,o){const a=[t,n,o];if(this.donationHistory[n].push(a),this.donationHistory[t].push(a),this.openedWindowPlayerID===t||this.openedWindowPlayerID===n){const o=this.donationHistory[this.openedWindowPlayerID===t?t:n].length;this.contentElement.prepend(e(a,o,this.openedWindowPlayerID,!0))}},this.displayHistory=function(t,n=f("rawPlayerNames"),o=f("gIsSingleplayer")){var a=E.getHistoryOf(t);console.log("History for "+n[t]+":"),console.log(a),document.querySelector("#donationhistory h1").innerHTML="Donation history for "+w(n[t]),this.contentElement.innerHTML="",a.length>0?a.forEach(((n,o)=>{this.contentElement.appendChild(e(n,a.length-o,t))})):this.contentElement.innerText="Nothing to display",this.openedWindowPlayerID=t,r.openWindow("donationHistory",o)}},k=E,x=new function(){const e=document.createElement("img");e.setAttribute("src","assets/players_icon.png"),document.getElementById("playerlist_content").addEventListener("click",(e=>{const t=e.target.closest("tr[data-player-id]")?.getAttribute("data-player-id");t&&f("gIsTeamGame")&&(r.closeWindow("playerList"),k.displayHistory(t))})),this.display=function(e){const t=f("gHumans"),n=f("gLobbyMaxJoin");let o=`

Players (${t})

`;for(let a=0;aBots (${n-t})`),o+=`${a+1}. ${w(e[a])}`;document.getElementById("playerlist_content").innerHTML=o,document.getElementById("playerlist_content").setAttribute("class",f("gIsTeamGame")?"clickable":""),r.openWindow("playerList")},this.hoveringOverButton=!1,this.drawButton=(t,n,o,a)=>{t.fillRect(n,o,a,a),t.fillStyle=this.hoveringOverButton?"#aaaaaaaa":"#000000aa",t.clearRect(n+1,o+1,a-2,a-2),t.fillRect(n+1,o+1,a-2,a-2),t.fillStyle="#ffffff",t.imageSmoothingEnabled=!0,t.drawImage(e,n+2,o+2,a-4,a-4),t.imageSmoothingEnabled=!1}};r.add({name:"playerList",element:document.getElementById("playerlist")});const L=x,T=new function(){this.getMaxTroops=function(e,t){return(150*e[t]).toString()},this.getDensity=function(e,t=f("playerBalances"),n=f("playerTerritories")){return"percentage"===y().densityDisplayStyle?(t[e]/(150*(0===n[e]?1:n[e]))*100).toFixed(1)+"%":(t[e]/(0===n[e]?1:n[e])).toFixed(1)},this.isPointInRectangle=function(e,t,n,o,a,s){return e>=n&&e<=n+a&&t>=o&&t<=o+s},this.fillTextMultiline=function(e,t,n,o,a){const s=parseInt(e.font.split(" ").find((e=>e.endsWith("px"))).slice(0,-2));t.split("\n").forEach(((t,i)=>e.fillText(t,n,o+i*s,a)))},this.textStyleBasedOnDensity=function(e){const t=f("playerBalances"),n=f("playerTerritories");return`hsl(${t[e]/(1.5*n[e])}, 100%, 50%, 1)`}},S=new function(){let e=!1;function t(t){if(!y().hoveringTooltip||!f("gameState")||e)return;let n,o;if(t.type.includes("touch")){const{touches:e,changedTouches:a}=t.originalEvent??t,s=e[0]??a[0];n=s.pageX,o=s.pageY}else t.type.includes("mouse")&&(n=t.clientX,o=t.clientY);e=!0;try{this.display(this.canvasPixelScale*n,this.canvasPixelScale*o)}catch(t){console.error(t)}setTimeout((()=>e=!1),100)}this.display=()=>{},this.canvasPixelScale=1,document.getElementById("canvasA").addEventListener("mousemove",t.bind(this)),document.getElementById("canvasA").addEventListener("touchstart",t.bind(this))},I={setAbsolute:()=>{},setRelative:()=>{}};let O=!1,C="",A=()=>{},B=()=>{},N=(e,t)=>{};const j=new TextEncoder,P=new TextDecoder;r.add({name:"lobbyJoinMenu",element:document.getElementById("customLobbyJoinMenu")});const H=r.create({name:"customLobby",classes:"scrollable selectable flex-column text-align-center",closable:!1}),M=document.createElement("h2");M.textContent="Custom Lobby";const F=document.createElement("div");F.className="customlobby-main";const W=document.createElement("div"),D=document.createElement("p");D.textContent="0 Players";const _=document.createElement("div");W.append(D,_);const R=document.createElement("div"),U=document.createElement("select");G([{value:0,label:"2 Teams"},{value:1,label:"3 Teams"},{value:2,label:"4 Teams"},{value:3,label:"5 Teams"},{value:4,label:"6 Teams"},{value:5,label:"7 Teams"},{value:6,label:"8 Teams"},{value:7,label:"Battle Royale"},{value:10,label:"No Fullsend Battle Royale"},{value:9,label:"Zombie mode"}],U),U.value="7";const J=document.createElement("select");U.addEventListener("change",(e=>X("options",["mode",parseInt(e.target.value)]))),J.addEventListener("change",(e=>X("options",["map",parseInt(e.target.value)]))),R.append("Mode: ",U,document.createElement("br"),"Map: ",J,document.createElement("br")),F.append(W,R);const $=document.createElement("footer");$.style.marginTop="10px";const q=document.createElement("button"),K=document.createElement("button");function G(e,t){e.forEach((e=>{const n=document.createElement("option");n.setAttribute("value",e.value),n.textContent=e.label,t.append(n)}))}function X(e,t){const n=void 0!==t?{t:e,d:t}:{t:e},o=j.encode(JSON.stringify(n)),a=new ArrayBuffer(o.length+1);new DataView(a).setUint8(0,120),new Uint8Array(a,1).set(o),N(1,a)}q.textContent="Start game",K.textContent="Leave lobby",q.addEventListener("click",(function(){r.closeWindow("customLobby"),X("startGame")})),K.addEventListener("click",(()=>B())),$.append(q,K),H.append(M,F,$),document.getElementById("lobbyCode").addEventListener("input",(({target:e})=>{5===e.value.length&&(C=e.value.toLowerCase(),e.value="",r.closeWindow("lobbyJoinMenu"),O=!0,A())})),document.getElementById("createLobbyButton").addEventListener("click",(()=>{C="",r.closeWindow("lobbyJoinMenu"),O=!0,A()}));let V=[];function z(e){const t=document.createElement("div");t.className="lobby-player",t.textContent=e.name;const n=document.createElement("span");n.textContent="Host",n.className=e.isHost?"":"d-none",t.append(n),_.append(t),V.push({element:t,hostBadge:n}),Y()}function Y(){D.textContent=`${V.length} Player${1===V.length?"":"s"}`}const Q={showJoinPrompt:function(){r.openWindow("lobbyJoinMenu")},isCustomMessage:function(e){if(120!==e[0])return!1;if(1===e.length)return!0;const t=new Uint8Array(e.buffer,1),n=JSON.parse(P.decode(t)),{t:o,d:a}=n;if("lobby"===o)r.openWindow("customLobby"),M.textContent="Custom Lobby "+a.code,C=a.code,q.disabled=!a.isHost,R.className=a.isHost?"":"disabled",U.value=a.options.mode.toString(),J.value=a.options.map.toString(),s=a.players,V=[],_.innerHTML="",s.forEach(z),Y();else if("addPlayer"===o)z(a);else if("removePlayer"===o){const e=a;V[e].element.remove(),V.splice(e,1),Y()}else if("options"===o){console.log(a);const[e,t]=a;"mode"===e?U.value=t.toString():"map"===e&&(J.value=t.toString())}else"setHost"===o?V[a].hostBadge.className="":"host"===o&&(q.disabled=!1,R.className="");var s;return!0},getSocketURL:function(){return"wss://fx.peshomir.workers.dev/"+(""===C?"create":"join?"+C)},setJoinFunction:function(e){A=e},setLeaveFunction:function(e){B=e},setSendFunction:function(e){N=e},setMapInfo:function(e){setTimeout((()=>G(e.map(((e,t)=>({value:t.toString(),label:e.name}))),J)),0)},isActive:()=>O,setActive:function(e){O=e,!1===e&&r.closeWindow("customLobby")}};window.__fx=window.__fx||{};const Z=window.__fx;Z.version="0.6.6.3 Oct 21",Z.settingsManager=p,Z.leaderboardFilter=g,Z.utils=T,Z.WindowManager=r,Z.keybindFunctions=I,Z.keybindHandler=e=>{const t=y().attackPercentageKeybinds.find((t=>t.key===e));return void 0!==t&&("absolute"===t.type?I.setAbsolute(t.value):I.setRelative(t.value),!0)},Z.donationsTracker=k,Z.playerList=L,Z.hoveringTooltip=S,Z.clanFilter=v,Z.wins=n,Z.customLobby=Q,console.log("Successfully loaded FX Client")})(); \ No newline at end of file diff --git a/index.html b/index.html index 164920b..45fdc24 100644 --- a/index.html +++ b/index.html @@ -35,7 +35,7 @@ - +