From 2728c65a496048eebabca8edb7eb0ee332249d15 Mon Sep 17 00:00:00 2001 From: Vantha Date: Tue, 7 Jul 2026 11:21:01 +0200 Subject: [PATCH] Remove some unused getters from components Since __________, a bunch of getter on various components are now unused. This patch removes three of them: - `Identity.prototype.GetRankTechName`, because it is kinda redundant since there's also `Identity.prototype.GetRank`. - `Auras.prototype.GetDescriptions` and `Upgrade.prototype.GetUpgrades` because they are long and perform additional logic (only duplicating some lines from globalscripts/Templates.js). All of the other getters are simple and kept for now because they are useful to have in general and might be handy in the future or for mods. --- .../public/simulation/components/Auras.js | 17 ------------ .../public/simulation/components/Identity.js | 5 ---- .../public/simulation/components/Upgrade.js | 27 ------------------- .../tests/test_UpgradeModification.js | 11 +++++--- 4 files changed, 7 insertions(+), 53 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/Auras.js b/binaries/data/mods/public/simulation/components/Auras.js index 960c8a8d87..f0d95c0983 100644 --- a/binaries/data/mods/public/simulation/components/Auras.js +++ b/binaries/data/mods/public/simulation/components/Auras.js @@ -26,23 +26,6 @@ Auras.prototype.GetModifierIdentifier = function(name) return "aura/" + name; }; -Auras.prototype.GetDescriptions = function() -{ - var ret = {}; - for (const auraID of this.GetAuraNames()) - { - const aura = AuraTemplates.Get(auraID); - ret[auraID] = { - "name": { - "generic": aura.auraName - }, - "description": aura.auraDescription || null, - "radius": this.GetRange(auraID) || null - }; - } - return ret; -}; - Auras.prototype.GetAuraNames = function() { return this.template._string.split(/\s+/); diff --git a/binaries/data/mods/public/simulation/components/Identity.js b/binaries/data/mods/public/simulation/components/Identity.js index 963a58c0e0..ddd76304c4 100644 --- a/binaries/data/mods/public/simulation/components/Identity.js +++ b/binaries/data/mods/public/simulation/components/Identity.js @@ -218,11 +218,6 @@ Identity.prototype.GetRank = function() return this.template.Rank || ""; }; -Identity.prototype.GetRankTechName = function() -{ - return this.template.Rank ? "unit_" + this.template.Rank.toLowerCase() : ""; -}; - Identity.prototype.GetClassesList = function() { return this.classesList; diff --git a/binaries/data/mods/public/simulation/components/Upgrade.js b/binaries/data/mods/public/simulation/components/Upgrade.js index 282c4be689..3f24e2d933 100644 --- a/binaries/data/mods/public/simulation/components/Upgrade.js +++ b/binaries/data/mods/public/simulation/components/Upgrade.js @@ -128,33 +128,6 @@ Upgrade.prototype.CanUpgradeTo = function(template) return this.upgradeTemplates[template] !== undefined; }; -Upgrade.prototype.GetUpgrades = function() -{ - const ret = []; - - for (const option in this.upgradeTemplates) - { - const choice = this.template[this.upgradeTemplates[option]]; - - let cost = {}; - if (choice.Cost) - cost = this.GetResourceCosts(option); - if (choice.Time) - cost.time = this.GetUpgradeTime(option); - - const hasCost = choice.Cost || choice.Time; - ret.push({ - "entity": option, - "icon": choice.Icon || undefined, - "cost": hasCost ? cost : undefined, - "tooltip": choice.Tooltip || undefined, - "requirements": this.GetRequirements(option), - }); - } - - return ret; -}; - Upgrade.prototype.CancelTimer = function() { if (!this.timer) diff --git a/binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js b/binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js index a408855568..b1858b83de 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js +++ b/binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js @@ -148,8 +148,10 @@ TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrade.options[0].cost, { "stone": 100, parsed_template = g_TemplateHelper.computeDataFromPlayer(template, {}, Resources, playerID, civCode, ["Upgrade"]); TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrade.options[0].cost, { "stone": 100, "wood": 50, "time": 100 }); -// T3: Check that the value is correct within the Update Component. -TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetUpgrades()[0].cost, { "stone": 100, "wood": 50, "time": 100 }); +// T3: Check that the value is correct within the Upgrade Component. +const entity = template.Upgrade.Tower.Entity.replace("{civ}", civCode); +TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetResourceCosts(entity), { "stone": 100, "wood": 50 }); +TS_ASSERT_EQUALS(cmpUpgrade.GetUpgradeTime(entity), 100); /** * Tell the Upgrade component to start the Upgrade, @@ -167,8 +169,9 @@ parsed_template = g_TemplateHelper.computeDataFromPlayer(template, {}, Resources TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrade.options[0].cost, { "stone": 160, "wood": 25, "time": 90 }); // T6: The upgrade component should still be using the old resource cost (but new time cost) for the upgrade in progress... -TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetUpgrades()[0].cost, { "stone": 100, "wood": 50, "time": 90 }); +TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetResourceCosts(entity), { "stone": 100, "wood": 50 }); +TS_ASSERT_EQUALS(cmpUpgrade.GetUpgradeTime(entity), 90); // T7: ...but with the upgrade cancelled, it now uses the modified value. cmpUpgrade.CancelUpgrade(playerID); -TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetUpgrades()[0].cost, { "stone": 160, "wood": 25, "time": 90 }); +TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetResourceCosts(entity), { "stone": 160, "wood": 25 });