Changeset View
Standalone View
binaries/data/mods/public/globalscripts/Templates.js
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* @param template A valid template as returned by the template loader. | * @param template A valid template as returned by the template loader. | ||||
* @param player An optional player id to get the technology modifications | * @param player An optional player id to get the technology modifications | ||||
* of properties. | * of properties. | ||||
* @param auraTemplates An object in the form of {key: {auraName: "", auraDescription: ""}} | * @param auraTemplates An object in the form of {key: {auraName: "", auraDescription: ""}} | ||||
* @param resources An instance of the Resources prototype | * @param resources An instance of the Resources prototype | ||||
*/ | */ | ||||
function GetTemplateDataHelper(template, player, auraTemplates, resources) | function GetTemplateDataHelper(template, player, auraTemplates, resources) | ||||
{ | { | ||||
bb: One could add spaces in the commented object for consistency, meh.
Committer can add them too | |||||
// Return data either from template (in tech tree) or sim state (ingame) | // Return data either from template (in tech tree) or sim state (ingame) | ||||
let getEntityValue = function(tech_type) { | let getEntityValue = function(tech_type) { | ||||
Done Inline Actionsperiods bb: periods | |||||
Not Done Inline Actions...are what lady-folk get roughly once a month. I'll add in some full-stops instead. *ahem* ok, levity over. Back to work. s0600204: ...are what lady-folk get roughly once a month. I'll add in some full-stops instead.
*ahem* ok… | |||||
let current_value = template; | let current_value = template; | ||||
for (let property of tech_type.split("/")) | for (let property of tech_type.split("/")) | ||||
Not Done Inline ActionsThis function should be at the top scope instead. It will be useful for D302 and there's no reason not to put it there in general. This function should not used g_CurrentModifiers but get a list of modifiers as a parameter, so that it becomes pure. See comments below about deriveAutoresearchedModifications. Also, I'm not entirely sure why you add mod_key here, the description is unclear and it doesn't actually seem used? wraitii: This function should be at the top scope instead. It will be useful for D302 and there's no… | |||||
Not Done Inline Actions
See D92#5200. Unless you meant why added in this commit. Hypothetically to reduce possibility of merge conflict with D92, which also changes code in this area, and looked to be closer to being committed at the time. s0600204: > Also, I'm not entirely sure why you add mod_key here, the description is unclear and it… | |||||
current_value = current_value[property] || 0; | current_value = current_value[property] || 0; | ||||
current_value = +current_value; | current_value = +current_value; | ||||
bbUnsubmitted Not Done Inline ActionsThis will crash when the template and tech paths does not correspond, but I guess thats ok. bb: This will crash when the template and tech paths does not correspond, but I guess thats ok. | |||||
s0600204AuthorUnsubmitted Not Done Inline ActionsIt should not crash. It may give the wrong value under certain specific circumstances, but it should not crash. If you can prove evidence or a test case where it does crash, I'll look into it. s0600204: It should not crash. It may give the wrong value under certain specific circumstances, but it… | |||||
if (!player) | if (player) | ||||
return current_value; | |||||
return ApplyValueModificationsToTemplate(tech_type, current_value, player, template); | return ApplyValueModificationsToTemplate(tech_type, current_value, player, template); | ||||
bbUnsubmitted Not Done Inline ActionsWondering what this call is (trying to) do... bb: Wondering what this call is (trying to) do... | |||||
s0600204AuthorUnsubmitted Not Done Inline ActionsThe same thing that the call does in the pre-revision state of the code. If called from within a running game session, it returns the appropriately modified value by running it through the simulation state, which is more complete and includes player-specific modifications unlike the call below which only applies global or game-start modifications. s0600204: The same thing that the call does in the pre-revision state of the code.
If called from within… | |||||
bbUnsubmitted Not Done Inline ActionsThen I think it's broken, tested with the corral ups for cav speed... probably out of scope of this diff bb: Then I think it's broken, tested with the corral ups for cav speed...
probably out of scope of… | |||||
Not Done Inline ActionsI don't suspect any stat needs to be displayed with more than 8 decimals, so seems fine bb: I don't suspect any stat needs to be displayed with more than 8 decimals, so seems fine | |||||
if (typeof g_CurrentModifiers !== "undefined") | |||||
return GetTechModifiedProperty(g_CurrentModifiers, GetIdentityClasses(template.Identity), tech_type, current_value); | |||||
return current_value; | |||||
Done Inline ActionsI like adding "else" for incompatible ifs anyhow. wraitii: I like adding "else" for incompatible ifs anyhow. | |||||
}; | }; | ||||
let ret = {}; | let ret = {}; | ||||
if (template.Armour) | if (template.Armour) | ||||
ret.armour = { | ret.armour = { | ||||
"hack": getEntityValue("Armour/Hack"), | "hack": getEntityValue("Armour/Hack"), | ||||
"pierce": getEntityValue("Armour/Pierce"), | "pierce": getEntityValue("Armour/Pierce"), | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | function GetTemplateDataHelper(template, player, auraTemplates, resources) | ||||
if (template.Identity) | if (template.Identity) | ||||
{ | { | ||||
ret.selectionGroupName = template.Identity.SelectionGroupName; | ret.selectionGroupName = template.Identity.SelectionGroupName; | ||||
ret.name = { | ret.name = { | ||||
"specific": (template.Identity.SpecificName || template.Identity.GenericName), | "specific": (template.Identity.SpecificName || template.Identity.GenericName), | ||||
"generic": template.Identity.GenericName | "generic": template.Identity.GenericName | ||||
}; | }; | ||||
ret.icon = template.Identity.Icon; | ret.icon = template.Identity.Icon; | ||||
ret.tooltip = template.Identity.Tooltip; | ret.tooltip = template.Identity.Tooltip; | ||||
ret.requiredTechnology = template.Identity.RequiredTechnology; | ret.requiredTechnology = template.Identity.RequiredTechnology; | ||||
ret.visibleIdentityClasses = GetVisibleIdentityClasses(template.Identity); | ret.visibleIdentityClasses = GetVisibleIdentityClasses(template.Identity); | ||||
} | } | ||||
if (template.UnitMotion) | if (template.UnitMotion) | ||||
{ | { | ||||
ret.speed = { | ret.speed = { | ||||
"walk": getEntityValue("UnitMotion/WalkSpeed"), | "walk": getEntityValue("UnitMotion/WalkSpeed"), | ||||
Show All 29 Lines | function GetTemplateDataHelper(template, player, auraTemplates, resources) | ||||
if (template.WallPiece) | if (template.WallPiece) | ||||
ret.wallPiece = { "length": +template.WallPiece.Length }; | ret.wallPiece = { "length": +template.WallPiece.Length }; | ||||
return ret; | return ret; | ||||
} | } | ||||
/** | /** | ||||
* Get information about a technology template. | * Get basic information about a technology template. | ||||
* @param template A valid template as obtained by loading the tech JSON file. | * @param template A valid template as obtained by loading the tech JSON file. | ||||
Not Done Inline ActionsNever seen that hyphen in comments, nuke bb: Never seen that hyphen in comments, nuke | |||||
Not Done Inline ActionsThen with due respect, you're not looking very hard. Hint: run ack --type=js "\* \@param \{" in binaries/data/mods/public and you'll find that more frequently than not, a hyphen is included. s0600204: Then with due respect, you're not looking very hard.
Hint: run `ack --type=js "\* \@param \{"`… | |||||
* @param civ Civilization for which the specific name should be returned. | |||||
* @param resources An instance of the Resources prototype. | |||||
*/ | */ | ||||
Done Inline ActionsSee above bb: See above | |||||
Done Inline Actionsrequirements seem to also be based on civ bb: requirements seem to also be based on civ | |||||
function GetTechnologyDataHelper(template, civ, resources) | function GetTechnologyBasicDataHelper(template, civ) | ||||
{ | { | ||||
let ret = {}; | let ret = {}; | ||||
// Get specific name for this civ or else the generic specific name | |||||
let specific; | |||||
if (template.specificName) | |||||
specific = template.specificName[civ] || template.specificName.generic; | |||||
ret.name = { | ret.name = { | ||||
bbUnsubmitted Done Inline ActionsMerge this with ret declaration above. bb: Merge this with `ret` declaration above. | |||||
"specific": specific, | |||||
"generic": template.genericName, | "generic": template.genericName, | ||||
bbUnsubmitted Done Inline ActionsTrailling comma. bb: Trailling comma. | |||||
}; | }; | ||||
ret.icon = template.icon ? "technologies/" + template.icon : null; | if (template.icon) | ||||
ret.icon = "technologies/" + template.icon; | |||||
else | |||||
ret.icon = null; | |||||
bbUnsubmitted Done Inline ActionsShouldn't that be undefined (instead on null)? bb: Shouldn't that be `undefined` (instead on `null`)?
Imo ternary was better. | |||||
ret.description = template.description; | |||||
ret.reqs = DeriveTechnologyRequirements(template, civ); | |||||
return ret; | |||||
} | |||||
/** | |||||
* Get information about a technology template. | |||||
* @param template A valid template as obtained by loading the tech JSON file. | |||||
* @param civ Civilization for which the specific name should be returned. | |||||
bbUnsubmitted Done Inline ActionsImproper JsDocs (same as above). bb: Improper JsDocs (same as above). | |||||
*/ | |||||
function GetTechnologyDataHelper(template, civ, resources) | |||||
{ | |||||
let ret = GetTechnologyBasicDataHelper(template, civ); | |||||
if (template.specificName) | |||||
ret.name.specific = template.specificName[civ] || template.specificName.generic; | |||||
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); | ||||
ret.tooltip = template.tooltip; | ret.tooltip = template.tooltip; | ||||
ret.requirementsTooltip = template.requirementsTooltip || ""; | ret.requirementsTooltip = template.requirementsTooltip || ""; | ||||
ret.reqs = DeriveTechnologyRequirements(template, civ); | |||||
ret.description = template.description; | |||||
return ret; | return ret; | ||||
} | } | ||||
function calculateCarriedResources(carriedResources, tradingGoods) | function calculateCarriedResources(carriedResources, tradingGoods) | ||||
{ | { | ||||
var resources = {}; | var resources = {}; | ||||
if (carriedResources) | if (carriedResources) | ||||
Show All 13 Lines |
One could add spaces in the commented object for consistency, meh.
Committer can add them too