From 0f90efaa54e24e3c7b6db7a5cb8df7f9b7fb1c57 Mon Sep 17 00:00:00 2001 From: ExitCode Date: Sun, 22 Apr 2018 05:31:16 +0200 Subject: [PATCH 1/4] Implemented a func to determine the current percentage level of a mod --- src/app/utils/BlueprintFunctions.js | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/app/utils/BlueprintFunctions.js b/src/app/utils/BlueprintFunctions.js index 29a342f7..2367570b 100644 --- a/src/app/utils/BlueprintFunctions.js +++ b/src/app/utils/BlueprintFunctions.js @@ -311,3 +311,60 @@ function _setValue(ship, m, featureName, value) { ship.setModification(m, featureName, value); } } + +/** + * Provide 'percent' primary query + * @param {Object} m The module for which to perform the query + * @returns {Number} percent The percentage indicator of current applied values. + */ +export function getPercent(m) { + let result = null; + const features = m.blueprint.grades[m.blueprint.grade].features; + for (const featureName in features) { + + if (features[featureName][0] === features[featureName][1]) { + continue; + } + + let value = _getValue(m, featureName); + let mult; + if (Modifications.modifications[featureName].higherbetter) { + // Higher is better, but is this making it better or worse? + if (features[featureName][0] < 0 || (features[featureName][0] === 0 && features[featureName][1] < 0)) { + mult = Math.round((value - features[featureName][1]) / (features[featureName][0] - features[featureName][1]) * 100); + } else { + mult = Math.round((value - features[featureName][0]) / (features[featureName][1] - features[featureName][0]) * 100); + } + } else { + // Higher is worse, but is this making it better or worse? + if (features[featureName][0] < 0 || (features[featureName][0] === 0 && features[featureName][1] < 0)) { + mult = Math.round((value - features[featureName][0]) / (features[featureName][1] - features[featureName][0]) * 100); + } else { + mult = Math.round((value - features[featureName][1]) / (features[featureName][0] - features[featureName][1]) * 100); + } + } + + if (result && result != mult) { + return null; + } else if (result != mult) { + result = mult; + } + } + + return result; +} + +/** + * Query a feature value + * @param {Object} m The module for which to perform the query + * @param {string} featureName The feature being queried + */ +function _getValue(m, featureName) { + if (Modifications.modifications[featureName].type == 'percentage') { + return m.getModValue(featureName) / 10000; + } else if (Modifications.modifications[featureName].type == 'numeric') { + return m.getModValue(featureName) / 100; + } else { + return m.getModValue(featureName); + } +} From 1d36d41da1ab977406e62b3d7580c34582e8930f Mon Sep 17 00:00:00 2001 From: ExitCode Date: Sun, 22 Apr 2018 05:33:47 +0200 Subject: [PATCH 2/4] Tuned visibility of components in mod menu --- src/app/components/ModificationsMenu.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/components/ModificationsMenu.jsx b/src/app/components/ModificationsMenu.jsx index 9171da8b..a341813f 100644 --- a/src/app/components/ModificationsMenu.jsx +++ b/src/app/components/ModificationsMenu.jsx @@ -258,8 +258,8 @@ export default class ModificationsMenu extends TranslatedComponent { const showSpecial = haveBlueprint && specials.length && !blueprintMenuOpened; const showSpecialsMenu = specialMenuOpened; const showRolls = haveBlueprint && !blueprintMenuOpened && !specialMenuOpened; - const showReset = !blueprintMenuOpened && !specialMenuOpened; - const showMods = !blueprintMenuOpened && !specialMenuOpened; + const showReset = !blueprintMenuOpened && !specialMenuOpened && haveBlueprint; + const showMods = !blueprintMenuOpened && !specialMenuOpened && haveBlueprint; return (
Date: Sun, 22 Apr 2018 05:34:25 +0200 Subject: [PATCH 3/4] Added a spacer between the mod values --- src/app/components/ModificationsMenu.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/components/ModificationsMenu.jsx b/src/app/components/ModificationsMenu.jsx index a341813f..bb1e83a3 100644 --- a/src/app/components/ModificationsMenu.jsx +++ b/src/app/components/ModificationsMenu.jsx @@ -290,6 +290,7 @@ export default class ModificationsMenu extends TranslatedComponent { : null } : null } + { showMods ?
: null } { showMods ? { this._renderModifications(this.props) } From dbfe68decbdeee9f4964e8b2c6d067877f6272ca Mon Sep 17 00:00:00 2001 From: ExitCode Date: Sun, 22 Apr 2018 05:36:19 +0200 Subject: [PATCH 4/4] Implemented active selected blueprint value highlight; updated look and feel --- src/app/components/ModificationsMenu.jsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/app/components/ModificationsMenu.jsx b/src/app/components/ModificationsMenu.jsx index bb1e83a3..14d32f78 100644 --- a/src/app/components/ModificationsMenu.jsx +++ b/src/app/components/ModificationsMenu.jsx @@ -6,7 +6,7 @@ import { isEmpty, stopCtxPropagation } from '../utils/UtilityFunctions'; import cn from 'classnames'; import { Modifications } from 'coriolis-data/dist'; import Modification from './Modification'; -import { getBlueprint, blueprintTooltip, setPercent, setRandom } from '../utils/BlueprintFunctions'; +import { getBlueprint, blueprintTooltip, setPercent, getPercent, setRandom } from '../utils/BlueprintFunctions'; /** * Modifications menu @@ -239,10 +239,12 @@ export default class ModificationsMenu extends TranslatedComponent { let blueprintLabel; let haveBlueprint = false; let blueprintTt; + let blueprintCv; if (m.blueprint && m.blueprint.name) { blueprintLabel = translate(m.blueprint.name) + ' ' + translate('grade') + ' ' + m.blueprint.grade; haveBlueprint = true; blueprintTt = blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade], Modifications.modules[m.grp].blueprints[m.blueprint.fdname].grades[m.blueprint.grade].engineers, m.grp); + blueprintCv = getPercent(m); } let specialLabel; @@ -273,20 +275,18 @@ export default class ModificationsMenu extends TranslatedComponent { { showBlueprintsMenu ? this._renderBlueprints(this.props, this.context) : null } { showSpecial & !showSpecialsMenu ?
{specialLabel}
: null } { showSpecialsMenu ? specials : null } - { showRolls || showReset ? + { showReset ?
{ translate('reset') }
: null } + { showRolls ? + { showRolls ? - - - - - : null } - { showReset ? - - + + + + : null }
{ translate('roll') }: { translate('0%') } { translate('50%') } { translate('100%') } { translate('random') }
{ translate('reset') } { translate('0%') } { translate('50%') } { translate('100%') } { translate('random') }
: null }