Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/app/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ function isStandAlone() {
return standalone;
}

/**
* Creates a debounced version of the provided function that delays invocation
* until after a specified time has elapsed since the last call.
*
* @param {Function} fn Function to debounce
* @param {number} delay in ms, default 100
* @returns {Function} debounced function
*/
function debouncer(fn, delay = 100) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => fn.apply(this, args), delay);
};
}

/**
* Register path with callback fn(), or route path`, or Router.start().
*
Expand Down Expand Up @@ -50,13 +66,13 @@ Router.start = function() {
let state = Persist.getState();
// If a previous state has been stored, load that state
if (state && state.path) {
Router.replace(state.path, null, true);
Router._replace(state.path, null, true);
} else {
Router.replace('/', null, true);
Router._replace('/', null, true);
}
} else {
let url = location.pathname + location.search;
Router.replace(url, null, true);
Router._replace(url, null, true);
}
};

Expand Down Expand Up @@ -100,7 +116,7 @@ Router.go = function(path, state) {
* @return {Context} New Context
* @api public
*/
Router.replace = function(path, state, dispatch) {
Router._replace = function(path, state, dispatch) {
gaTrack(path);
let ctx = new Context(path, state);
if (dispatch) {
Expand All @@ -121,6 +137,7 @@ Router.replace = function(path, state, dispatch) {
}
return ctx;
};
Router.replace = debouncer(Router._replace); // debouncing to avoid issues with 'history'

/**
* Dispatch the given `ctx`.
Expand Down Expand Up @@ -306,7 +323,7 @@ function pathtoRegexp(path, keys, sensitive, strict) {
function onpopstate(e) {
if (e.state) {
let path = e.state.path;
Router.replace(path, e.state, true);
Router._replace(path, e.state, true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/components/EngineProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class EngineProfile extends TranslatedComponent {
const thrusters = ship.standard[1].m;
const minMass = ship.calcLowestPossibleMass({ th: thrusters });
const maxMass = thrusters.getMaxMass();
const mass = ship.unladenMass + fuel + cargo;
const mass = ship.outfittedMass + fuel + cargo;
const minSpeed = Calc.calcSpeed(maxMass, ship.speed, thrusters, ship.pipSpeed, 0, ship.boost / ship.speed, false);
const maxSpeed = Calc.calcSpeed(minMass, ship.speed, thrusters, ship.pipSpeed, 4, ship.boost / ship.speed, true);
// Add a mark at our current mass
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/FSDProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class FSDProfile extends TranslatedComponent {
const fsd = ship.standard[2].m;
const minMass = ship.calcLowestPossibleMass({ th: thrusters });
const maxMass = thrusters.getMaxMass();
const mass = ship.unladenMass + fuel + cargo;
const mass = ship.outfittedMass + fuel + cargo;
const minRange = 0;
const maxRange = Calc.jumpRange(minMass + fsd.getMaxFuelPerJump(), fsd, fsd.getMaxFuelPerJump(), ship);
// Add a mark at our current mass
Expand Down
14 changes: 7 additions & 7 deletions src/app/components/ShipSummaryTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ export default class ShipSummaryTable extends TranslatedComponent {
<td onMouseEnter={termtip.bind(null, boostTooltip, { cap: 0 })} onMouseLeave={hide}>{ canBoost ? <span>{int(ship.calcSpeed(4, ship.fuelCapacity, 0, true))}{u['m/s']}</span> : <span className='warning'>0 <Warning/></span> }</td>
<td>{distBoost !== 'No Boost' ? formats.time(distBoost) : 'No Boost'}</td>
<td>{ship.boostInt && ship.boostInt !== 'undefined' ? formats.time(ship.boostInt) : 0 }</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_MAX_SINGLE_JUMP', { cap: 0 })} onMouseLeave={hide}>{ canJump ? <span>{ f2(Calc.jumpRange(ship.unladenMass - ship.fuelCapacity + ship.standard[2].m.getMaxFuelPerJump(), ship.standard[2].m, ship.standard[2].m.getMaxFuelPerJump(), ship))}{u.LY}</span> : <span className='warning'>0 <Warning/></span> }</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_UNLADEN_SINGLE_JUMP', { cap: 0 })} onMouseLeave={hide}>{ canJump ? <span>{f2(Calc.jumpRange(ship.unladenMass, ship.standard[2].m, ship.fuelCapacity, ship))}{u.LY}</span> : <span className='warning'>0 <Warning/></span> }</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_LADEN_SINGLE_JUMP', { cap: 0 })} onMouseLeave={hide}>{ canJump ? <span>{f2(Calc.jumpRange(ship.unladenMass + ship.cargoCapacity, ship.standard[2].m, ship.fuelCapacity, ship))}{u.LY}</span> : <span className='warning'>0 <Warning/></span> }</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_MAX_SINGLE_JUMP', { cap: 0 })} onMouseLeave={hide}>{ canJump ? <span>{ f2(Calc.jumpRange(ship.outfittedMass + ship.standard[2].m.getMaxFuelPerJump(), ship.standard[2].m, ship.standard[2].m.getMaxFuelPerJump(), ship))}{u.LY}</span> : <span className='warning'>0 <Warning/></span> }</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_UNLADEN_SINGLE_JUMP', { cap: 0 })} onMouseLeave={hide}>{ canJump ? <span>{f2(Calc.jumpRange(ship.unladenMass + ship.reserveFuelCapacity, ship.standard[2].m, ship.fuelCapacity, ship))}{u.LY}</span> : <span className='warning'>0 <Warning/></span> }</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_LADEN_SINGLE_JUMP', { cap: 0 })} onMouseLeave={hide}>{ canJump ? <span>{f2(Calc.jumpRange(ship.ladenMass, ship.standard[2].m, ship.fuelCapacity, ship))}{u.LY}</span> : <span className='warning'>0 <Warning/></span> }</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_UNLADEN_TOTAL_JUMP', { cap: 0 })} onMouseLeave={hide}>{ canJump ? <span>{f2(Calc.totalJumpRange(ship.unladenMass, ship.standard[2].m, ship.fuelCapacity, ship))}{u.LY}</span> : <span className='warning'>0 <Warning/></span> }</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_LADEN_TOTAL_JUMP', { cap: 0 })} onMouseLeave={hide}>{ canJump ? <span>{f2(Calc.totalJumpRange(ship.unladenMass + ship.cargoCapacity, ship.standard[2].m, ship.fuelCapacity, ship))}{u.LY}</span> : <span className='warning'>0 <Warning/></span> }</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_LADEN_TOTAL_JUMP', { cap: 0 })} onMouseLeave={hide}>{ canJump ? <span>{f2(Calc.totalJumpRange(ship.ladenMass, ship.standard[2].m, ship.fuelCapacity, ship))}{u.LY}</span> : <span className='warning'>0 <Warning/></span> }</td>
<td className={sgClassNames} onMouseEnter={termtip.bind(null, sgTooltip, { cap: 0 })} onMouseLeave={hide}>{int(ship.shield)}{u.MJ}</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_INTEGRITY', { cap: 0 })} onMouseLeave={hide}>{int(ship.armour)}</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_DPS', { cap: 0 })} onMouseLeave={hide}>{f1(ship.totalDps)}</td>
Expand All @@ -123,9 +123,9 @@ export default class ShipSummaryTable extends TranslatedComponent {
<td>{round(ship.cargoCapacity)}{u.T}</td>
<td>{ship.passengerCapacity}</td>
<td>{round(ship.fuelCapacity)}{u.T}</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_HULL_MASS', { cap: 0 })} onMouseLeave={hide}>{ship.hullMass}{u.T}</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_UNLADEN_MASS', { cap: 0 })} onMouseLeave={hide}>{int(ship.unladenMass)}{u.T}</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_LADEN_MASS', { cap: 0 })} onMouseLeave={hide}>{int(ship.ladenMass)}{u.T}</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_HULL_MASS', { cap: 0 })} onMouseLeave={hide}>{int(ship.hullMass)}{u.T}</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_UNLADEN_MASS', { cap: 0 })} onMouseLeave={hide}>{(ship.unladenMass + ship.reserveFuelCapacity).toFixed(1)}{u.T}</td>
<td onMouseEnter={termtip.bind(null, 'TT_SUMMARY_LADEN_MASS', { cap: 0 })} onMouseLeave={hide}>{(ship.ladenMass + ship.reserveFuelCapacity).toFixed(1)}{u.T}</td>
<td>{int(ship.hardness)}</td>
<td>{ship.crew}</td>
<td>{ship.masslock}</td>
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/StandardSlotSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default class StandardSlotSection extends SlotSection {
selected={currentMenu == st[1]}
onChange={this.props.onChange}
ship={ship}
warning={m => m instanceof Module ? m.getMaxMass() < (ship.unladenMass + cargo + fuel - st[1].m.mass + m.mass) : m.maxmass < (ship.unladenMass + cargo + fuel - st[1].m.mass + m.mass)}
warning={m => m instanceof Module ? m.getMaxMass() < (ship.outfittedMass + cargo + fuel - st[1].m.mass + m.mass) : m.maxmass < (ship.outfittedMass + cargo + fuel - st[1].m.mass + m.mass)}
/>;


Expand Down
2 changes: 1 addition & 1 deletion src/app/shipyard/Calculations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function jumpRange(mass, fsd, fuel, ship) {
const fsdOptimalMass = fsd instanceof Module ? fsd.getOptMass() : fsd.optmass;
let jumpAddition = 0;
if (ship) {
mass += ship.reserveFuelCapacity || 0;
// mass += ship.reserveFuelCapacity || 0; // matching in-game values, adding this only to unladen calculation at '..\components\ShipSummaryTable.jsx:113'
for (const module of ship.internal) {
if (module && module.m && module.m.grp === 'gfsb' && ship.getSlotStatus(module) == 3) {
jumpAddition += module.m.getJumpBoost();
Expand Down
50 changes: 26 additions & 24 deletions src/app/shipyard/Ship.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default class Ship {
*/
canThrust(cargo, fuel) {
return this.getSlotStatus(this.standard[1]) == 3 && // Thrusters are powered
this.unladenMass + cargo + fuel < this.standard[1].m.getMaxMass(); // Max mass not exceeded
this.outfittedMass + cargo + fuel < this.standard[1].m.getMaxMass(); // Max mass not exceeded
}

/**
Expand Down Expand Up @@ -164,7 +164,7 @@ export default class Ship {
calcUnladenRange(massDelta, fuel, fsd) {
fsd = fsd || this.standard[2].m;
let fsdMaxFuelPerJump = fsd instanceof Module ? fsd.getMaxFuelPerJump() : fsd.maxfuel;
return Calc.jumpRange(this.unladenMass + (massDelta || 0) + Math.min(fsdMaxFuelPerJump, fuel || this.fuelCapacity), fsd || this.standard[2].m, fuel, this);
return Calc.jumpRange(this.outfittedMass + (massDelta || 0) + Math.min(fsdMaxFuelPerJump, fuel || this.fuelCapacity), fsd || this.standard[2].m, fuel, this);
}

/**
Expand All @@ -174,7 +174,7 @@ export default class Ship {
* @return {array} Speed at pip settings
*/
calcSpeedsWith(fuel, cargo) {
return Calc.speed(this.unladenMass + fuel + cargo, this.speed, this.standard[1].m, this.pipSpeed);
return Calc.speed(this.outfittedMass + fuel + cargo, this.speed, this.standard[1].m, this.pipSpeed);
}

/**
Expand All @@ -186,7 +186,7 @@ export default class Ship {
* @return {Number} Speed
*/
calcSpeed(eng, fuel, cargo, boost) {
return Calc.calcSpeed(this.unladenMass + fuel + cargo, this.speed, this.standard[1].m, this.pipSpeed, eng, this.boost / this.speed, boost);
return Calc.calcSpeed(this.outfittedMass + fuel + cargo, this.speed, this.standard[1].m, this.pipSpeed, eng, this.boost / this.speed, boost);
}

/**
Expand All @@ -198,7 +198,7 @@ export default class Ship {
* @return {Number} Pitch
*/
calcPitch(eng, fuel, cargo, boost) {
return Calc.calcPitch(this.unladenMass + fuel + cargo, this.pitch, this.standard[1].m, this.pipSpeed, eng, this.boost / this.speed, boost);
return Calc.calcPitch(this.outfittedMass + fuel + cargo, this.pitch, this.standard[1].m, this.pipSpeed, eng, this.boost / this.speed, boost);
}

/**
Expand All @@ -210,7 +210,7 @@ export default class Ship {
* @return {Number} Roll
*/
calcRoll(eng, fuel, cargo, boost) {
return Calc.calcRoll(this.unladenMass + fuel + cargo, this.roll, this.standard[1].m, this.pipSpeed, eng, this.boost / this.speed, boost);
return Calc.calcRoll(this.outfittedMass + fuel + cargo, this.roll, this.standard[1].m, this.pipSpeed, eng, this.boost / this.speed, boost);
}

/**
Expand All @@ -222,7 +222,7 @@ export default class Ship {
* @return {Number} Yaw
*/
calcYaw(eng, fuel, cargo, boost) {
return Calc.calcYaw(this.unladenMass + fuel + cargo, this.yaw, this.standard[1].m, this.pipSpeed, eng, this.boost / this.speed, boost);
return Calc.calcYaw(this.outfittedMass + fuel + cargo, this.yaw, this.standard[1].m, this.pipSpeed, eng, this.boost / this.speed, boost);
}

/**
Expand Down Expand Up @@ -570,12 +570,13 @@ export default class Ship {
this.fuelCapacity = 0;
this.cargoCapacity = 0;
this.passengerCapacity = 0;
this.outfittedMass = this.hullMass;
this.unladenMass = this.hullMass;
this.ladenMass = 0;
this.armour = this.baseArmour;
this.shield = this.baseShieldStrength;
this.shieldCells = 0;
this.totalCost = this.m.incCost ? this.m.discountedCost : 0;
this.unladenMass = this.hullMass;
this.totalDpe = 0;
this.totalAbsDpe = 0;
this.totalExplDpe = 0;
Expand Down Expand Up @@ -1172,17 +1173,17 @@ export default class Ship {
* @return {this} The ship instance (for chaining operations)
*/
recalculateMass() {
let unladenMass = this.hullMass;
let outfittedMass = this.hullMass; // used only for hull and module mass
let cargoCapacity = 0;
let fuelCapacity = 0;
let passengerCapacity = 0;

unladenMass += this.bulkheads.m.getMass();
outfittedMass += this.bulkheads.m.getMass();

let slots = this.standard.concat(this.internal, this.hardpoints);
// TODO: create class for slot and also add slot.get
// handle unladen mass
unladenMass += chain(slots)
outfittedMass += chain(slots)
.map(slot => slot.m ? slot.m.get('mass') : null)
.map(mass => mass || 0)
.reduce((sum, mass) => sum + mass)
Expand Down Expand Up @@ -1210,11 +1211,12 @@ export default class Ship {
.value();

// Update global stats
this.unladenMass = unladenMass + fuelCapacity;
this.cargoCapacity = cargoCapacity;
this.fuelCapacity = fuelCapacity;
this.cargoCapacity = cargoCapacity;
this.passengerCapacity = passengerCapacity;
this.ladenMass = unladenMass + fuelCapacity + cargoCapacity;
this.outfittedMass = outfittedMass; // separated from 'unladenMass' and used in place of it to fix a few issues that included fuel twice in calculations
this.unladenMass = outfittedMass + fuelCapacity;
this.ladenMass = outfittedMass + fuelCapacity + cargoCapacity;
return this;
}

Expand All @@ -1223,17 +1225,17 @@ export default class Ship {
* @return {this} The ship instance (for chaining operations)
*/
updateMovement() {
this.speeds = Calc.speed(this.unladenMass + this.fuelCapacity, this.speed, this.standard[1].m, this.pipSpeed);
this.speeds = Calc.speed(this.unladenMass, this.speed, this.standard[1].m, this.pipSpeed);
this.topSpeed = this.speeds[4];
this.topBoost = this.canBoost(0, 0) ? this.speeds[4] * this.boost / this.speed : 0;

this.pitches = Calc.pitch(this.unladenMass + this.fuelCapacity, this.pitch, this.standard[1].m, this.pipSpeed);
this.pitches = Calc.pitch(this.unladenMass, this.pitch, this.standard[1].m, this.pipSpeed);
this.topPitch = this.pitches[4];

this.rolls = Calc.roll(this.unladenMass + this.fuelCapacity, this.roll, this.standard[1].m, this.pipSpeed);
this.rolls = Calc.roll(this.unladenMass, this.roll, this.standard[1].m, this.pipSpeed);
this.topRoll = this.rolls[4];

this.yaws = Calc.yaw(this.unladenMass + this.fuelCapacity, this.yaw, this.standard[1].m, this.pipSpeed);
this.yaws = Calc.yaw(this.unladenMass, this.yaw, this.standard[1].m, this.pipSpeed);
this.topYaw = this.yaws[4];

return this;
Expand Down Expand Up @@ -1298,13 +1300,13 @@ export default class Ship {
*/
updateJumpStats() {
let fsd = this.standard[2].m; // Frame Shift Drive;
let { unladenMass, fuelCapacity } = this;

this.unladenRange = this.calcUnladenRange(); // Includes fuel weight for jump
this.fullTankRange = Calc.jumpRange(unladenMass + fuelCapacity, fsd, fuelCapacity, this); // Full Tank
this.ladenRange = this.calcLadenRange(); // Includes full tank and caro
this.unladenFastestRange = Calc.totalJumpRange(unladenMass + this.fuelCapacity, fsd, fuelCapacity, this);
this.ladenFastestRange = Calc.totalJumpRange(unladenMass + this.fuelCapacity + this.cargoCapacity, fsd, fuelCapacity, this);
this.maxJumpCount = Math.ceil(fuelCapacity / fsd.getMaxFuelPerJump());
this.ladenRange = this.calcLadenRange(); // Includes full tank and cargo
this.fullTankRange = Calc.jumpRange(this.unladenMass, fsd, this.fuelCapacity, this); // Full Tank
this.unladenFastestRange = Calc.totalJumpRange(this.unladenMass, fsd, this.fuelCapacity, this);
this.ladenFastestRange = Calc.totalJumpRange(this.ladenMass, fsd, this.fuelCapacity, this);
this.maxJumpCount = Math.ceil(this.fuelCapacity / fsd.getMaxFuelPerJump());
return this;
}

Expand Down