From f82122f29f968cd55859be25137b558def56e8a5 Mon Sep 17 00:00:00 2001 From: Cmdr McDonald Date: Sun, 18 Dec 2016 21:37:21 +0000 Subject: [PATCH] Add module copy functionality - drag module whilst holding 'alt' to copy --- ChangeLog.md | 1 + src/app/components/HardpointSlot.jsx | 2 +- src/app/components/InternalSlot.jsx | 2 +- src/app/components/SlotSection.jsx | 36 ++++++++++++++++++---------- src/app/components/StandardSlot.jsx | 2 +- src/app/pages/AboutPage.jsx | 9 ------- src/app/shipyard/Module.js | 26 +++++++++++++------- 7 files changed, 45 insertions(+), 33 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index a2d989ce..db6b395f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -17,6 +17,7 @@ * Add 'Damage received' section * Add 'Piercing' information to hardpoints * Add 'Hardness' information to ship summary + * Add module copy functionality - drag module whilst holding 'alt' to copy #2.2.5 * Calculate rate of fire for multi-burst weapons diff --git a/src/app/components/HardpointSlot.jsx b/src/app/components/HardpointSlot.jsx index 5941f805..cc1d80ac 100644 --- a/src/app/components/HardpointSlot.jsx +++ b/src/app/components/HardpointSlot.jsx @@ -46,7 +46,7 @@ export default class HardpointSlot extends Slot { // Modifications tooltip shows blueprint and grade, if available let modTT = translate('modified'); - if (m && m.blueprint) { + if (m && m.blueprint && m.blueprint.name) { modTT = translate(m.blueprint.name) + ' ' + translate('grade') + ' ' + m.blueprint.grade; if (m.blueprint.special && m.blueprint.special.id) { modTT += ', ' + translate(m.blueprint.special.name); diff --git a/src/app/components/InternalSlot.jsx b/src/app/components/InternalSlot.jsx index cfd6e7ff..cfa066b4 100644 --- a/src/app/components/InternalSlot.jsx +++ b/src/app/components/InternalSlot.jsx @@ -28,7 +28,7 @@ export default class InternalSlot extends Slot { // Modifications tooltip shows blueprint and grade, if available let modTT = translate('modified'); - if (m && m.blueprint) { + if (m && m.blueprint && m.blueprint.name) { modTT = translate(m.blueprint.name) + ' ' + translate('grade') + ' ' + m.blueprint.grade; } diff --git a/src/app/components/SlotSection.jsx b/src/app/components/SlotSection.jsx index 4a339a33..d0789448 100644 --- a/src/app/components/SlotSection.jsx +++ b/src/app/components/SlotSection.jsx @@ -77,7 +77,7 @@ export default class SlotSection extends TranslatedComponent { _drag(originSlot, e) { e.dataTransfer.setData('text/html', e.currentTarget); e.dataTransfer.effectAllowed = 'all'; - this.setState({ originSlot }); + this.setState({ originSlot, copy: e.getModifierState('Alt') }); this._close(); } @@ -91,7 +91,9 @@ export default class SlotSection extends TranslatedComponent { e.stopPropagation(); let os = this.state.originSlot; if (os) { - e.dataTransfer.dropEffect = os != targetSlot && canMount(this.props.ship, targetSlot, os.m.grp, os.m.class) ? 'copyMove' : 'none'; + // Show correct icon + const effect = this.state.copy ? 'copy' : 'move'; + e.dataTransfer.dropEffect = os != targetSlot && canMount(this.props.ship, targetSlot, os.m.grp, os.m.class) ? effect : 'none'; this.setState({ targetSlot }); } else { e.dataTransfer.dropEffect = 'none'; @@ -114,20 +116,30 @@ export default class SlotSection extends TranslatedComponent { * the origin slot will be empty. */ _drop() { - let { originSlot, targetSlot } = this.state; + let { originSlot, targetSlot, copy } = this.state; let m = originSlot.m; - if (targetSlot && m && canMount(this.props.ship, targetSlot, m.grp, m.class)) { - // Swap modules if possible - if (targetSlot.m && canMount(this.props.ship, originSlot, targetSlot.m.grp, targetSlot.m.class)) { - this.props.ship.use(originSlot, targetSlot.m, true); - } else { // Otherwise empty the origin slot - this.props.ship.use(originSlot, null, true); // Empty but prevent summary update + if (copy) { + // We want to copy the module in to the target slot + if (targetSlot && canMount(this.props.ship, targetSlot, m.grp, m.class)) { + const mCopy = m.clone(); + this.props.ship.use(targetSlot, mCopy); + this.props.onChange(); + } + } else { + // We want to move the module in to the target slot, and swap back any module that was originally in the target slot + if (targetSlot && m && canMount(this.props.ship, targetSlot, m.grp, m.class)) { + // Swap modules if possible + if (targetSlot.m && canMount(this.props.ship, originSlot, targetSlot.m.grp, targetSlot.m.class)) { + this.props.ship.use(originSlot, targetSlot.m, true); + } else { // Otherwise empty the origin slot + this.props.ship.use(originSlot, null, true); // Empty but prevent summary update + } + this.props.ship.use(targetSlot, m); // update target slot + this.props.onChange(); } - this.props.ship.use(targetSlot, m); // update target slot - this.props.onChange(); } - this.setState({ originSlot: null, targetSlot: null }); + this.setState({ originSlot: null, targetSlot: null, copy: null }); } /** diff --git a/src/app/components/StandardSlot.jsx b/src/app/components/StandardSlot.jsx index 9bd56da9..ebbd5485 100644 --- a/src/app/components/StandardSlot.jsx +++ b/src/app/components/StandardSlot.jsx @@ -52,7 +52,7 @@ export default class StandardSlot extends TranslatedComponent { // Modifications tooltip shows blueprint and grade, if available let modTT = translate('modified'); - if (m && m.blueprint) { + if (m && m.blueprint && m.blueprint.name) { modTT = translate(m.blueprint.name) + ' ' + translate('grade') + ' ' + m.blueprint.grade; } diff --git a/src/app/pages/AboutPage.jsx b/src/app/pages/AboutPage.jsx index 77579786..7cfaa1fd 100644 --- a/src/app/pages/AboutPage.jsx +++ b/src/app/pages/AboutPage.jsx @@ -39,15 +39,6 @@ export default class AboutPage extends Page {

