import WindowManager from "./windowManager.js"; import { getVar } from "./gameInterface.js"; import { escapeHtml } from "./utils.js"; WindowManager.add({ name: "donationHistory", element: document.querySelector("#donationhistory"), beforeOpen: function(isSingleplayer) { document.getElementById("donationhistory_note").style.display = (/*(settings.showBotDonations || isSingleplayer)*/ true ? "none" : "block"); }, onClose: function() { donationsTracker.openedWindowPlayerID = null; } }); const donationsTracker = new (function(){ this.openedWindowPlayerID = null; this.contentElement = document.querySelector("#donationhistory_content"); this.donationHistory = Array(512); // 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 this.getHistoryOf = function(playerID) { return this.donationHistory[playerID].toReversed(); } this.reset = function() { for (var i = 0; i < 512; i++) this.donationHistory[i] = []; }; this.logDonation = function(senderID, receiverID, amount) { const donationInfo = [senderID, receiverID, amount]; this.donationHistory[receiverID].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)); } }; function generateTableRowItem(historyItem, index, playerID, isNew) { const rawPlayerNames = getVar("rawPlayerNames"); const row = document.createElement("tr"); if (isNew) row.setAttribute("class", "new"); let content = `