mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 14:45:35 +00:00
Tidy-ups
This commit is contained in:
@@ -56,11 +56,11 @@ export default class HardpointSlot extends Slot {
|
||||
<div className={'r'}>{formats.round1(m.getMass())}{u.T}</div>
|
||||
</div>
|
||||
<div className={'cb'}>
|
||||
{ m.getDps() ? <div className={'l'}>{translate('DPS')}: {formats.round1(m.getDps())} { m.getClip() ? <span>({formats.round1((m.getClip() * m.getDps() / m.getRoF()) / ((m.getClip() / m.getRoF()) + m.getReload())) })</span> : null }</div> : null }
|
||||
{ m.getEps() ? <div className={'l'}>{translate('EPS')}: {formats.round1(m.getEps())}{u.MW} { m.getClip() ? <span>({formats.round1((m.getClip() * m.getEps() / m.getRoF()) / ((m.getClip() / m.getRoF()) + m.getReload())) }{u.MW})</span> : null }</div> : null }
|
||||
{ m.getHps() ? <div className={'l'}>{translate('HPS')}: {formats.round1(m.getHps())} { m.getClip() ? <span>({formats.round1((m.getClip() * m.getHps() / m.getRoF()) / ((m.getClip() / m.getRoF()) + m.getReload())) })</span> : null }</div> : null }
|
||||
{ m.getDps() && m.getEps() ? <div className={'l'}>{translate('DPE')}: {formats.f1(m.getDps() / m.getEps())}</div> : null }
|
||||
{ m.getRoF() ? <div className={'l'}>{translate('ROF')}: {formats.f1(m.getRoF())}{u.ps}</div> : null }
|
||||
{ m.getDps() ? <div className={'l'} onMouseOver={termtip.bind(null, m.getClip() ? 'dpssdps' : 'dps')} onMouseOut={tooltip.bind(null, null)}>{translate('DPS')}: {formats.round1(m.getDps())} { m.getClip() ? <span>({formats.round1((m.getClip() * m.getDps() / m.getRoF()) / ((m.getClip() / m.getRoF()) + m.getReload())) })</span> : null }</div> : null }
|
||||
{ m.getEps() ? <div className={'l'} onMouseOver={termtip.bind(null, m.getClip() ? 'epsseps' : 'eps')} onMouseOut={tooltip.bind(null, null)}>{translate('EPS')}: {formats.round1(m.getEps())}{u.MW} { m.getClip() ? <span>({formats.round1((m.getClip() * m.getEps() / m.getRoF()) / ((m.getClip() / m.getRoF()) + m.getReload())) }{u.MW})</span> : null }</div> : null }
|
||||
{ m.getHps() ? <div className={'l'} onMouseOver={termtip.bind(null, m.getClip() ? 'hpsshps' : 'hps')} onMouseOut={tooltip.bind(null, null)}>{translate('HPS')}: {formats.round1(m.getHps())} { m.getClip() ? <span>({formats.round1((m.getClip() * m.getHps() / m.getRoF()) / ((m.getClip() / m.getRoF()) + m.getReload())) })</span> : null }</div> : null }
|
||||
{ m.getDps() && m.getEps() ? <div className={'l'} onMouseOver={termtip.bind(null, 'dpe')} onMouseOut={tooltip.bind(null, null)}>{translate('DPE')}: {formats.f1(m.getDps() / m.getEps())}</div> : null }
|
||||
{ m.getRoF() ? <div className={'l'} onMouseOver={termtip.bind(null, 'rof')} onMouseOut={tooltip.bind(null, null)}>{translate('ROF')}: {formats.f1(m.getRoF())}{u.ps}</div> : null }
|
||||
{ m.getRange() && !m.getDps() ? <div className={'l'}>{translate('Range')} : {formats.round(m.getRange() / 1000)}{u.km}</div> : null }
|
||||
{ m.getShieldMul() ? <div className={'l'}>+{formats.rPct(m.getShieldMul())}</div> : null }
|
||||
{ m.getAmmo() ? <div className={'l'}>{translate('ammunition')}: {formats.int(m.getClip())}/{formats.int(m.getAmmo())}</div> : null }
|
||||
|
||||
@@ -89,7 +89,7 @@ export default class StandardSlot extends TranslatedComponent {
|
||||
{ m.getRange() ? <div className='l'>{translate('range')}: {formats.f2(m.getRange())}{units.km}</div> : null }
|
||||
{ m.time ? <div className='l'>{translate('time')}: {formats.time(m.time)}</div> : null }
|
||||
{ m.getThermalEfficiency() ? <div className='l'>{translate('efficiency')}: {formats.f2(m.getThermalEfficiency())}</div> : null }
|
||||
{ m.getPowerGeneration() > 0 ? <div className='l'>{translate('pGen')}: {formats.f1(m.getPowerGeneration())}{units.MW}</div> : null }
|
||||
{ m.getPowerGeneration() > 0 ? <div className='l'>{translate('pgen')}: {formats.f1(m.getPowerGeneration())}{units.MW}</div> : null }
|
||||
{ m.getMaxFuelPerJump() ? <div className='l'>{translate('max')} {translate('fuel')}: {formats.f1(m.getMaxFuelPerJump())}{units.T}</div> : null }
|
||||
{ m.getWeaponsCapacity() ? <div className='l'>{translate('WEP')}: {formats.f1(m.getWeaponsCapacity())}{units.MJ} / {formats.f1(m.getWeaponsRechargeRate())}{units.MW}</div> : null }
|
||||
{ m.getSystemsCapacity() ? <div className='l'>{translate('SYS')}: {formats.f1(m.getSystemsCapacity())}{units.MJ} / {formats.f1(m.getSystemsRechargeRate())}{units.MW}</div> : null }
|
||||
|
||||
@@ -114,7 +114,7 @@ export default class StandardSlotSection extends SlotSection {
|
||||
selected={currentMenu == st[0]}
|
||||
onChange={this.props.onChange}
|
||||
ship={ship}
|
||||
warning={m => m.pGen < ship.powerRetracted}
|
||||
warning={m => m.pgen < ship.powerRetracted}
|
||||
/>;
|
||||
|
||||
slots[2] = <StandardSlot
|
||||
|
||||
@@ -92,21 +92,27 @@ export const terms = {
|
||||
// Unit for seconds
|
||||
secs: 's',
|
||||
|
||||
// Hardpoint abbreviations
|
||||
dpe: 'Damage per MJ of energy',
|
||||
dps: 'Damage per second',
|
||||
dpssdps: 'Damage per second (sustained damage per second)',
|
||||
eps: 'Energy per second',
|
||||
epsseps: 'Energy per second (sustained energy per second)',
|
||||
hps: 'Heat per second',
|
||||
hpsshps: 'Heat per second (sustained heat per second)',
|
||||
|
||||
// Modifications
|
||||
ammo: 'Ammunition maximum',
|
||||
armourpen: 'Armour penetration',
|
||||
boot: 'Boot time',
|
||||
brokenregen: 'Broken regeneration rate',
|
||||
burst: 'Burst',
|
||||
clip: 'Ammunition clip',
|
||||
damage: 'Damage',
|
||||
dps: 'Damage per second',
|
||||
distdraw: 'Distributor draw',
|
||||
duration: 'Duration',
|
||||
eff: 'Efficiency',
|
||||
engcap: 'Engines capacity',
|
||||
engrate: 'Engines recharge rate',
|
||||
eps: 'Energy per second',
|
||||
explres: 'Explosive resistance',
|
||||
facinglimit: 'Facing limit',
|
||||
hullboost: 'Hull boost',
|
||||
@@ -118,7 +124,8 @@ export const terms = {
|
||||
mass: 'Mass',
|
||||
optmass: 'Optimal mass',
|
||||
optmul: 'Optimal multiplier',
|
||||
pGen: 'Power generation',
|
||||
pgen: 'Power generation',
|
||||
piercing: 'Piercing',
|
||||
power: 'Power draw',
|
||||
range: 'Range',
|
||||
ranget: 'Range', // Range in time (for FSD interdictor)
|
||||
|
||||
@@ -70,7 +70,7 @@ export default class Module {
|
||||
* @return {Number} the power generation of this module
|
||||
*/
|
||||
getPowerGeneration() {
|
||||
return this._getModifiedValue('pGen');
|
||||
return this._getModifiedValue('pgen');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,7 +413,7 @@ export default class Module {
|
||||
// DPS is a synthetic value
|
||||
let damage = this.getDamage();
|
||||
let rpshot = this.getRoundsPerShot() || 1;
|
||||
let rof = this.getRoF();
|
||||
let rof = this.getRoF() || 1;
|
||||
|
||||
return damage * rpshot * rof;
|
||||
}
|
||||
@@ -425,11 +425,8 @@ export default class Module {
|
||||
getEps() {
|
||||
// EPS is a synthetic value
|
||||
let distdraw = this.getDistDraw();
|
||||
console.log('distdraw is ' + distdraw);
|
||||
let rpshot = this.getRoundsPerShot() || 1;
|
||||
console.log('rpshot is ' + rpshot);
|
||||
let rof = this.getRoF();
|
||||
console.log('rof is ' + rof);
|
||||
let rof = this.getRoF() || 1;
|
||||
|
||||
return distdraw * rpshot * rof;
|
||||
}
|
||||
@@ -442,7 +439,7 @@ export default class Module {
|
||||
// HPS is a synthetic value
|
||||
let heat = this.getThermalLoad();
|
||||
let rpshot = this.getRoundsPerShot() || 1;
|
||||
let rof = this.getRoF();
|
||||
let rof = this.getRoF() || 1;
|
||||
|
||||
return heat * rpshot * rof;
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ export default class ModuleSet {
|
||||
|
||||
for (let p of this.standard[0]) {
|
||||
// Provides enough power, is lighter or the same mass as current power plant but better output/efficiency
|
||||
if (p.pGen >= powerNeeded && (p.mass < pp.mass || (p.mass == pp.mass && p.pGen > pp.pGen))) {
|
||||
if (p.pgen >= powerNeeded && (p.mass < pp.mass || (p.mass == pp.mass && p.pgen > pp.pgen))) {
|
||||
pp = p;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as ModuleUtils from './ModuleUtils';
|
||||
import Module from './Module';
|
||||
import LZString from 'lz-string';
|
||||
import isEqual from 'lodash/lang';
|
||||
import { Modifications } from 'coriolis-data/dist';
|
||||
|
||||
const UNIQUE_MODULES = ['psg', 'sg', 'bsg', 'rf', 'fs', 'fh'];
|
||||
|
||||
@@ -21,25 +22,6 @@ function powerUsageType(slot, modul) {
|
||||
return slot.cat != 1 ? 'retracted' : 'deployed';
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the modifications array with modification values from the code
|
||||
* @param {String} code Serialized modification code
|
||||
* @param {Array} arr Modification array
|
||||
*/
|
||||
function decodeModsToArray(code, arr) {
|
||||
let moduleMods = code.split(',');
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
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][modElements[0]] = Number(modElements[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the category array with module IDs from
|
||||
* the provided code
|
||||
@@ -418,7 +400,7 @@ export default class Ship {
|
||||
*/
|
||||
setModification(m, name, value) {
|
||||
// Handle special cases
|
||||
if (name == 'pGen') {
|
||||
if (name == 'pgen') {
|
||||
// Power generation
|
||||
m.setModValue(name, value);
|
||||
this.updatePower();
|
||||
@@ -598,8 +580,9 @@ export default class Ship {
|
||||
}
|
||||
|
||||
if (parts[3]) {
|
||||
// decodeModsToArray(LZString.decompressFromBase64(parts[3].replace(/-/g, '/')), mods);
|
||||
decodeModsToArray(parts[3], mods);
|
||||
const buf = Buffer.from(parts[3].replace(/-/g, '/'), 'base64');
|
||||
this.decodeModificationsString(Buffer.from(parts[3].replace(/-/g, '/'), 'base64'), mods);
|
||||
//decodeModificationsString(LZString.decompressFromBase64(parts[3].replace(/-/g, '/')), mods);
|
||||
}
|
||||
|
||||
decodeToArray(code, internal, decodeToArray(code, hardpoints, decodeToArray(code, standard, 1)));
|
||||
@@ -982,13 +965,13 @@ export default class Ship {
|
||||
* Update the modifications string
|
||||
* @return {this} The ship instance (for chaining operations)
|
||||
*/
|
||||
updateModificationsString() {
|
||||
oldupdateModificationsString() {
|
||||
let allMods = new Array();
|
||||
|
||||
let bulkheadMods = new Array();
|
||||
if (this.bulkheads.m && this.bulkheads.m.mods) {
|
||||
for (let modKey in this.bulkheads.m.mods) {
|
||||
bulkheadMods.push(modKey + ':' + Math.round(this.bulkheads.m.getModValue(modKey) * 10000));
|
||||
bulkheadMods.push(Modifications.modifiers.indexOf(modKey) + ':' + Math.round(this.bulkheads.m.getModValue(modKey) * 10000));
|
||||
}
|
||||
}
|
||||
allMods.push(bulkheadMods.join(';'));
|
||||
@@ -997,7 +980,7 @@ export default class Ship {
|
||||
let slotMods = new Array();
|
||||
if (slot.m && slot.m.mods) {
|
||||
for (let modKey in slot.m.mods) {
|
||||
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 10000));
|
||||
slotMods.push(Modifications.modifiers.indexOf(modKey) + ':' + Math.round(slot.m.getModValue(modKey) * 10000));
|
||||
}
|
||||
}
|
||||
allMods.push(slotMods.join(';'));
|
||||
@@ -1006,7 +989,7 @@ export default class Ship {
|
||||
let slotMods = new Array();
|
||||
if (slot.m && slot.m.mods) {
|
||||
for (let modKey in slot.m.mods) {
|
||||
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 10000));
|
||||
slotMods.push(Modifications.modifiers.indexOf(modKey) + ':' + Math.round(slot.m.getModValue(modKey) * 10000));
|
||||
}
|
||||
}
|
||||
allMods.push(slotMods.join(';'));
|
||||
@@ -1015,16 +998,145 @@ export default class Ship {
|
||||
let slotMods = new Array();
|
||||
if (slot.m && slot.m.mods) {
|
||||
for (let modKey in slot.m.mods) {
|
||||
slotMods.push(modKey + ':' + Math.round(slot.m.getModValue(modKey) * 10000));
|
||||
slotMods.push(Modifications.modifiers.indexOf(modKey) + ':' + Math.round(slot.m.getModValue(modKey) * 10000));
|
||||
}
|
||||
}
|
||||
allMods.push(slotMods.join(';'));
|
||||
}
|
||||
// this.serialized.modifications = LZString.compressToBase64(allMods.join(',').replace(/,+$/, '')).replace(/\//g, '-');
|
||||
this.serialized.modifications = allMods.join(',').replace(/,+$/, '');
|
||||
this.serialized.modifications = LZString.compressToBase64(allMods.join(',').replace(/,+$/, '')).replace(/\//g, '-');
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the modifications array with modification values from the code
|
||||
* @param {String} code Serialized modification code
|
||||
* @param {Array} arr Modification array
|
||||
*/
|
||||
olddecodeModificationsString(code, arr) {
|
||||
let moduleMods = code.split(',');
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
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(':');
|
||||
if (modElements[0].match('[0-9]+')) {
|
||||
arr[i][Modifications.modifiers[modElements[0]]] = Number(modElements[1]);
|
||||
} else {
|
||||
arr[i][modElements[0]] = Number(modElements[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the modifications string
|
||||
* @return {this} The ship instance (for chaining operations)
|
||||
*/
|
||||
updateModificationsString() {
|
||||
// Start off by gathering the information that we need
|
||||
let modules = new Array();
|
||||
|
||||
let bulkheadMods = new Array();
|
||||
if (this.bulkheads.m && this.bulkheads.m.mods) {
|
||||
for (let modKey in this.bulkheads.m.mods) {
|
||||
bulkheadMods.push({ id: Modifications.modifiers.indexOf(modKey), value: Math.round(this.bulkheads.m.getModValue(modKey) * 10000) });
|
||||
}
|
||||
}
|
||||
modules.push(bulkheadMods);
|
||||
|
||||
for (let slot of this.standard) {
|
||||
let slotMods = new Array();
|
||||
if (slot.m && slot.m.mods) {
|
||||
for (let modKey in slot.m.mods) {
|
||||
slotMods.push({ id: Modifications.modifiers.indexOf(modKey), value: Math.round(slot.m.getModValue(modKey) * 10000) });
|
||||
}
|
||||
}
|
||||
modules.push(slotMods);
|
||||
}
|
||||
|
||||
for (let slot of this.hardpoints) {
|
||||
let slotMods = new Array();
|
||||
if (slot.m && slot.m.mods) {
|
||||
for (let modKey in slot.m.mods) {
|
||||
slotMods.push({ id: Modifications.modifiers.indexOf(modKey), value: Math.round(slot.m.getModValue(modKey) * 10000) });
|
||||
}
|
||||
}
|
||||
modules.push(slotMods);
|
||||
}
|
||||
|
||||
for (let slot of this.internal) {
|
||||
let slotMods = new Array();
|
||||
if (slot.m && slot.m.mods) {
|
||||
for (let modKey in slot.m.mods) {
|
||||
slotMods.push({ id: Modifications.modifiers.indexOf(modKey), value: Math.round(slot.m.getModValue(modKey) * 10000) });
|
||||
}
|
||||
}
|
||||
modules.push(slotMods);
|
||||
}
|
||||
|
||||
// Now work out the size of the binary buffer from our modifications array
|
||||
let bufsize = 0;
|
||||
for (let module of modules) {
|
||||
if (module.length > 0) {
|
||||
bufsize = bufsize + 1 + (3 * module.length) + 1; //
|
||||
}
|
||||
}
|
||||
|
||||
if (bufsize > 0) {
|
||||
bufsize = bufsize + 1; // For end marker
|
||||
// Now create and populate the buffer
|
||||
let buffer = Buffer.alloc(bufsize);
|
||||
let curpos = 0;
|
||||
let i = 1;
|
||||
for (let module of modules) {
|
||||
if (module.length > 0) {
|
||||
buffer.writeInt8(i, curpos++);
|
||||
for (let modification of module) {
|
||||
buffer.writeInt8(modification.id, curpos++);
|
||||
console.log('modification value is ' + modification.value);
|
||||
buffer.writeInt16BE(modification.value, curpos);
|
||||
curpos += 2;
|
||||
}
|
||||
buffer.writeInt8(0, curpos++);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (curpos > 0) {
|
||||
buffer.writeInt8(0, curpos++);
|
||||
}
|
||||
|
||||
this.serialized.modifications = buffer.toString('base64').replace(/\//g, '-');
|
||||
} else {
|
||||
this.serialized.modifications = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the modifications array with modification values from the code
|
||||
* @param {String} buffer Buffer holding modification info
|
||||
* @param {Array} arr Modification array
|
||||
*/
|
||||
decodeModificationsString(buffer, arr) {
|
||||
let curpos = 0;
|
||||
let module = buffer.readInt8(curpos++);
|
||||
while (module != 0) {
|
||||
module = module - 1; // Fix offset to make the rest of the code easy
|
||||
let modifications = [];
|
||||
let modificationId = buffer.readInt8(curpos++);
|
||||
while (modificationId != 0) {
|
||||
let modificationValue = buffer.readInt16BE(curpos);
|
||||
curpos += 2;
|
||||
modifications[Modifications.modifiers[modificationId]] = modificationValue;
|
||||
modificationId = buffer.readInt8(curpos++);
|
||||
}
|
||||
arr[module] = modifications;
|
||||
module = buffer.readInt8(curpos++);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a slot with a the modul if the id is different from the current id for this slot.
|
||||
* Has logic handling ModuleUtils that you may only have 1 of (Shield Generator or Refinery).
|
||||
|
||||
@@ -136,7 +136,7 @@ const PROP_BLACKLIST = {
|
||||
};
|
||||
|
||||
const TERM_LOOKUP = {
|
||||
pGen: 'power',
|
||||
pgen: 'power',
|
||||
armouradd: 'armour',
|
||||
shieldmul: 'multiplier',
|
||||
rof: 'ROF',
|
||||
@@ -156,7 +156,7 @@ const UNIT_LOOKUP = {
|
||||
recharge: 'MJ',
|
||||
rangeLS: 'Ls',
|
||||
power: 'MJ',
|
||||
pGen: 'MJ',
|
||||
pgen: 'MJ',
|
||||
rof: 'ps'
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user