Coriolis is an open source project. Checkout the list of upcoming features and to-do list on github. Any and all contributions and feedback are welcome. If you encounter any bugs please report them and provide as much detail as possible.

-
- - - - -
- -

Help keep the lights on! Donations will be used to cover costs of running and maintaining Coriolis. Thanks for helping!

-

Chat

You can chat to us on our EDCD Discord server.

; diff --git a/src/app/shipyard/Module.js b/src/app/shipyard/Module.js index 4236d015..37879de6 100755 --- a/src/app/shipyard/Module.js +++ b/src/app/shipyard/Module.js @@ -12,20 +12,28 @@ export default class Module { * @param {Object} params Module parameters. Either grp/id or template */ constructor(params) { - let properties = Object.assign({ grp: null, id: null, template: null, }, params); + let properties = Object.assign({ grp: null, id: null, template: null }, params); - let template; - if (properties.template == undefined) { - return ModuleUtils.findModule(properties.grp, properties.id); + if (properties.class != undefined) { + // We already have a fully-formed module; copy the data over + for (let p in properties) { this[p] = properties[p]; } + } else if (properties.template != undefined) { + // We have a template from coriolis-data; copy the data over + for (let p in properties.template) { this[p] = properties.template[p]; } } else { - template = properties.template; - if (template) { - // Copy all properties from coriolis-data template - for (let p in template) { this[p] = template[p]; } - } + // We don't have a template; find it given the group and ID + return ModuleUtils.findModule(properties.grp, properties.id); } } + /** + * Clone an existing module + * @return {Object} A clone of the existing module + */ + clone() { + return new Module(JSON.parse(JSON.stringify(this))); + } + /** * Get a value for a given modification * @param {Number} name The name of the modification