Update v0.6.2.1

Donation history viewer and player list UI improvements,
fixed a bug with the donation history viewer
dev
peshomir 2024-03-10 20:58:56 +02:00
parent fb331b678d
commit 0fed20b940
4 changed files with 73 additions and 32 deletions

View File

@ -35,6 +35,8 @@ let dictionary = {};
/\w+\.\w+\((\w+)\)\?\w+\.\w+\(\1\)\?(\w+)=(\w+\.\w+)\(13,\[\2\]\):\(\w+=\w+\.\w+\(\1\),\2=\3\(14,\[(?<playerNames>\w+)\[(\w+)\],(\w+\.\w+\.\w+\()(?<playerBalances>\w+)\[\5\]\),\6(?<playerTerritories>\w+)\[\5\]\),\2\]\),\w+=!0\):\2=/g, /\w+\.\w+\((\w+)\)\?\w+\.\w+\(\1\)\?(\w+)=(\w+\.\w+)\(13,\[\2\]\):\(\w+=\w+\.\w+\(\1\),\2=\3\(14,\[(?<playerNames>\w+)\[(\w+)\],(\w+\.\w+\.\w+\()(?<playerBalances>\w+)\[\5\]\),\6(?<playerTerritories>\w+)\[\5\]\),\2\]\),\w+=!0\):\2=/g,
// this one also broke in 1.91.3 /,\w+="Player: "\+(?<playerNames>\w+)\[\w+\],\w+=\(\w\+=" Balance: "\+\w+\.\w+\((?<playerBalances>\w+)\[\w+\]\)\)\+\(" Territory: "\+\w+\.\w+\((?<playerTerritories>\w+)\[\w+\]\)\)\+\(" Coords: "/g, // this one also broke in 1.91.3 /,\w+="Player: "\+(?<playerNames>\w+)\[\w+\],\w+=\(\w\+=" Balance: "\+\w+\.\w+\((?<playerBalances>\w+)\[\w+\]\)\)\+\(" Territory: "\+\w+\.\w+\((?<playerTerritories>\w+)\[\w+\]\)\)\+\(" Coords: "/g,
/\((?<uiOffset>\w+)=Math\.floor\(\(\w+\?\.0114:\.01296\)\*\w+\)\)/g, /\((?<uiOffset>\w+)=Math\.floor\(\(\w+\?\.0114:\.01296\)\*\w+\)\)/g,
/(function \w+\((\w+),(\w+),(\w+),(\w+),(\w+)\){\6\.fillText\((?<playerNames>\w+)\[\2\],\4,\5\)),(\2<(?<gHumans>\w+)&&2!==(?<playerStates>\w+)\[)/g,
/,\w+=512,(?<gLobbyMaxJoin>\w+)=\w+,(?<gIsSingleplayer>\w+)&&\(\1=\w+\.\w+\(\)\),\w+=\1-\w+,\w+=0,/g
].forEach(expression => { ].forEach(expression => {
result = expression.exec(script); result = expression.exec(script);
if (result === null) throw new Error("no match for ") + expression; if (result === null) throw new Error("no match for ") + expression;
@ -139,7 +141,7 @@ replaceOne(/(this\.\w+=function\((\w+),(\w+)\)\{)(\2===\w+&&\(\w+\.\w+\((\w+\.\w
// Display donations for a player when clicking on them in the leaderboard // Display donations for a player when clicking on them in the leaderboard
// match , 0 !== dG[x]) && fq.hB(x, 800, false, 0), // match , 0 !== dG[x]) && fq.hB(x, 800, false, 0),
replaceOne(/,(0!==\w+\[(\w+)\]\)&&\w+\.\w+\(\2,800,!1,0\),)/g, replaceOne(/,(0!==\w+\[(\w+)\]\)&&\w+\.\w+\(\2,800,!1,0\),)/g,
`, ${dictionary.gIsTeamGame} && displayDonationsHistory($2, ${dictionary.playerNames}, ${dictionary.gIsSingleplayer}), $1`); `, ${dictionary.gIsTeamGame} && donationsTracker.displayHistory($2, ${dictionary.playerNames}, ${dictionary.gIsSingleplayer}), $1`);
// Reset donation history when a new game is started // Reset donation history when a new game is started
replaceOne(new RegExp(`,${dictionary.playerBalances}=new Uint32Array\\(\\w+\\),`, "g"), "$& donationsTracker.reset(), "); replaceOne(new RegExp(`,${dictionary.playerBalances}=new Uint32Array\\(\\w+\\),`, "g"), "$& donationsTracker.reset(), ");

View File

@ -1,5 +1,5 @@
const fx_version = '0.6.2'; // FX Client Version const fx_version = '0.6.2.1'; // FX Client Version
const fx_update = 'Mar 8'; // FX Client Last Updated const fx_update = 'Mar 10'; // FX Client Last Updated
if (localStorage.getItem("fx_winCount") == undefined || localStorage.getItem("fx_winCount") == null) { if (localStorage.getItem("fx_winCount") == undefined || localStorage.getItem("fx_winCount") == null) {
var wins_counter = 0; var wins_counter = 0;
@ -200,6 +200,7 @@ var WindowManager = new (function() {
if (windows[windowName].isOpen === false) return; if (windows[windowName].isOpen === false) return;
windows[windowName].isOpen = false; windows[windowName].isOpen = false;
windows[windowName].element.style.display = "none"; windows[windowName].element.style.display = "none";
if (windows[windowName].onClose !== undefined) windows[windowName].onClose();
}; };
this.closeAll = function() { this.closeAll = function() {
Object.values(windows).forEach(function(windowObj) { Object.values(windows).forEach(function(windowObj) {
@ -217,7 +218,8 @@ WindowManager.add({
element: document.querySelector("#donationhistory"), element: document.querySelector("#donationhistory"),
beforeOpen: function(isSingleplayer) { beforeOpen: function(isSingleplayer) {
document.getElementById("donationhistory_note").style.display = ((true || settings.showBotDonations || /*getVarByName("dt")*/ isSingleplayer) ? "none" : "block"); document.getElementById("donationhistory_note").style.display = ((true || settings.showBotDonations || /*getVarByName("dt")*/ isSingleplayer) ? "none" : "block");
} },
onClose: function() { donationsTracker.openedWindowPlayerID = null; }
}); });
WindowManager.add({ WindowManager.add({
name: "playerList", name: "playerList",
@ -236,11 +238,14 @@ const playerList = new (function () {
document.getElementById("playerlist_content").addEventListener("click", event => { document.getElementById("playerlist_content").addEventListener("click", event => {
const playerId = event.target.closest("tr[data-player-id]")?.getAttribute("data-player-id"); const playerId = event.target.closest("tr[data-player-id]")?.getAttribute("data-player-id");
if (!playerId) return; if (!playerId) return;
if (getVar("gIsTeamGame")) WindowManager.closeWindow("playerList"), displayDonationsHistory(playerId); if (getVar("gIsTeamGame")) WindowManager.closeWindow("playerList"), donationsTracker.displayHistory(playerId);
}); });
this.display = function displayPlayerList(playerNames) { this.display = function displayPlayerList(playerNames) {
let listContent = ""; const gHumans = getVar("gHumans");
for (let i = 0; i < playerNames.length; i++) { const gLobbyMaxJoin = getVar("gLobbyMaxJoin");
let listContent = `<h3>Players (${gHumans})</h3>`;
for (let i = 0; i < gLobbyMaxJoin; i++) {
if (i === gHumans) listContent += `<h3>Bots (${gLobbyMaxJoin - gHumans})</h3>`;
listContent += `<tr data-player-id="${i}"><td><span class="color-light-gray">${i}.</span> ${escapeHtml(playerNames[i])}</td></tr>` listContent += `<tr data-player-id="${i}"><td><span class="color-light-gray">${i}.</span> ${escapeHtml(playerNames[i])}</td></tr>`
} }
document.getElementById("playerlist_content").innerHTML = listContent; document.getElementById("playerlist_content").innerHTML = listContent;
@ -260,38 +265,50 @@ const playerList = new (function () {
} }
}); });
var donationsTracker = new (function(){ var donationsTracker = new (function(){
this.openedWindowPlayerID = null;
this.contentElement = document.querySelector("#donationhistory_content");
this.donationHistory = Array(512); this.donationHistory = Array(512);
// fill the array with empty arrays with length of 3 // fill the array with empty arrays with length of 3
//for (var i = 0; i < 512; i++) this.donationHistory.push([]); // not needed as .reset is called on game start //for (var i = 0; i < 512; i++) this.donationHistory.push([]); // not needed as .reset is called on game start
// from inside of game: this.getHistoryOf = function(playerID) {
// ((!gE[g].startsWith("[Bot] ") || settings.showBotDonations) && donationsTracker.logDonation(g,k,x)) return this.donationHistory[playerID].toReversed();
}
this.reset = function() { for (var i = 0; i < 512; i++) this.donationHistory[i] = []; };
this.logDonation = function(senderID, receiverID, amount) { this.logDonation = function(senderID, receiverID, amount) {
const donationInfo = [senderID, receiverID, amount]; const donationInfo = [senderID, receiverID, amount];
this.donationHistory[receiverID].push(donationInfo); this.donationHistory[receiverID].push(donationInfo);
this.donationHistory[senderID].push(donationInfo); this.donationHistory[senderID].push(donationInfo);
if (this.openedWindowPlayerID === senderID || this.openedWindowPlayerID === receiverID) {
const indexOfNewItem = this.donationHistory[this.openedWindowPlayerID === senderID ? senderID : receiverID].length;
this.contentElement.prepend(generateTableRowItem(donationInfo, indexOfNewItem, this.openedWindowPlayerID, true));
}
}; };
this.getRecipientHistoryOf = function(playerID) { function generateTableRowItem(historyItem, index, playerID, isNew) {
return this.donationHistory[playerID]; const playerNames = getVar("playerNames");
}; const row = document.createElement("tr");
this.reset = function() { for (var i = 0; i < 512; i++) this.donationHistory[i] = []; }; if (isNew) row.setAttribute("class", "new");
}); let content = `<td><span class="color-light-gray">${index}.</span> `;
function displayDonationsHistory(playerID, playerNames = getVar("playerNames"), isSingleplayer = getVar("gIsSingleplayer")) {
var history = donationsTracker.getRecipientHistoryOf(playerID);
console.log("History for " + playerNames[playerID] + ":");
console.log(history);
document.querySelector("#donationhistory h1").innerHTML = "Donation history for " + escapeHtml(playerNames[playerID]);
var historyText = "";
history.reverse();
if (history.length > 0) history.forEach(function(historyItem, index) {
historyText += `<span class="color-light-gray">${(history.length - index)}.</span> `;
if (playerID === historyItem[1]) if (playerID === historyItem[1])
historyText += `Received <span class="color-green">${historyItem[2]}</span> resources from ${escapeHtml(playerNames[historyItem[0]])}<br>`; content += `Received <span class="color-green">${historyItem[2]}</span> resources from ${escapeHtml(playerNames[historyItem[0]])}`;
else historyText += `Sent <span class="color-red">${historyItem[2]}</span> resources to ${escapeHtml(playerNames[historyItem[1]])}<br>`; else content += `Sent <span class="color-red">${historyItem[2]}</span> resources to ${escapeHtml(playerNames[historyItem[1]])}`;
}); content += "</td>";
else historyText = "Nothing to display"; row.innerHTML = content;
document.querySelector("#donationhistory p#donationhistory_text").innerHTML = historyText; return row;
WindowManager.openWindow("donationHistory", isSingleplayer); }
} this.displayHistory = function displayDonationsHistory(playerID, playerNames = getVar("playerNames"), isSingleplayer = getVar("gIsSingleplayer")) {
var history = donationsTracker.getHistoryOf(playerID);
console.log("History for " + playerNames[playerID] + ":");
console.log(history);
document.querySelector("#donationhistory h1").innerHTML = "Donation history for " + escapeHtml(playerNames[playerID]);
this.contentElement.innerHTML = "";
if (history.length > 0) history.forEach((historyItem, index) => {
this.contentElement.appendChild(generateTableRowItem(historyItem, history.length - index, playerID));
});
else this.contentElement.innerText = "Nothing to display";
this.openedWindowPlayerID = playerID;
WindowManager.openWindow("donationHistory", isSingleplayer);
}
});
var utils = new (function() { var utils = new (function() {
this.getMaxTroops = function(playerTerritories, playerID) { return (playerTerritories[playerID]*150).toString(); }; this.getMaxTroops = function(playerTerritories, playerID) { return (playerTerritories[playerID]*150).toString(); };

View File

@ -117,7 +117,7 @@
<div class="window scrollable selectable" id="donationhistory" style="display:none"> <div class="window scrollable selectable" id="donationhistory" style="display:none">
<h1>Donation history for </h1> <h1>Donation history for </h1>
<p id="donationhistory_note">Note: donations from bots are not shown here</p> <p id="donationhistory_note">Note: donations from bots are not shown here</p>
<p id="donationhistory_text"></p> <table><tbody id="donationhistory_content"></tbody></table>
</div> </div>
<script src="variables.js?buildTimestamp"></script> <script src="variables.js?buildTimestamp"></script>
<script src="fx_core.js?buildTimestamp"></script> <script src="fx_core.js?buildTimestamp"></script>

View File

@ -16,7 +16,7 @@
width : 90%; width : 90%;
top : 0; top : 0;
color : white; color : white;
font-family : 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; font-family : 'Franklin Gothic Medium', 'Trebuchet MS', Arial, sans-serif;
margin : auto; margin : auto;
margin-top : 20px; margin-top : 20px;
right : 0; right : 0;
@ -62,6 +62,15 @@ h1 {
margin-block-end : 0.5em; margin-block-end : 0.5em;
transition : 0.2s; transition : 0.2s;
} }
#playerlist h1 {
margin-block-start: 0.3em;
margin-block-end : 0.3em;
}
h3 {
font-weight : normal;
margin-block-start: 0.6em;
margin-block-end : 0.6em;
}
canvas, canvas,
input, input,
@ -86,6 +95,19 @@ td {
#playerlist_content.clickable td { cursor: pointer; } #playerlist_content.clickable td { cursor: pointer; }
#playerlist_content.clickable td:hover { background-color: #00ff0040; } #playerlist_content.clickable td:hover { background-color: #00ff0040; }
tr.new {
animation: flashAnimation 0.4s ease-out;
}
@keyframes flashAnimation {
0% {
background-color: #ffffffaa;
}
100% {
background-color: transparent;
}
}
table { table {
border-spacing: 0px; border-spacing: 0px;
} }