import { Component } from 'react'; import { Ships, Components } from 'coriolis-data'; import cn from 'classnames'; import Ship from 'Ship'; function countHp(slot) { this.hp[slot.maxClass]++; this.hpCount++; } function countInt(slot) { var crEligible = !slot.eligible || slot.eligible.cr; this.int[slot.maxClass - 1]++; // Subtract 1 since there is no Class 0 Internal compartment this.intCount++; this.maxCargo += crEligible ? Components.findInternal('cr', slot.maxClass, 'E').capacity : 0; } 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' }); // Optmize mass with Max Thrusters summary.topSpeed = ship.topSpeed; summary.topBoost = ship.topBoost; return summary; } let shipSummaries = []; for (var s in Ships) { shipSummaries.push(shipSummary(s, Ships[s])); } export default class ShipyardPage extends Component { constructor(props) { super(props); this.state = { title: 'Coriolis - Shipyard', shipPredicate: 'properties.name', shipDesc = false }; } shouldComponentUpdate(nextProps, nextState) { // Only on language change. Context? return false; } /** * Sort ships * @param {object} key Sort predicate */ _sortShips(shipPredicate, shipPredicateIndex) { let shipDesc = this.state.shipPredicate == shipPredicate ? !this.state.shipDesc : this.state.shipDesc; this.setState({ shipPredicate, shipDesc, shipPredicateIndex }); }; render() { let sortShips = this._sortShips.bind(this); let shipPredicate = this.state.shipPredicate; let shipPredicateIndex = this.state.shipPredicateIndex; let shipRows = []; // Sort shipsOverview shipSummaries.sort((a, b) => { let valA = a[shipPredicate], valB = b[shipPredicate]; if (shipPredicateIndex != undefined) { valA = valA[shipPredicateIndex]; valB = valB[shipPredicateIndex]; } return this.state.shipDesc ? (valA > valB) : (valB > valA); }); for (s of shipSummaries) { shipRows.push(
| {/* Max */} | {/* Hardpoints */} | {/* Internal */} | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|