Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/globalscripts/Templates.js
Show First 20 Lines • Show All 298 Lines • ▼ Show 20 Lines | function GetTemplateDataHelper(template, player, auraTemplates, modifiers = {}) | ||||
{ | { | ||||
ret.cost = {}; | ret.cost = {}; | ||||
for (let resCode in template.Cost.Resources) | for (let resCode in template.Cost.Resources) | ||||
ret.cost[resCode] = getEntityValue("Cost/Resources/" + resCode); | ret.cost[resCode] = getEntityValue("Cost/Resources/" + resCode); | ||||
if (template.Cost.Population) | if (template.Cost.Population) | ||||
ret.cost.population = getEntityValue("Cost/Population"); | ret.cost.population = getEntityValue("Cost/Population"); | ||||
if (template.Cost.PopulationBonus) | if (template.Population && template.Population.Bonus) | ||||
ret.cost.populationBonus = getEntityValue("Cost/PopulationBonus"); | ret.population = { | ||||
"bonus": getEntityValue("Population/Bonus") | |||||
}; | |||||
if (template.Cost.BuildTime) | if (template.Cost.BuildTime) | ||||
ret.cost.time = getEntityValue("Cost/BuildTime"); | ret.cost.time = getEntityValue("Cost/BuildTime"); | ||||
} | } | ||||
if (template.Footprint) | if (template.Footprint) | ||||
{ | { | ||||
ret.footprint = { "height": template.Footprint.Height }; | ret.footprint = { "height": template.Footprint.Height }; | ||||
Freagarach: PopBonus is not optional in the template, so I guess we don't need to check for its existence. | |||||
Done Inline ActionsI'm not sure I entirely understand the syntax "popBonus": getvalue . I assume you meant what I've written below? if (template.PopulationHolder.PopulationBonus) ret.populationHolder = { "populationBonus": getEntityValue("PopulationHolder/PopulationBonus") }; lonehawk: I'm not sure I entirely understand the syntax ` "popBonus": getvalue `. I assume you meant… | |||||
Done Inline ActionsYes, I meant that :) if (template.PopulationHolder && template.PopulationHolder.PopulationBonus) Freagarach: Yes, I meant that :)
Regarding the `if`: as you write it it fails (prints an error or a… | |||||
if (template.Footprint.Square) | if (template.Footprint.Square) | ||||
ret.footprint.square = { | ret.footprint.square = { | ||||
"width": +template.Footprint.Square["@width"], | "width": +template.Footprint.Square["@width"], | ||||
"depth": +template.Footprint.Square["@depth"] | "depth": +template.Footprint.Square["@depth"] | ||||
}; | }; | ||||
else if (template.Footprint.Circle) | else if (template.Footprint.Circle) | ||||
ret.footprint.circle = { "radius": +template.Footprint.Circle["@radius"] }; | ret.footprint.circle = { "radius": +template.Footprint.Circle["@radius"] }; | ||||
else | else | ||||
▲ Show 20 Lines • Show All 263 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
PopBonus is not optional in the template, so I guess we don't need to check for its existence.
Also you can inline the declaration.
If we still want to check for the existence of the bonus you can do it in the first if.