Changeset View
Standalone View
binaries/data/mods/public/globalscripts/Templates.js
Show First 20 Lines • Show All 361 Lines • ▼ Show 20 Lines | ret.name = { | ||||
"specific": specific, | "specific": specific, | ||||
"generic": template.genericName, | "generic": template.genericName, | ||||
}; | }; | ||||
ret.icon = template.icon ? "technologies/" + template.icon : null; | ret.icon = template.icon ? "technologies/" + template.icon : null; | ||||
ret.cost = { "time": template.researchTime ? +template.researchTime : 0 }; | ret.cost = { "time": template.researchTime ? +template.researchTime : 0 }; | ||||
for (let type of resources.GetCodes()) | for (let type of resources.GetCodes()) | ||||
ret.cost[type] = template.cost ? +template.cost[type] : 0; | ret.cost[type] = +(template.cost && template.cost[type] || 0); | ||||
elexis: Why was it changed? `x ? y : z` seems nicer to read than `x && y || z` (and why wouldnt the… | |||||
Not Done Inline ActionsExpanding on my comment in the trac ticket linked at the top of the page; any of the following
results in warnings about template.cost[type] being undefined if the value of type does not exist as a key in template.cost. This happens if a technology template has not got a cost set for a given resource, such as when a technology file from "vanilla" 0ad is used in a mod which has added a new resource. If we don't support this, we would instead require any mod that adds a new resource type to have to modify every technology template that 0ad possesses so as to add that new resource type to the cost of the technology. Alternatively, template.cost && template.cost[type] ? +template.cost[type] : 0; would work, but this was apparently not acceptable to you in the original patch as posted on trac. And before you ask, +(template.cost[type] || 0) results in an error complaining that template.cost sometimes doesn't exist. And assuming you meant the line with researchTime - that was not changed because it is unnecessary to do so - we check that it exists before we try casting it to a number. s0600204: Expanding on my comment in the trac ticket linked at the top of the page; any of the following… | |||||
ret.tooltip = template.tooltip; | ret.tooltip = template.tooltip; | ||||
ret.requirementsTooltip = template.requirementsTooltip || ""; | ret.requirementsTooltip = template.requirementsTooltip || ""; | ||||
ret.reqs = DeriveTechnologyRequirements(template, civ); | ret.reqs = DeriveTechnologyRequirements(template, civ); | ||||
ret.description = template.description; | ret.description = template.description; | ||||
Show All 21 Lines |
Why was it changed? x ? y : z seems nicer to read than x && y || z (and why wouldnt the other instance above not be changed as well)