mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 22:55:35 +00:00
Updates to internal representation of modification information. Temporary power usage slider with standard modules for testing
This commit is contained in:
@@ -5,6 +5,7 @@ import { jumpRange } from '../shipyard/Calculations';
|
||||
import { diffDetails } from '../utils/SlotFunctions';
|
||||
import AvailableModulesMenu from './AvailableModulesMenu';
|
||||
import { Modifications } from './SvgIcons';
|
||||
import Slider from './Slider';
|
||||
|
||||
/**
|
||||
* Standard Slot
|
||||
@@ -16,6 +17,7 @@ export default class StandardSlot extends TranslatedComponent {
|
||||
modules: React.PropTypes.array.isRequired,
|
||||
onSelect: React.PropTypes.func.isRequired,
|
||||
onOpen: React.PropTypes.func.isRequired,
|
||||
onChange: React.PropTypes.func.isRequired,
|
||||
ship: React.PropTypes.object.isRequired,
|
||||
selected: React.PropTypes.bool,
|
||||
warning: React.PropTypes.func,
|
||||
@@ -66,10 +68,38 @@ export default class StandardSlot extends TranslatedComponent {
|
||||
{ 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()} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{menu}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update power usage modification given a slider value.
|
||||
* Note that this is a temporary function until we have a slider section
|
||||
*/
|
||||
_updateSliderValue(value) {
|
||||
let m = this.props.slot.m;
|
||||
if (m) {
|
||||
m.setModValue(2, value * 2 - 1);
|
||||
}
|
||||
this.props.onChange();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain slider value from a power usage modification.
|
||||
* Note that this is a temporary function until we have a slider section
|
||||
*/
|
||||
_getSliderValue() {
|
||||
let m = this.props.slot.m;
|
||||
if (m && m.getModValue(2)) {
|
||||
return (m.getModValue(2) + 1) / 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ export default class StandardSlotSection extends SlotSection {
|
||||
onOpen={open.bind(this, bh)}
|
||||
onSelect={this._selectBulkhead}
|
||||
selected={currentMenu == bh}
|
||||
onChange={this.props.onChange}
|
||||
ship={ship}
|
||||
/>;
|
||||
|
||||
@@ -113,6 +114,7 @@ export default class StandardSlotSection extends SlotSection {
|
||||
onOpen={open.bind(this, st[0])}
|
||||
onSelect={select.bind(this, st[0])}
|
||||
selected={currentMenu == st[0]}
|
||||
onChange={this.props.onChange}
|
||||
ship={ship}
|
||||
warning={m => m.pGen < ship.powerRetracted}
|
||||
/>;
|
||||
@@ -124,6 +126,7 @@ export default class StandardSlotSection extends SlotSection {
|
||||
onOpen={open.bind(this, st[1])}
|
||||
onSelect={select.bind(this, st[1])}
|
||||
selected={currentMenu == st[1]}
|
||||
onChange={this.props.onChange}
|
||||
ship={ship}
|
||||
warning={m => m.maxmass < (ship.ladenMass - st[1].mass + m.mass)}
|
||||
/>;
|
||||
@@ -135,6 +138,7 @@ export default class StandardSlotSection extends SlotSection {
|
||||
modules={avail[2]}
|
||||
onOpen={open.bind(this, st[2])}
|
||||
onSelect={select.bind(this, st[2])}
|
||||
onChange={this.props.onChange}
|
||||
ship={ship}
|
||||
selected={currentMenu == st[2]}
|
||||
/>;
|
||||
@@ -145,6 +149,7 @@ export default class StandardSlotSection extends SlotSection {
|
||||
modules={avail[3]}
|
||||
onOpen={open.bind(this, st[3])}
|
||||
onSelect={select.bind(this, st[3])}
|
||||
onChange={this.props.onChange}
|
||||
ship={ship}
|
||||
selected={currentMenu == st[3]}
|
||||
/>;
|
||||
@@ -156,6 +161,7 @@ export default class StandardSlotSection extends SlotSection {
|
||||
onOpen={open.bind(this, st[4])}
|
||||
onSelect={select.bind(this, st[4])}
|
||||
selected={currentMenu == st[4]}
|
||||
onChange={this.props.onChange}
|
||||
ship={ship}
|
||||
warning= {m => m.enginecapacity < ship.boostEnergy}
|
||||
/>;
|
||||
@@ -167,6 +173,7 @@ export default class StandardSlotSection extends SlotSection {
|
||||
onOpen={open.bind(this, st[5])}
|
||||
onSelect={select.bind(this, st[5])}
|
||||
selected={currentMenu == st[5]}
|
||||
onChange={this.props.onChange}
|
||||
ship={ship}
|
||||
warning= {m => m.enginecapacity < ship.boostEnergy}
|
||||
/>;
|
||||
@@ -178,6 +185,7 @@ export default class StandardSlotSection extends SlotSection {
|
||||
onOpen={open.bind(this, st[6])}
|
||||
onSelect={select.bind(this, st[6])}
|
||||
selected={currentMenu == st[6]}
|
||||
onChange={this.props.onChange}
|
||||
ship={ship}
|
||||
warning= {m => m.fuel < st[2].m.maxfuel} // Show warning when fuel tank is smaller than FSD Max Fuel
|
||||
/>;
|
||||
|
||||
@@ -23,22 +23,30 @@ export default class Module {
|
||||
for (let p in template) { this[p] = template[p]; }
|
||||
}
|
||||
}
|
||||
this.mods = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value for a given modification ID
|
||||
* @param {Number} modId The ID of the modification
|
||||
* @return {Number} The value of the modification
|
||||
* @return {Number} The value of the modification, as a decimal value from -1 to 1
|
||||
*/
|
||||
_getModValue(modId) {
|
||||
let result = null;
|
||||
if (this.mods) {
|
||||
let mod = _.find(this.mods, function(o) { return o.id == modId; });
|
||||
if (mod) {
|
||||
result = mod.value;
|
||||
}
|
||||
getModValue(modId) {
|
||||
return this.mods ? this.mods[modId] / 100000 : 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
|
||||
*/
|
||||
setModValue(modId, value) {
|
||||
if (value == null || value == 0) {
|
||||
delete this.mods[modId];
|
||||
} else {
|
||||
// Store value with 3dp
|
||||
this.mods[modId] = Math.round(value * 100000);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,8 +58,8 @@ export default class Module {
|
||||
if (this.pGen) {
|
||||
result = this.pGen;
|
||||
if (result) {
|
||||
let mult = this._getModValue(1);
|
||||
if (mult) { result = result * (1 + (mult / 1000)); }
|
||||
let mult = this.getModValue(1);
|
||||
if (mult) { result = result * (1 + mult); }
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -66,8 +74,8 @@ export default class Module {
|
||||
if (this.power) {
|
||||
result = this.power;
|
||||
if (result) {
|
||||
let mult = this._getModValue(2);
|
||||
if (mult) { result = result * (1 + (mult / 1000)); }
|
||||
let mult = this.getModValue(2);
|
||||
if (mult) { result = result * (1 + mult); }
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -82,8 +90,8 @@ export default class Module {
|
||||
if (this.mass) {
|
||||
result = this.mass;
|
||||
if (result) {
|
||||
let mult = this._getModValue(3);
|
||||
if (mult) { result = result * (1 + (mult / 1000)); }
|
||||
let mult = this.getModValue(3);
|
||||
if (mult) { result = result * (1 + mult); }
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -98,8 +106,8 @@ export default class Module {
|
||||
if (this.health) {
|
||||
result = this.health;
|
||||
if (result) {
|
||||
let mult = this._getModValue(4);
|
||||
if (mult) { result = result * (1 + (mult / 1000)); }
|
||||
let mult = this.getModValue(4);
|
||||
if (mult) { result = result * (1 + mult); }
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -30,12 +30,12 @@ function powerUsageType(slot, modul) {
|
||||
function decodeModsToArray(code, arr) {
|
||||
let moduleMods = code.split(',');
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
arr[i] = new Array();
|
||||
arr[i] = {};
|
||||
if (moduleMods.length > i && moduleMods[i] != '') {
|
||||
let mods = moduleMods[i].split(';');
|
||||
for (let j = 0; j < mods.length; j++) {
|
||||
let modElements = mods[j].split(':');
|
||||
arr[i].push({ id: Number(modElements[0]), value: Number(modElements[1]) });
|
||||
arr[i][Number(modElements[0])] = Number(modElements[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -353,9 +353,9 @@ export default class Ship {
|
||||
* @return {String} Serialized modifications 'code'
|
||||
*/
|
||||
getModificationsString() {
|
||||
if(!this.serialized.modifications) {
|
||||
this.updateModificationsString();
|
||||
}
|
||||
// Modifications can be updated outside of the ship's direct knowledge, for example when sliders change the value,
|
||||
// so always recreate it from scratch
|
||||
this.updateModificationsString();
|
||||
return this.serialized.modifications;
|
||||
}
|
||||
|
||||
@@ -434,10 +434,10 @@ 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] : [];
|
||||
this.cargoHatch.mods = mods ? mods[0] : {};
|
||||
|
||||
for (i = 0, l = this.priorityBands.length; i < l; i++) {
|
||||
this.priorityBands[i].deployed = 0;
|
||||
@@ -458,7 +458,7 @@ export default class Ship {
|
||||
standard[i].discountedCost = 0;
|
||||
if (comps) {
|
||||
let module = ModuleUtils.standard(i, comps.standard[i]);
|
||||
if (module != null) { module.mods = mods && mods[i + 1] ? mods[i + 1] : []; }
|
||||
if (module != null) { module.mods = mods && mods[i + 1] ? mods[i + 1] : {}; }
|
||||
this.use(standard[i], module, true);
|
||||
}
|
||||
}
|
||||
@@ -477,7 +477,7 @@ export default class Ship {
|
||||
|
||||
if (comps && comps.hardpoints[i] !== 0) {
|
||||
let module = ModuleUtils.hardpoints(comps.hardpoints[i]);
|
||||
if (module != null) { module.mods = mods && mods[cl + i] ? mods[cl + i] : []; }
|
||||
if (module != null) { module.mods = mods && mods[cl + i] ? mods[cl + i] : {}; }
|
||||
this.use(hps[i], module, true);
|
||||
}
|
||||
}
|
||||
@@ -494,7 +494,7 @@ export default class Ship {
|
||||
|
||||
if (comps && comps.internal[i] !== 0) {
|
||||
let module = ModuleUtils.internal(comps.internal[i]);
|
||||
if (module != null) { module.mods = mods && mods[cl + i] ? mods[cl + i] : []; }
|
||||
if (module != null) { module.mods = mods && mods[cl + i] ? mods[cl + i] : {}; }
|
||||
this.use(internal[i], module, true);
|
||||
}
|
||||
}
|
||||
@@ -896,8 +896,8 @@ export default class Ship {
|
||||
|
||||
let bulkheadMods = new Array();
|
||||
if (this.bulkheads.m && this.bulkheads.m.mods) {
|
||||
for (let mod of this.bulkheads.m.mods) {
|
||||
bulkheadMods.push(mod.id + ':' + mod.value);
|
||||
for (var modKey in this.bulkheads.m.mods) {
|
||||
bulkheadMods.push(modKey + ':' + Math.round(this.bulkheads.m.getModValue(modKey) * 100000));
|
||||
}
|
||||
}
|
||||
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 (let mod of slot.m.mods) {
|
||||
slotMods.push(mod.id + ':' + mod.value);
|
||||
for (var modKey in slot.m.mods) {
|
||||
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 100000));
|
||||
}
|
||||
}
|
||||
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 (let mod of slot.m.mods) {
|
||||
slotMods.push(mod.id + ':' + mod.value);
|
||||
for (var modKey in slot.m.mods) {
|
||||
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 100000));
|
||||
}
|
||||
}
|
||||
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 (let mod of slot.m.mods) {
|
||||
slotMods.push(mod.id + ':' + mod.value);
|
||||
for (var modKey in slot.m.mods) {
|
||||
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 100000));
|
||||
}
|
||||
}
|
||||
allMods.push(slotMods.join(';'));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import cn from 'classnames';
|
||||
import { isShieldGenerator } from '../shipyard/ModuleUtils';
|
||||
import Module from '../shipyard/Module';
|
||||
import { Infinite } from '../components/SvgIcons';
|
||||
import Persist from '../stores/Persist';
|
||||
|
||||
@@ -206,7 +207,7 @@ function diff(format, mVal, mmVal) {
|
||||
* @return {React.Component} Component to be rendered
|
||||
*/
|
||||
export function diffDetails(language, m, mm) {
|
||||
mm = mm || {};
|
||||
mm = mm || new Module();
|
||||
let { formats, translate, units } = language;
|
||||
let propDiffs = [];
|
||||
let mMass = m.mass || 0;
|
||||
|
||||
Reference in New Issue
Block a user