From 37d007d9abc8dc237b4e9ef5da1289b59e80b80f Mon Sep 17 00:00:00 2001 From: willyb321 Date: Sun, 17 Jun 2018 08:24:24 +1000 Subject: [PATCH 1/5] apply module blueprint and special before setting value Fixes #297 --- src/app/shipyard/Module.js | 2 +- src/app/utils/JournalUtils.js | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/app/shipyard/Module.js b/src/app/shipyard/Module.js index c5cde25d..193f37d2 100755 --- a/src/app/shipyard/Module.js +++ b/src/app/shipyard/Module.js @@ -72,7 +72,7 @@ export default class Module { * Set a value for a given modification ID * @param {Number} name The name of the modification * @param {object} value The value of the modification. If it is a numeric value then it should be an integer scaled so that -2.34% == -234 - * @param {bool} valueiswithspecial true if the value includes the special effect (when coming from a UI component) + * @param {Boolean} valueiswithspecial true if the value includes the special effect (when coming from a UI component) */ setModValue(name, value, valueiswithspecial) { if (!this.mods) { diff --git a/src/app/utils/JournalUtils.js b/src/app/utils/JournalUtils.js index 94c1b6be..cbfd7e45 100644 --- a/src/app/utils/JournalUtils.js +++ b/src/app/utils/JournalUtils.js @@ -252,6 +252,16 @@ function _addModifications(module, modifiers, blueprint, grade, specialModificat if (specialModifications) { special = Modifications.specials[specialModifications]; } + // Add the blueprint definition, grade and special + if (blueprint) { + module.blueprint = getBlueprint(blueprint, module); + if (grade) { + module.blueprint.grade = Number(grade); + } + if (special) { + module.blueprint.special = special; + } + } for (const i in modifiers) { // Some special modifications // Look up the modifiers to find what we need to do @@ -268,24 +278,14 @@ function _addModifications(module, modifiers, blueprint, grade, specialModificat if (modifiers[i].Label.search('Resistance') >= 0) { value = (modifiers[i].Value * 100) - (modifiers[i].OriginalValue * 100); } + // Carry out the required changes for (const action in modifierActions) { if (isNaN(modifierActions[action])) { module.setModValue(action, modifierActions[action]); } else { - module.setModValue(action, value); + module.setModValue(action, value, true); } } } - - // Add the blueprint definition, grade and special - if (blueprint) { - module.blueprint = getBlueprint(blueprint, module); - if (grade) { - module.blueprint.grade = Number(grade); - } - if (special) { - module.blueprint.special = special; - } - } } From 96626219807465feb81e8d8687a18d7a38950429 Mon Sep 17 00:00:00 2001 From: willyb321 Date: Tue, 26 Jun 2018 08:01:46 +1000 Subject: [PATCH 2/5] fix name of guardian pd --- src/app/shipyard/Constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shipyard/Constants.js b/src/app/shipyard/Constants.js index e7421e2f..70569e65 100755 --- a/src/app/shipyard/Constants.js +++ b/src/app/shipyard/Constants.js @@ -18,7 +18,7 @@ export const ModuleGroupToName = { // Standard pp: 'Power Plant', gpp: 'Guardian Hybrid Power Plant', - gpd: 'Guardian Hybrid Power Distributor', + gpd: 'Guardian Power Distributor', t: 'Thrusters', fsd: 'Frame Shift Drive', ls: 'Life Support', From 2aa6a6daa2622b5a3345e1c950d768d2ab1f3c42 Mon Sep 17 00:00:00 2001 From: willyb321 Date: Tue, 26 Jun 2018 08:01:57 +1000 Subject: [PATCH 3/5] translations update --- src/app/i18n/en.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/i18n/en.json b/src/app/i18n/en.json index c2c5d9dd..ff504e94 100644 --- a/src/app/i18n/en.json +++ b/src/app/i18n/en.json @@ -139,6 +139,7 @@ "t": "thrusters", "tp": "Torpedo Pylon", "ul": "Burst Laser", + "Send To EDEngineer": "Send To EDEngineer", "ws": "Frame Shift Wake Scanner", "rpl": "Repair Limpet Controller", "rcpl": "Recon Limpet Controller", From fd7923155fd30ebdf86c2b3899457739466e4e31 Mon Sep 17 00:00:00 2001 From: willyb321 Date: Tue, 26 Jun 2018 08:02:04 +1000 Subject: [PATCH 4/5] more prep for gpd --- src/app/components/AvailableModulesMenu.jsx | 2 +- src/app/components/StandardSlot.jsx | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/components/AvailableModulesMenu.jsx b/src/app/components/AvailableModulesMenu.jsx index 6d10c191..2fc495d8 100644 --- a/src/app/components/AvailableModulesMenu.jsx +++ b/src/app/components/AvailableModulesMenu.jsx @@ -90,7 +90,7 @@ const CATEGORIES = { 'experimental': ['axmc', 'axmr', 'rfl', 'xs', 'sfn', 'rcpl'], // Guardian - 'guardian': ['gpp', 'gpc', 'ggc'] + 'guardian': ['gpp', 'gpd', 'gpc', 'ggc'] }; /** diff --git a/src/app/components/StandardSlot.jsx b/src/app/components/StandardSlot.jsx index 18ba79a1..54ce4733 100644 --- a/src/app/components/StandardSlot.jsx +++ b/src/app/components/StandardSlot.jsx @@ -67,6 +67,9 @@ export default class StandardSlot extends TranslatedComponent { if (m && m.name && m.name === 'Guardian Hybrid Power Plant') { validMods = []; } + if (m && m.name && m.name === 'Guardian Power Distributor') { + validMods = []; + } let showModuleResistances = Persist.showModuleResistances(); let mass = m.getMass() || m.cargo || m.fuel || 0; From 39c2ca94c88aaf556c855fcad956114c65471281 Mon Sep 17 00:00:00 2001 From: willyb321 Date: Wed, 27 Jun 2018 05:54:52 +1000 Subject: [PATCH 5/5] add "send to edengineer" button --- src/app/components/ModalShoppingList.jsx | 79 +++++++++++++++++++++++- src/app/stores/Persist.js | 21 +++++++ 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/src/app/components/ModalShoppingList.jsx b/src/app/components/ModalShoppingList.jsx index f9f0a9d3..b143a66f 100644 --- a/src/app/components/ModalShoppingList.jsx +++ b/src/app/components/ModalShoppingList.jsx @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import TranslatedComponent from './TranslatedComponent'; -import ShortenUrl from '../utils/ShortenUrl'; +import request from 'superagent'; import Persist from '../stores/Persist'; /** @@ -22,7 +22,9 @@ export default class ModalShoppingList extends TranslatedComponent { this.state = { matsList: '', mats: {}, - matsPerGrade: Persist.getRolls() + cmdrName: Persist.getCmdr(), + matsPerGrade: Persist.getRolls(), + blueprints: [] }; } @@ -31,6 +33,61 @@ export default class ModalShoppingList extends TranslatedComponent { */ componentDidMount() { this.renderMats(); + this.registerBPs(); + } + + /** + * Convert mats object to string + */ + registerBPs() { + const ship = this.props.ship; + let blueprints = []; + for (const module of ship.costList) { + if (module.type === 'SHIP') { + continue; + } + if (module.m && module.m.blueprint) { + if (!module.m.blueprint.grade || !module.m.blueprint.grades) { + continue; + } + for (const g in module.m.blueprint.grades) { + if (g > module.m.blueprint.grade) { + continue; + } + blueprints.push({ blueprint: module.m.blueprint.grades[g], number: this.state.matsPerGrade[g] }); + } + } + } + this.setState({ blueprints }); + } + + /** + * Send all blueprints to ED Engineer + * @param {SyntheticEvent} event React event + */ + sendToEDEng(event) { + event.preventDefault(); + event.target.disabled = true; + event.target.innerText = 'Sending...'; + let countSent = 0; + let countTotal = this.state.blueprints.length; + const target = event.target; + for (const i of this.state.blueprints) { + request + .patch(`http://localhost:44405/${this.state.cmdrName}/shopping-list`) + .field('uuid', i.blueprint.uuid) + .field('size', i.number) + .end((err, res) => { + if (err) { + console.log(err); + } + countSent++; + if (countSent === countTotal) { + target.disabled = false; + target.innerText = 'Send to EDEngineer'; + } + }); + } } /** @@ -86,6 +143,17 @@ export default class ModalShoppingList extends TranslatedComponent { this.setState({ matsPerGrade: newState }); Persist.setRolls(newState); this.renderMats(); + this.registerBPs(); + } + + /** + * Handler for changing roll amounts + * @param {SyntheticEvent} e React Event + */ + cmdrChangeHandler(e) { + let cmdrName = e.target.value; + this.setState({ cmdrName }); + Persist.setCmdr(cmdrName); } /** @@ -95,6 +163,8 @@ export default class ModalShoppingList extends TranslatedComponent { render() { let translate = this.context.language.translate; this.changeHandler = this.changeHandler.bind(this); + this.cmdrChangeHandler = this.cmdrChangeHandler.bind(this); + this.sendToEDEng = this.sendToEDEng.bind(this); return
e.stopPropagation() }>

{translate('PHRASE_SHOPPING_MATS')}

@@ -114,6 +184,11 @@ export default class ModalShoppingList extends TranslatedComponent {