Changeset View
Standalone View
binaries/data/mods/public/gui/common/tooltips.js
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | function getResistanceTooltip(template) | ||||
let details = []; | let details = []; | ||||
if (template.resistance.Damage) | if (template.resistance.Damage) | ||||
details.push(getDamageResistanceTooltip(template.resistance.Damage)); | details.push(getDamageResistanceTooltip(template.resistance.Damage)); | ||||
if (template.resistance.Capture) | if (template.resistance.Capture) | ||||
details.push(getCaptureResistanceTooltip(template.resistance.Capture)); | details.push(getCaptureResistanceTooltip(template.resistance.Capture)); | ||||
// ToDo: Status effects resistance. | if (template.resistance.ApplyStatus) | ||||
details.push(getStatusEffectsResistanceTooltip(template.resistance.ApplyStatus)); | |||||
return sprintf(translate("%(label)s\n %(details)s"), { | return sprintf(translate("%(label)s\n %(details)s"), { | ||||
"label": headerFont(translate("Resistance:")), | "label": headerFont(translate("Resistance:")), | ||||
"details": details.join("\n ") | "details": details.join("\n ") | ||||
}); | }); | ||||
} | } | ||||
function getDamageResistanceTooltip(resistanceTypeTemplate) | function getDamageResistanceTooltip(resistanceTypeTemplate) | ||||
Show All 32 Lines | "details": | ||||
'[font="sans-10"]' + | '[font="sans-10"]' + | ||||
sprintf(translate("(%(resistancePercentage)s)"), { | sprintf(translate("(%(resistancePercentage)s)"), { | ||||
"resistancePercentage": resistanceLevelToPercentageString(resistanceTypeTemplate) | "resistancePercentage": resistanceLevelToPercentageString(resistanceTypeTemplate) | ||||
}) + '[/font]' | }) + '[/font]' | ||||
}) | }) | ||||
}); | }); | ||||
} | } | ||||
function getStatusEffectsResistanceTooltip(resistanceTypeTemplate) | |||||
{ | |||||
if (!resistanceTypeTemplate) | |||||
return ""; | |||||
return sprintf(translate("%(label)s %(details)s"), { | |||||
"label": headerFont(translate("Status Effects Resistance:")), | |||||
"details": | |||||
Object.keys(resistanceTypeTemplate).map( | |||||
statusEffect => { | |||||
if (resistanceTypeTemplate[statusEffect].blockChance == 1) | |||||
return sprintf(translate("Blocks %(name)s"), { | |||||
"name": unitFont(translateWithContext("status effect", g_StatusEffectsMetadata.augment(statusEffect) || statusEffect)) | |||||
}); | |||||
if (resistanceTypeTemplate[statusEffect].blockChance == 0) | |||||
return sprintf(translate("%(name)s %(details)s"), { | |||||
"name": unitFont(translateWithContext("status effect", g_StatusEffectsMetadata.augment(statusEffect) || statusEffect)), | |||||
"details": sprintf(translate("Duration reduction: %(durationReduction)s%%"), { | |||||
"durationReduction": (100 - resistanceTypeTemplate[statusEffect].duration * 100) | |||||
}) | |||||
}); | |||||
if (resistanceTypeTemplate[statusEffect].duration == 1) | |||||
return sprintf(translate("%(name)s %(details)s"), { | |||||
"name": unitFont(translateWithContext("status effect", g_StatusEffectsMetadata.augment(statusEffect) || statusEffect)), | |||||
"details": sprintf(translate("Block chance: %(blockChance)s%%"), { | |||||
bb: The mathematician in me screams overly load: a chance is a value in [0,1] NOT a percentage. One… | |||||
"blockChance": resistanceTypeTemplate[statusEffect].blockChance * 100 | |||||
}) | |||||
}); | |||||
return sprintf(translate("%(name)s %(details)s"), { | |||||
"name": unitFont(translateWithContext("status effect", g_StatusEffectsMetadata.augment(statusEffect) || statusEffect)), | |||||
"details": sprintf(translate("Block chance: %(blockChance)s%%, Duration reduction: %(durationReduction)s%%"), { | |||||
"blockChance": resistanceTypeTemplate[statusEffect].blockChance * 100, | |||||
"durationReduction": (100 - resistanceTypeTemplate[statusEffect].duration * 100) | |||||
}) | |||||
}); | |||||
} | |||||
).join(commaFont(translate(", "))) | |||||
}); | |||||
} | |||||
function attackRateDetails(interval, projectiles) | function attackRateDetails(interval, projectiles) | ||||
{ | { | ||||
if (!interval) | if (!interval) | ||||
return ""; | return ""; | ||||
if (projectiles === 0) | if (projectiles === 0) | ||||
return translate("Garrison to fire arrows"); | return translate("Garrison to fire arrows"); | ||||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | |||||
function getStatusEffectsTooltip(template, applier) | function getStatusEffectsTooltip(template, applier) | ||||
{ | { | ||||
let tooltipAttributes = []; | let tooltipAttributes = []; | ||||
if (applier && template.ApplierTooltip) | if (applier && template.ApplierTooltip) | ||||
tooltipAttributes.push(translate(template.ApplierTooltip)); | tooltipAttributes.push(translate(template.ApplierTooltip)); | ||||
else if (!applier && template.ReceiverTooltip) | else if (!applier && template.ReceiverTooltip) | ||||
tooltipAttributes.push(translate(template.ReceiverTooltip)); | tooltipAttributes.push(translate(template.ReceiverTooltip)); | ||||
if (template.Damage || template.Capture) | if (template.Damage || template.Capture) | ||||
Done Inline Actionsinstead of calling the globalscript 3 times, and checking for existence again, one could consider calling getData and pull the stuff from there bb: instead of calling the globalscript 3 times, and checking for existence again, one could… | |||||
Done Inline ActionsIt is actually only called twice and the getName is convenient to have separately. So using getData.property would be not necessary IMHO. Freagarach: It is actually only called twice and the `getName` is convenient to have separately. So using… | |||||
tooltipAttributes.push(attackEffectsDetails(template)); | tooltipAttributes.push(attackEffectsDetails(template)); | ||||
if (template.Interval) | if (template.Interval) | ||||
tooltipAttributes.push(attackRateDetails(+template.Interval)); | tooltipAttributes.push(attackRateDetails(+template.Interval)); | ||||
if (template.Duration) | if (template.Duration) | ||||
tooltipAttributes.push(getStatusEffectDurationTooltip(template)); | tooltipAttributes.push(getStatusEffectDurationTooltip(template)); | ||||
if (applier) | if (applier) | ||||
Done Inline ActionsI feel like it would be better to put the description after the actual info. First, it avoids an awkward case with multiple sentences (you currently ought not end with a dot), and it makes more sense game-play wise. (I realise you're just changing this here). wraitii: I feel like it would be better to put the description after the actual info. First, it avoids… | |||||
return sprintf(translate("%(statusName)s: %(statusInfo)s %(stackability)s"), { | return sprintf(translate("%(statusName)s: %(statusInfo)s %(stackability)s"), { | ||||
"statusName": headerFont(translateWithContext("status effect", template.StatusName)), | "statusName": headerFont(translateWithContext("status effect", template.StatusName)), | ||||
"statusInfo": tooltipAttributes.join(commaFont(translate(", "))), | "statusInfo": tooltipAttributes.join(commaFont(translate(", "))), | ||||
"stackability": getStatusEffectStackabilityTooltip(template) | "stackability": getStatusEffectStackabilityTooltip(template) | ||||
}); | }); | ||||
return sprintf(translate("%(statusName)s: %(statusInfo)s"), { | return sprintf(translate("%(statusName)s: %(statusInfo)s"), { | ||||
"statusName": headerFont(translateWithContext("status effect", template.StatusName)), | "statusName": headerFont(translateWithContext("status effect", template.StatusName)), | ||||
"statusInfo": tooltipAttributes.join(commaFont(translate(", "))) | "statusInfo": tooltipAttributes.join(commaFont(translate(", "))) | ||||
Done Inline Actionsstill under the hood we are calling g_StatusEffectsMetadata.getData twice, whatever parameters are passed. Why not add the defaults in the constructor and call getData once to replace all 4 appearances? bb: still under the hood we are calling g_StatusEffectsMetadata.getData twice, whatever parameters… | |||||
Done Inline ActionsBecause I like to be explicit. Freagarach: Because I like to be explicit. | |||||
}); | }); | ||||
} | } | ||||
function getStatusEffectDurationTooltip(template) | function getStatusEffectDurationTooltip(template) | ||||
{ | { | ||||
if (!template.Duration) | if (!template.Duration) | ||||
return ""; | return ""; | ||||
▲ Show 20 Lines • Show All 547 Lines • Show Last 20 Lines |
The mathematician in me screams overly load: a chance is a value in [0,1] NOT a percentage. One can say that in x% of the cases something happens, but not that the chance is x%.
So either Block Chance: resistanceTypeTemplate[statusEffect].blockChance or Blocks: resistanceTypeTemplate[statusEffect].blockChance * 100 %