diff --git a/src/app/pages/ShipyardPage.jsx b/src/app/pages/ShipyardPage.jsx index 3c8c53b8..f4893f30 100755 --- a/src/app/pages/ShipyardPage.jsx +++ b/src/app/pages/ShipyardPage.jsx @@ -27,6 +27,38 @@ function countInt(slot) { this.maxCargo += crEligible ? ModuleUtils.findInternal('cr', slot.maxClass, 'E').cargo : 0; } +/** + * Generate Ship summary and aggregated properties + * @param {String} shipId Ship Id + * @param {Object} shipData Ship Default Data + * @return {Object} Ship summary and aggregated properties + */ +function shipSummary(shipId, shipData) { + let summary = { + id: shipId, + hpCount: 0, + intCount: 0, + maxCargo: 0, + hp: [0, 0, 0, 0, 0], // Utility, Small, Medium, Large, Huge + int: [0, 0, 0, 0, 0, 0, 0, 0] // Sizes 1 - 8 + }; + Object.assign(summary, shipData.properties); + let ship = new Ship(shipId, shipData.properties, shipData.slots); + + // Build Ship + ship.buildWith(shipData.defaults); // Populate with stock/default components + ship.hardpoints.forEach(countHp.bind(summary)); // Count Hardpoints by class + ship.internal.forEach(countInt.bind(summary)); // Count Internal Compartments by class + summary.retailCost = ship.totalCost; // Record Stock/Default/retail cost + ship.optimizeMass({ pd: '1D' }); // Optimize Mass with 1D PD for maximum possible jump range + summary.maxJumpRange = ship.unladenRange; // Record Jump Range + ship.optimizeMass({ th: ship.standard[1].maxClass + 'A', fsd: '2D', ft: '1C' }); // Optmize mass with Max Thrusters + summary.topSpeed = ship.topSpeed; + summary.topBoost = ship.topBoost; + + return summary; +} + /** * The Shipyard summary page */ @@ -41,20 +73,20 @@ export default class ShipyardPage extends Page { */ constructor(props, context) { super(props, context); - this.state = { - title: 'Coriolis - Shipyard', - shipPredicate: 'name', - shipDesc: true - }; if (!ShipyardPage.cachedShipSummaries) { ShipyardPage.cachedShipSummaries = []; for (let s in Ships) { - ShipyardPage.cachedShipSummaries.push(this._shipSummary(s, Ships[s])); + ShipyardPage.cachedShipSummaries.push(shipSummary(s, Ships[s])); } } - this.shipSummaries = ShipyardPage.cachedShipSummaries; + this.state = { + title: 'Coriolis - Shipyard', + shipPredicate: 'name', + shipDesc: true, + shipSummaries: ShipyardPage.cachedShipSummaries + }; } /** @@ -76,38 +108,6 @@ export default class ShipyardPage extends Page { this.setState({ shipPredicate, shipDesc, shipPredicateIndex }); }; - /** - * Generate Ship summary and aggregated properties - * @param {String} shipId Ship Id - * @param {Object} shipData Ship Default Data - * @return {Object} Ship summary and aggregated properties - */ - _shipSummary(shipId, shipData) { - let summary = { - id: shipId, - hpCount: 0, - intCount: 0, - maxCargo: 0, - hp: [0, 0, 0, 0, 0], // Utility, Small, Medium, Large, Huge - int: [0, 0, 0, 0, 0, 0, 0, 0] // Sizes 1 - 8 - }; - Object.assign(summary, shipData.properties); - let ship = new Ship(shipId, shipData.properties, shipData.slots); - - // Build Ship - ship.buildWith(shipData.defaults); // Populate with stock/default components - ship.hardpoints.forEach(countHp.bind(summary)); // Count Hardpoints by class - ship.internal.forEach(countInt.bind(summary)); // Count Internal Compartments by class - summary.retailCost = ship.totalCost; // Record Stock/Default/retail cost - ship.optimizeMass({ pd: '1D' }); // Optimize Mass with 1D PD for maximum possible jump range - summary.maxJumpRange = ship.unladenRange; // Record Jump Range - ship.optimizeMass({ th: ship.standard[1].maxClass + 'A', fsd: '2D', ft: '1C' }); // Optmize mass with Max Thrusters - summary.topSpeed = ship.topSpeed; - summary.topBoost = ship.topBoost; - - return summary; - } - /** * Generate the table row summary for the ship * @param {Object} s Ship summary @@ -118,8 +118,7 @@ export default class ShipyardPage extends Page { * @return {React.Component} Table Row */ _shipRowElement(s, translate, u, fInt, fRound) { - return - {s.name} + return {s.manufacturer} {translate(SizeMap[s.class])} {s.agility} @@ -155,17 +154,27 @@ export default class ShipyardPage extends Page { * @return {React.Component} The page contents */ renderPage() { - let { translate, formats, units } = this.context.language; + let { sizeRatio, language, termtip } = this.context; + let { translate, formats, units } = language; + let hide = this.context.tooltip.bind(null, null); let fInt = formats.int; let fRound = formats.round; - let shipSummaries = this.shipSummaries; - let shipPredicate = this.state.shipPredicate; - let shipPredicateIndex = this.state.shipPredicateIndex; - let shipRows = []; - let hide = this.context.tooltip.bind(null, null); - let tip = this.context.termtip; + let { shipSummaries, shipPredicate, shipPredicateIndex } = this.state; let sortShips = (predicate, index) => this._sortShips.bind(this, predicate, index); + let filters = { + // 'class': { 1: 1, 2: 1} + }; + + shipSummaries = shipSummaries.filter(s => { + for (let prop in filters) { + if (!(s[prop] in filters[prop])) { + return false; + } + } + return true; + }); + // Sort shipsOverview shipSummaries.sort((a, b) => { let valA = a[shipPredicate], valB = b[shipPredicate]; @@ -194,26 +203,46 @@ export default class ShipyardPage extends Page { } }); + let i = 0; + let shipRows = new Array(shipSummaries.length); + let detailRows = new Array(shipSummaries.length); + for (let s of shipSummaries) { - shipRows.push(this._shipRowElement(s, translate, units, fInt, fRound)); + detailRows[i] = this._shipRowElement(s, translate, units, fInt, fRound); + shipRows[i] = {s.name}; + i++; } return ( -
-
- +
+
+ Show: manufacturer, size, maneuverability, base stats, max stats, hardpoints, internal slots, hull mass, mass lock factor, cost +
+ +
+
+ + + + + + + {shipRows} + +
{translate('ship')}
+
+ - - + - + @@ -244,9 +273,10 @@ export default class ShipyardPage extends Page { - {shipRows} + {detailRows}
{translate('ship')} {translate('manufacturer')} {translate('size')}{translate('mnv')}{translate('mnv')} {translate('base')} {translate('max')} {translate('hardpoints')} {translate('internal compartments')} {translate('hull')}{translate('MLF')}{translate('MLF')} {translate('cost')}
+
);