From a65bb06754e237a603d8fd4b232f7b8443aefba2 Mon Sep 17 00:00:00 2001 From: Felix Linker Date: Mon, 1 Feb 2021 22:40:01 +0100 Subject: [PATCH] Implement tooltips for experimental effects --- src/app/components/ModificationsMenu.jsx | 14 ++--- src/app/utils/BlueprintFunctions.js | 74 +++++++++--------------- 2 files changed, 31 insertions(+), 57 deletions(-) diff --git a/src/app/components/ModificationsMenu.jsx b/src/app/components/ModificationsMenu.jsx index 2f06005f..006ffd95 100644 --- a/src/app/components/ModificationsMenu.jsx +++ b/src/app/components/ModificationsMenu.jsx @@ -102,21 +102,15 @@ export default class ModificationsMenu extends TranslatedComponent { const experimentals = []; for (const experimental of m.getApplicableExperimentals()) { const active = experimental === applied; - // TODO: - // let specialTt = specialToolTip( - // translate, - // m.blueprint.grades[m.blueprint.grade], - // m.grp, m, - // experimental, - // ); + let specialTt = specialToolTip(language, m, experimental); experimentals.push(
{ this.selectedSpecialRef = ref; } : undefined} - // onMouseOver={termtip.bind(null, specialTt)} - // onMouseOut={tooltip.bind(null, null)} + onMouseOver={termtip.bind(null, specialTt)} + onMouseOut={tooltip.bind(null, null)} >{translate(experimental)}
); } @@ -273,7 +267,7 @@ export default class ModificationsMenu extends TranslatedComponent { let specialTt; if (appliedExperimental) { specialLabel = appliedExperimental; - // specialTt = specialToolTip(translate, m.blueprint.grades[m.blueprint.grade], m.grp, m, m.blueprint.special.edname); + specialTt = specialToolTip(language, m, appliedExperimental); } renderComponents.push(
- {translate(feature, grp)} -   - {current}{symbol} -   - - ); - } - } - } - } - +export function specialToolTip(language, m, specialName) { + const { formats, translate } = language; return (
- {effects} + {entries(getExperimentalInfo(specialName).features).map( + ([prop, feats]) => { + const { max, only } = feats; + if (only && !m.getItem().match(only)) { + return null; + } + + const { value, unit, beneficial } = m.getModifierFormatted(prop); + // If the product of value and min/max is positive, both values + // point into the same direction, i.e. positive/negative. + const specialBeneficial = (value * max) > 0 === beneficial; + + return + + + + + ; + } + )}
{translate(prop)} {formats.round(max * 100)}{unit}