From 674affb84e3df185aa3738d3509f96a5d84e2af2 Mon Sep 17 00:00:00 2001 From: peshomir <80340328+peshomir@users.noreply.github.com> Date: Fri, 8 Mar 2024 13:08:20 +0200 Subject: [PATCH] Update v0.6.2; Player density update The territrorial density is now displayed below each player's/bot's name, this can be toggled in the settings --- build.js | 13 +++++++++++-- static/fx_core.js | 13 ++++++++++--- static/index.html | 4 ++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/build.js b/build.js index 126d25c..0db4313 100644 --- a/build.js +++ b/build.js @@ -59,14 +59,14 @@ replaceOne(/(0===(\w+)\?(\w+)\[\2\]\.length)-1:(\3\[\2\]\.length:1,)/g, "$1 - 2 // Max size for custom maps: from 4096x4096 to 8192x8192 // TODO: test this; it might cause issues with new boat mechanics? -{ // Add Troop Density and Maximum Troops in side panel -- todo +{ // Add Troop Density and Maximum Troops in side panel const { groups: { valuesArray } } = replaceOne(/(,(?\w+)\[\d\]="Interest",\2\[\d\]="Income",\2\[\d\]="Time"),(\w+=\w+-\w+\(\w+,100\),\((?\w+)=new Array\(\2\.length\)\)\[0\]=\w+)/g, '$1, $.push("Max Troops", "Density"), $3'); // add labels replaceOne(new RegExp(/(:(?\w+)<7\?\w+\.\w+\.\w+\(valuesArray\[\2\]\)):(\w+\.\w+\(valuesArray\[7\]\))}/ .source.replace(/valuesArray/g, valuesArray), "g"), '$1 : $ === 7 ? $3 ' + `: $ === 8 ? utils.getMaxTroops(${dictionary.playerTerritories}, ${dictionary.playerId}) ` - + `: utils.getDensity(${dictionary.playerBalances}, ${dictionary.playerTerritories}, ${dictionary.playerId}) }`); + + `: utils.getDensity(${dictionary.playerId}) }`); // increase the size of the side panel by 25% to make the text easier to read // match this.w = Math.floor((o ? .1646 : .126) * cZ), replaceOne(/(this\.\w+=Math\.floor\(\(\w+\?\.1646:\.126\))\*(\w+\),)/g, "$1 * 1.25 * $2"); @@ -158,6 +158,15 @@ replaceOne(new RegExp(`,${dictionary.playerBalances}=new Uint32Array\\(\\w+\\),` + ` else { playerList.hoveringOverButton === true && (playerList.hoveringOverButton = false, ${drawFunction}(), $); } $4`); } +{ // Display density of other players + // Applies when the "Reverse Name/Balance" setting is off + const { groups: { settingsSwitchNameAndBalance } } = replaceOne(/(,(?\w+\.\w+\.\w+)\?(?\w+)\(\w+,\w+,(?\w+),(?\w+)\+\.78\*(?\w+),(?\w+)\)):(\7\.fillText\(\w+\.\w+\.\w+\(\w+\[(\w+)\]\),\4,\5\+\.78\*\6\))\)\)/g, + `$1 : ($8, settings.showPlayerDensity && $.fillText(utils.getDensity($9), $, $ + $ * 1.5)) ))`); + // Applies when the "Reverse Name/Balance" setting is on (default) + replaceOne(/(function \w+\((\w+),(?\w+),(?\w+),(?\w+),(?\w+)\){\6\.fillText\((?\w+)\[\2\],\4,\5\)),(\2<(?\w+)&&2!==(?\w+)\[)/g, + `$1, ${settingsSwitchNameAndBalance} && settings.showPlayerDensity && $.fillText(utils.getDensity($2), $, $ + $), $8`); +} + // Disable built-in Territorial.io error reporting replaceOne(/window\.addEventListener\("error",function (\w+)\((\w+)\){/g, '$& window.removeEventListener("error", $1); return alert("Error:\\n" + $2.filename + " " + $2.lineno + " " + $2.colno + " " + $2.message);'); diff --git a/static/fx_core.js b/static/fx_core.js index 3c8744e..9d41e46 100644 --- a/static/fx_core.js +++ b/static/fx_core.js @@ -1,5 +1,5 @@ -const fx_version = '0.6.1.9'; // FX Client Version -const fx_update = 'Mar 7'; // FX Client Last Updated +const fx_version = '0.6.2'; // FX Client Version +const fx_update = 'Mar 8'; // FX Client Last Updated if (localStorage.getItem("fx_winCount") == undefined || localStorage.getItem("fx_winCount") == null) { var wins_counter = 0; @@ -95,6 +95,7 @@ var settings = { "useFullscreenMode": false, "hideAllLinks": false, "realisticNames": false, + "showPlayerDensity": true, "densityDisplayStyle": "percentage", //"customMapFileBtn": true "customBackgroundUrl": "", @@ -113,6 +114,7 @@ var settingsManager = new (function() { realisticNames: document.getElementById("settings_realisticnames"), displayWinCounter: document.getElementById("settings_displaywincounter"), useFullscreenMode: document.getElementById("settings_usefullscreenmode"), + showPlayerDensity: document.getElementById("settings_showPlayerDensity"), //customMapFileBtn: document.getElementById("settings_custommapfileinput") }; this.save = function() { @@ -293,12 +295,17 @@ function displayDonationsHistory(playerID, playerNames = getVar("playerNames"), var utils = new (function() { this.getMaxTroops = function(playerTerritories, playerID) { return (playerTerritories[playerID]*150).toString(); }; - this.getDensity = function(playerBalances, playerTerritories, playerID) { + this.getDensity = function(playerID, playerBalances = getVar("playerBalances"), playerTerritories = getVar("playerTerritories")) { if (settings.densityDisplayStyle === "percentage") return (((playerBalances[playerID] / ((playerTerritories[playerID] === 0 ? 1 : playerTerritories[playerID]) * 150)) * 100).toFixed(1) + "%"); else return (playerBalances[playerID] / (playerTerritories[playerID] === 0 ? 1 : playerTerritories[playerID])).toFixed(1); }; this.isPointInRectangle = function(x, y, rectangleStartX, rectangleStartY, width, height) { return x >= rectangleStartX && x <= rectangleStartX + width && y >= rectangleStartY && y <= rectangleStartY + height; + }; + /** @param {CanvasRenderingContext2D} canvas @param {string} text */ + this.fillTextMultiline = function(canvas, text, x, y, maxWidth) { + const lineHeight = parseInt(canvas.font.split(" ").find(part => part.endsWith("px")).slice(0, -2)); + text.split("\n").forEach((line, index) => canvas.fillText(line, x, y + index * lineHeight, maxWidth)); } }); diff --git a/static/index.html b/static/index.html index 0de3ffb..5070a3f 100644 --- a/static/index.html +++ b/static/index.html @@ -83,6 +83,10 @@ Realistic Bot Names
+