Changeset View
Standalone View
binaries/data/mods/public/gui/reference/common/draw.js
/** | /** | ||||
* GUI limits. Populated if needed by a predraw() function. | * GUI limits. Populated if needed by a predraw() function. | ||||
*/ | */ | ||||
var g_DrawLimits = {}; | var g_DrawLimits = {}; | ||||
/** | /** | ||||
* These functions are defined in gui/common/tooltips.js | * List of functions that get the statistics of any template or entity, | ||||
* formatted in such a way as to appear in a tooltip. | |||||
* | |||||
* The functions listed are defined in gui/common/tooltips.js | |||||
*/ | */ | ||||
var g_TooltipFunctions = [ | var g_StatsFunctions = [ | ||||
elexis: The arrays should be optimized to be as eay as possible to edit, i.e. without having to lookup… | |||||
getEntityNamesFormatted, | |||||
getEntityCostTooltip, | |||||
getEntityTooltip, | |||||
getAurasTooltip, | |||||
getHealthTooltip, | getHealthTooltip, | ||||
getHealerTooltip, | getHealerTooltip, | ||||
getAttackTooltip, | getAttackTooltip, | ||||
getSplashDamageTooltip, | getSplashDamageTooltip, | ||||
getArmorTooltip, | getArmorTooltip, | ||||
getGarrisonTooltip, | getGarrisonTooltip, | ||||
getProjectilesTooltip, | getProjectilesTooltip, | ||||
getSpeedTooltip, | getSpeedTooltip, | ||||
getGatherTooltip, | getGatherTooltip, | ||||
getResourceSupplyTooltip, | |||||
getPopulationBonusTooltip, | getPopulationBonusTooltip, | ||||
getResourceTrickleTooltip, | getResourceTrickleTooltip, | ||||
getLootTooltip | getLootTooltip | ||||
]; | ]; | ||||
/** | /** | ||||
* Concatanates the return values of the array of passed functions. | * Concatanates the return values of the array of passed functions. | ||||
* | * | ||||
* @param {object} template | * @param {object} template | ||||
* @param {array} textFunctions | * @param {array} textFunctions | ||||
Done Inline ActionsI assume it would be more readable not to concat here but in the place using it. elexis: I assume it would be more readable not to concat here but in the place using it.
A bit… | |||||
* @param {string} joiner | * @param {string} joiner | ||||
Done Inline ActionsObject- and function-based programming should be prefered over procedural programming,. Hence statements in global context that aren't assignments should be avoided where possible. JS concat supports multiple arguments elexis: Object- and function-based programming should be prefered over procedural programming,. Hence… | |||||
* @return {string} The built text. | * @return {string} The built text. | ||||
*/ | */ | ||||
function buildText(template, textFunctions=[], joiner="\n") | function buildText(template, textFunctions=[], joiner="\n") | ||||
{ | { | ||||
return textFunctions.map(func => func(template)).filter(tip => tip).join(joiner); | return textFunctions.map(func => func(template)).filter(tip => tip).join(joiner); | ||||
} | } | ||||
/** | |||||
Done Inline ActionsThe two string functions should be grouped IMO (rename comment from the other one applies here too) elexis: The two string functions should be grouped IMO (rename comment from the other one applies here… | |||||
* Returns the resources this entity supplies in the specified entity's tooltip | |||||
*/ | |||||
Done Inline Actions(Perhaps there will be this one guy on transifex needing to know which information that is about) elexis: (Perhaps there will be this one guy on transifex needing to know which information that is… | |||||
function getResourceSupplyTooltip(template) | |||||
{ | |||||
if (!template.supply) | |||||
return ""; | |||||
let supply = template.supply; | |||||
let type = supply.type[0] == "treasure" ? supply.type[1] : supply.type[0]; | |||||
// Translation: Label in tooltip showing the resource type and quantity of a given resource supply. | |||||
return sprintf(translate("%(label)s %(component)s %(amount)s"), { | |||||
"label": headerFont(translate("Resource Supply:")), | |||||
"component": resourceIcon(type), | |||||
// Translation: Marks that a resource supply entity has an unending, infinite, supply of its resource. | |||||
"amount": Number.isFinite(+supply.amount) ? supply.amount : translate("∞") | |||||
}); | |||||
} |
The arrays should be optimized to be as eay as possible to edit, i.e. without having to lookup the code where its used. Where they are defined is secondary.