Changeset View
Standalone View
binaries/data/mods/public/gui/common/tooltips.js
Show First 20 Lines • Show All 175 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": g_Indent + details.join("\n" + g_Indent) | "details": g_Indent + details.join("\n" + g_Indent) | ||||
}); | }); | ||||
} | } | ||||
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:")), | |||||
"details": | |||||
Object.keys(resistanceTypeTemplate).map( | |||||
statusEffect => { | |||||
if (resistanceTypeTemplate[statusEffect].blockChance == 1) | |||||
return sprintf(translate("Blocks %(name)s"), { | |||||
"name": unitFont(translateWithContext("status effect", g_StatusEffectsMetadata.getName(statusEffect))) | |||||
}); | |||||
if (resistanceTypeTemplate[statusEffect].blockChance == 0) | |||||
return sprintf(translate("%(name)s %(details)s"), { | |||||
"name": unitFont(translateWithContext("status effect", g_StatusEffectsMetadata.getName(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.getName(statusEffect))), | |||||
"details": sprintf(translate("Blocks: %(blockPercentage)s%%"), { | |||||
"blockPercentage": resistanceTypeTemplate[statusEffect].blockChance * 100 | |||||
bb: The mathematician in me screams overly load: a chance is a value in [0,1] NOT a percentage. One… | |||||
}) | |||||
}); | |||||
return sprintf(translate("%(name)s %(details)s"), { | |||||
"name": unitFont(translateWithContext("status effect", g_StatusEffectsMetadata.getName(statusEffect))), | |||||
"details": sprintf(translate("Blocks: %(blockPercentage)s%%, Duration reduction: %(durationReduction)s%%"), { | |||||
"blockPercentage": 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 100 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
function applyStatusDetails(applyStatusTemplate) | function applyStatusDetails(applyStatusTemplate) | ||||
{ | { | ||||
if (!applyStatusTemplate) | if (!applyStatusTemplate) | ||||
return ""; | return ""; | ||||
return sprintf(translate("gives %(name)s"), { | return sprintf(translate("gives %(name)s"), { | ||||
"name": Object.keys(applyStatusTemplate).map(x => { | "name": Object.keys(applyStatusTemplate).map(x => | ||||
let template = g_StatusEffectsMetadata.augment(x, applyStatusTemplate[x]); | unitFont(translateWithContext("status effect", g_StatusEffectsMetadata.getName(x))) | ||||
return unitFont(translateWithContext("status effect", template.StatusName)); | ).join(commaFont(translate(", "))), | ||||
}).join(commaFont(translate(", "))), | |||||
}); | }); | ||||
} | } | ||||
function attackEffectsDetails(attackTypeTemplate) | function attackEffectsDetails(attackTypeTemplate) | ||||
{ | { | ||||
if (!attackTypeTemplate) | if (!attackTypeTemplate) | ||||
return ""; | return ""; | ||||
Show All 29 Lines | if (template.buildingAI) | ||||
projectiles = template.buildingAI.arrowCount || template.buildingAI.defaultArrowCount; | projectiles = template.buildingAI.arrowCount || template.buildingAI.defaultArrowCount; | ||||
let splashTemplate = attackTypeTemplate.splash; | let splashTemplate = attackTypeTemplate.splash; | ||||
// Show the effects of status effects below. | // Show the effects of status effects below. | ||||
let statusEffectsDetails = []; | let statusEffectsDetails = []; | ||||
if (attackTypeTemplate.ApplyStatus) | if (attackTypeTemplate.ApplyStatus) | ||||
for (let status in attackTypeTemplate.ApplyStatus) | for (let status in attackTypeTemplate.ApplyStatus) | ||||
{ | statusEffectsDetails.push("\n" + g_Indent + g_Indent + getStatusEffectsTooltip(status, attackTypeTemplate.ApplyStatus[status], true)); | ||||
let status_template = g_StatusEffectsMetadata.augment(status, attackTypeTemplate.ApplyStatus[status]); | |||||
statusEffectsDetails.push("\n" + g_Indent + g_Indent + getStatusEffectsTooltip(status_template, true)); | |||||
} | |||||
statusEffectsDetails = statusEffectsDetails.join(""); | statusEffectsDetails = statusEffectsDetails.join(""); | ||||
tooltips.push(sprintf(translate("%(attackLabel)s: %(effects)s, %(range)s, %(rate)s%(statusEffects)s%(splash)s"), { | tooltips.push(sprintf(translate("%(attackLabel)s: %(effects)s, %(range)s, %(rate)s%(statusEffects)s%(splash)s"), { | ||||
"attackLabel": attackLabel, | "attackLabel": attackLabel, | ||||
"effects": attackEffectsDetails(attackTypeTemplate), | "effects": attackEffectsDetails(attackTypeTemplate), | ||||
"range": rangeDetails(attackTypeTemplate), | "range": rangeDetails(attackTypeTemplate), | ||||
"rate": attackRateDetails(attackTypeTemplate.repeatTime, projectiles), | "rate": attackRateDetails(attackTypeTemplate.repeatTime, projectiles), | ||||
"splash": splashTemplate ? "\n" + g_Indent + g_Indent + splashDetails(splashTemplate) : "", | "splash": splashTemplate ? "\n" + g_Indent + g_Indent + splashDetails(splashTemplate) : "", | ||||
"statusEffects": statusEffectsDetails | "statusEffects": statusEffectsDetails | ||||
})); | })); | ||||
} | } | ||||
return sprintf(translate("%(label)s\n%(details)s"), { | return sprintf(translate("%(label)s\n%(details)s"), { | ||||
"label": headerFont(translate("Attack:")), | "label": headerFont(translate("Attack:")), | ||||
"details": g_Indent + tooltips.join("\n" + g_Indent) | "details": g_Indent + tooltips.join("\n" + g_Indent) | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* @param applier - if true, return the tooltip for the Applier. If false, Receiver is returned. | * @param applier - if true, return the tooltip for the Applier. If false, Receiver is returned. | ||||
*/ | */ | ||||
function getStatusEffectsTooltip(template, applier) | function getStatusEffectsTooltip(statusCode, template, applier) | ||||
{ | { | ||||
let tooltipAttributes = []; | let tooltipAttributes = []; | ||||
if (applier && template.ApplierTooltip) | if (applier) | ||||
tooltipAttributes.push(translate(template.ApplierTooltip)); | { | ||||
else if (!applier && template.ReceiverTooltip) | let applierTooltip = g_StatusEffectsMetadata.getApplierTooltip(statusCode); | ||||
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(translate(template.ReceiverTooltip)); | if (applierTooltip) | ||||
tooltipAttributes.push(translate(applierTooltip)); | |||||
} | |||||
else | |||||
{ | |||||
let receiverTooltip = g_StatusEffectsMetadata.getReceiverTooltip(statusCode); | |||||
if (receiverTooltip) | |||||
tooltipAttributes.push(translate(receiverTooltip)); | |||||
} | |||||
wraitiiUnsubmitted 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… | |||||
if (template.Damage || template.Capture) | if (template.Damage || template.Capture) | ||||
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) | ||||
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", g_StatusEffectsMetadata.getName(statusCode))), | ||||
"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", g_StatusEffectsMetadata.getName(statusCode))), | ||||
"statusInfo": tooltipAttributes.join(commaFont(translate(", "))) | "statusInfo": tooltipAttributes.join(commaFont(translate(", "))) | ||||
bbUnsubmitted 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… | |||||
FreagarachAuthorUnsubmitted 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 559 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 %