diff --git a/package.json b/package.json index 5ce7ae59..addce06a 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "fbemitter": "^2.0.0", "lodash": "^4.15.0", "lz-string": "^1.4.4", - "react-numeric-input": "^2.0.6", + "react-number-editor": "^4.0.2", "react": "^15.0.1", "react-dom": "^15.0.1", "superagent": "^1.4.0" diff --git a/src/app/components/ModSlider.jsx b/src/app/components/ModSlider.jsx deleted file mode 100644 index 386164f2..00000000 --- a/src/app/components/ModSlider.jsx +++ /dev/null @@ -1,56 +0,0 @@ -import React from 'react'; -import { findDOMNode } from 'react-dom'; -import Slider from './Slider'; - -const MARGIN_LR = 8; // Left/ Right margin - -/** - * Horizontal Slider for modifications - */ -export default class ModSlider extends Slider { - - /** - * Constructor - * @param {Object} props React Component properties - */ - constructor(props) { - super(props); - } - - /** - * Render the slider - * @return {React.Component} The slider - */ - render() { - let outerWidth = this.state.outerWidth; - let { axis, axisUnit, min, max, scale } = this.props; - - let style = { - width: '100%', - height: axis ? '2.5em' : '1.5em', - boxSizing: 'border-box' - }; - - if (!outerWidth) { - return ; - } - - let margin = MARGIN_LR * scale; - let width = outerWidth - (margin * 2); - let pctPos = width * this.props.percent + margin; - - // TODO add this back in from zero point to value - // - // TODO fix locations for labels (min, 0, max) - return - - - - {axis && - {min + axisUnit} - {(min + max / 2) + axisUnit} - {max + axisUnit} - } - ; - } -} diff --git a/src/app/components/ModificationsMenu.jsx b/src/app/components/ModificationsMenu.jsx index e93185f8..024cf290 100644 --- a/src/app/components/ModificationsMenu.jsx +++ b/src/app/components/ModificationsMenu.jsx @@ -1,12 +1,11 @@ import React from 'react'; import { findDOMNode } from 'react-dom'; -import NumericInput from 'react-numeric-input'; import TranslatedComponent from './TranslatedComponent'; import { stopCtxPropagation } from '../utils/UtilityFunctions'; import cn from 'classnames'; import { MountFixed, MountGimballed, MountTurret } from './SvgIcons'; import { Modifications } from 'coriolis-data/dist'; -import ModSlider from './ModSlider'; +import NumberEditor from 'react-number-editor'; const PRESS_THRESHOLD = 500; // mouse/touch down threshold @@ -46,12 +45,10 @@ export default class ModificationsMenu extends TranslatedComponent { for (let modId of Modifications.validity[m.grp]) { let modifiers = Modifications.modifiers[modId] list.push(
-
{translate(modifiers.name)}
- {formats.pct(m.getModValue(modId) || 0)} - +
{translate(modifiers.name)}{' (%)'}
+
); } - // return { list }; } @@ -71,34 +68,15 @@ export default class ModificationsMenu extends TranslatedComponent { * @param {Number} value The value to set, in the range [0,1] */ _updateValue(modId, value) { + let scaledValue = Math.floor(value * 100) / 10000; + let m = this.props.m; let ship = this.props.ship; - let modifiers = Modifications.modifiers[modId]; - let max = modifiers.max || 1; - let min = modifiers.min || -1; - let scaledValue = min + ((max - min) * value); - ship.setModification(m, modId, scaledValue); this.props.onChange(); } - /** - * Obtain slider value from a modification. - * @param {Number} modId The ID of the modification - * @return {Number} value The value of the slider, in the range [0,1] - */ - _getSliderPercent(modId) { - let modifiers = Modifications.modifiers[modId]; - let max = modifiers.max || 1; - let min = modifiers.min || -1; - let m = this.props.m; - if (m.getModValue(modId)) { - return (m.getModValue(modId) - min) / (max - min); - } - return -min / (max - min); - } - /** * Render the list * @return {React.Component} List @@ -114,5 +92,4 @@ export default class ModificationsMenu extends TranslatedComponent { ); } - } diff --git a/src/app/shipyard/Ship.js b/src/app/shipyard/Ship.js index 50d4018f..7c35e54e 100755 --- a/src/app/shipyard/Ship.js +++ b/src/app/shipyard/Ship.js @@ -566,6 +566,7 @@ export default class Ship { } if (parts[3]) { + //decodeModsToArray(LZString.decompressFromBase64(parts[3].replace(/-/g, '/')), mods); decodeModsToArray(parts[3], mods); } @@ -959,6 +960,7 @@ export default class Ship { } allMods.push(slotMods.join(';')); } + //this.serialized.modifications = LZString.compressToBase64(allMods.join(',').replace(/,+$/, '')).replace(/\//g, '-'); this.serialized.modifications = allMods.join(',').replace(/,+$/, ''); return this; }