Only show modifications icon if the module has valid modifications. Use no more than two decimal places for modification values.

This commit is contained in:
Cmdr McDonald
2016-10-24 18:40:12 +01:00
parent 183f22c223
commit adc5d1c039
6 changed files with 31 additions and 24 deletions

View File

@@ -1,6 +1,8 @@
import React from 'react';
import Slot from './Slot';
import { DamageKinetic, DamageThermal, DamageExplosive, MountFixed, MountGimballed, MountTurret, Modifications } from './SvgIcons';
import { DamageKinetic, DamageThermal, DamageExplosive, MountFixed, MountGimballed, MountTurret, ListModifications } from './SvgIcons';
import { Modifications } from 'coriolis-data/dist';
/**
* Hardpoint / Utility Slot
@@ -36,6 +38,7 @@ export default class HardpointSlot extends Slot {
if (m) {
let classRating = `${m.class}${m.rating}${m.missile ? '/' + m.missile : ''}`;
let { drag, drop } = this.props;
let validMods = Modifications.validity[m.grp] || [];
return <div className='details' draggable='true' onDragStart={drag} onDragEnd={drop}>
<div className={'cb'}>
@@ -59,7 +62,7 @@ export default class HardpointSlot extends Slot {
{ m.range && !m.dps ? <div className={'l'}>{translate('Range')} : {formats.round(m.range / 1000)}{u.km}</div> : null }
{ m.shieldmul ? <div className={'l'}>+{formats.rPct(m.shieldmul)}</div> : null }
{ m.ammo >= 0 ? <div className={'l'}>{translate('ammo')}: {formats.int(m.clip)}/{formats.int(m.ammo)}</div> : null }
<div className={'r'}><Modifications /></div>
{ validMods.length > 0 ? <div className='r' ><ListModifications /></div> : null }
</div>
</div>;
} else {

View File

@@ -1,6 +1,7 @@
import React from 'react';
import Slot from './Slot';
import { Modifications } from './SvgIcons';
import { ListModifications } from './SvgIcons';
import { Modifications } from 'coriolis-data/dist';
/**
* Internal Slot
@@ -19,6 +20,7 @@ export default class InternalSlot extends Slot {
if (m) {
let classRating = m.class + m.rating;
let { drag, drop } = this.props;
let validMods = Modifications.validity[m.grp] || [];
return <div className='details' draggable='true' onDragStart={drag} onDragEnd={drop}>
<div className={'cb'}>
@@ -42,7 +44,7 @@ export default class InternalSlot extends Slot {
{ m.rangeLS === null ? <div className={'l'}>{u.Ls}</div> : null }
{ m.rangeRating ? <div className={'l'}>{translate('range')}: {m.rangeRating}</div> : null }
{ m.armouradd ? <div className={'l'}>+{m.armouradd} <u className='cap'>{translate('armour')}</u></div> : null }
<div className={'r'}><Modifications /></div>
{ validMods.length > 0 ? <div className='r' ><ListModifications /></div> : null }
</div>
</div>;
} else {

View File

@@ -4,8 +4,9 @@ import TranslatedComponent from './TranslatedComponent';
import { jumpRange } from '../shipyard/Calculations';
import { diffDetails } from '../utils/SlotFunctions';
import AvailableModulesMenu from './AvailableModulesMenu';
import { Modifications } from './SvgIcons';
import { ListModifications } from './SvgIcons';
import Slider from './Slider';
import { Modifications } from 'coriolis-data/dist';
/**
* Standard Slot
@@ -33,6 +34,7 @@ export default class StandardSlot extends TranslatedComponent {
let m = slot.m;
let classRating = m.class + m.rating;
let menu;
let validMods = m == null ? [] : (Modifications.validity[m.grp] || []);
if (this.props.selected) {
menu = <AvailableModulesMenu
@@ -66,10 +68,7 @@ export default class StandardSlot extends TranslatedComponent {
{ m.weaponcapacity ? <div className='l'>{translate('WEP')}: {m.weaponcapacity}{units.MJ} / {m.weaponrecharge}{units.MW}</div> : null }
{ m.systemcapacity ? <div className='l'>{translate('SYS')}: {m.systemcapacity}{units.MJ} / {m.systemrecharge}{units.MW}</div> : null }
{ m.enginecapacity ? <div className='l'>{translate('ENG')}: {m.enginecapacity}{units.MJ} / {m.enginerecharge}{units.MW}</div> : null }
<div className={'r'}><Modifications /></div>
</div>
<div className={'cb'} >
<Slider onChange={this._updateSliderValue.bind(this)} min={-1} max={1} percent={this._getSliderValue()} />
{ validMods.length > 0 ? <div className='r' ><ListModifications /></div> : null }
</div>
</div>
</div>
@@ -77,10 +76,12 @@ export default class StandardSlot extends TranslatedComponent {
</div>
);
}
// {validMods.length > 0 ? <div className='cb' ><Slider onChange={this._updateSliderValue.bind(this)} min={-1} max={1} percent={this._getSliderValue()}/></div> : null }
/**
* Update power usage modification given a slider value.
* Note that this is a temporary function until we have a slider section
* @param {Number} value The value of the slider
*/
_updateSliderValue(value) {
let m = this.props.slot.m;
@@ -93,6 +94,7 @@ export default class StandardSlot extends TranslatedComponent {
/**
* Obtain slider value from a power usage modification.
* Note that this is a temporary function until we have a slider section
* @return {Number} value The value of the slider
*/
_getSliderValue() {
let m = this.props.slot.m;

View File

@@ -489,9 +489,9 @@ export class Rocket extends SvgIcon {
}
/**
* Modifications (engineers)
* ListModifications (engineers)
*/
export class Modifications extends SvgIcon {
export class ListModifications extends SvgIcon {
/**
* Overriden view box
* @return {String} view box

View File

@@ -32,20 +32,20 @@ export default class Module {
* @return {Number} The value of the modification, as a decimal value from -1 to 1
*/
getModValue(modId) {
return this.mods ? this.mods[modId] / 100000 : null;
return this.mods ? this.mods[modId] / 10000 : null;
}
/**
* Set a value for a given modification ID
* @param {Number} modId The ID of the modification
* @param {Number} val The value of the modification, as a decimal value from -1 to 1
* @param {Number} value The value of the modification, as a decimal value from -1 to 1
*/
setModValue(modId, value) {
if (value == null || value == 0) {
delete this.mods[modId];
} else {
// Store value with 3dp
this.mods[modId] = Math.round(value * 100000);
// Store value with 2dp
this.mods[modId] = Math.round(value * 10000);
}
}

View File

@@ -434,7 +434,7 @@ export default class Ship {
this.bulkheads.m = null;
this.useBulkhead(comps && comps.bulkheads ? comps.bulkheads : 0, true);
this.bulkheads.m.mods = mods && mods[0] ? mods[0] : {}
this.bulkheads.m.mods = mods && mods[0] ? mods[0] : {};
this.cargoHatch.priority = priorities ? priorities[0] * 1 : 0;
this.cargoHatch.enabled = enabled ? enabled[0] * 1 : true;
this.cargoHatch.mods = mods ? mods[0] : {};
@@ -896,8 +896,8 @@ export default class Ship {
let bulkheadMods = new Array();
if (this.bulkheads.m && this.bulkheads.m.mods) {
for (var modKey in this.bulkheads.m.mods) {
bulkheadMods.push(modKey + ':' + Math.round(this.bulkheads.m.getModValue(modKey) * 100000));
for (let modKey in this.bulkheads.m.mods) {
bulkheadMods.push(modKey + ':' + Math.round(this.bulkheads.m.getModValue(modKey) * 10000));
}
}
allMods.push(bulkheadMods.join(';'));
@@ -905,8 +905,8 @@ export default class Ship {
for (let slot of this.standard) {
let slotMods = new Array();
if (slot.m && slot.m.mods) {
for (var modKey in slot.m.mods) {
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 100000));
for (let modKey in slot.m.mods) {
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 10000));
}
}
allMods.push(slotMods.join(';'));
@@ -914,8 +914,8 @@ export default class Ship {
for (let slot of this.hardpoints) {
let slotMods = new Array();
if (slot.m && slot.m.mods) {
for (var modKey in slot.m.mods) {
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 100000));
for (let modKey in slot.m.mods) {
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 10000));
}
}
allMods.push(slotMods.join(';'));
@@ -923,8 +923,8 @@ export default class Ship {
for (let slot of this.internal) {
let slotMods = new Array();
if (slot.m && slot.m.mods) {
for (var modKey in slot.m.mods) {
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 100000));
for (let modKey in slot.m.mods) {
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 10000));
}
}
allMods.push(slotMods.join(';'));