mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-08-15 14:43:32 -07:00
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.
This commit is contained in:
parent
0a7a6aac87
commit
2728c65a49
4 changed files with 7 additions and 53 deletions
|
|
@ -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+/);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
|
|
|
|||
Loading…
Reference in a new issue