mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-10 15:15:34 +00:00
Bulkhead refactoring
This commit is contained in:
@@ -400,7 +400,7 @@ export default class CostSection extends TranslatedComponent {
|
|||||||
let retrofitCosts = [];
|
let retrofitCosts = [];
|
||||||
let retrofitTotal = 0, i, l, item;
|
let retrofitTotal = 0, i, l, item;
|
||||||
|
|
||||||
if (ship.bulkheads.index != retrofitShip.bulkheads.index) {
|
if (ship.bulkheads.m.index != retrofitShip.bulkheads.m.index) {
|
||||||
item = {
|
item = {
|
||||||
buyClassRating: ship.bulkheads.m.class + ship.bulkheads.m.rating,
|
buyClassRating: ship.bulkheads.m.class + ship.bulkheads.m.rating,
|
||||||
buyName: ship.bulkheads.m.name,
|
buyName: ship.bulkheads.m.name,
|
||||||
|
|||||||
@@ -48,8 +48,9 @@ export default class StandardSlot extends TranslatedComponent {
|
|||||||
<div className={'sz'}>{slot.maxClass}</div>
|
<div className={'sz'}>{slot.maxClass}</div>
|
||||||
<div>
|
<div>
|
||||||
<div className='l'>{classRating + ' ' + translate(m.grp)}</div>
|
<div className='l'>{classRating + ' ' + translate(m.grp)}</div>
|
||||||
<div className={'r'}>{m.mass || m.fuel}{units.T}</div>
|
<div className={'r'}>{m.mass || m.fuel || 0}{units.T}</div>
|
||||||
<div className={'cb'}>
|
<div className={'cb'}>
|
||||||
|
{ m.name ? <div className='l'>{translate(m.name)}</div> : null }
|
||||||
{ m.optmass ? <div className='l'>{translate('optimal mass') + ': '}{m.optmass}{units.T}</div> : null }
|
{ m.optmass ? <div className='l'>{translate('optimal mass') + ': '}{m.optmass}{units.T}</div> : null }
|
||||||
{ m.maxmass ? <div className='l'>{translate('max mass') + ': '}{m.maxmass}{units.T}</div> : null }
|
{ m.maxmass ? <div className='l'>{translate('max mass') + ': '}{m.maxmass}{units.T}</div> : null }
|
||||||
{ m.range ? <div className='l'>{translate('range')}: {m.range}{units.km}</div> : null }
|
{ m.range ? <div className='l'>{translate('range')}: {m.range}{units.km}</div> : null }
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export default class StandardSlotSection extends SlotSection {
|
|||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props, context, 'standard', 'standard');
|
super(props, context, 'standard', 'standard');
|
||||||
this._optimizeStandard = this._optimizeStandard.bind(this);
|
this._optimizeStandard = this._optimizeStandard.bind(this);
|
||||||
this._hideDiff = this._hideDiff.bind(this);
|
this._selectBulkhead = this._selectBulkhead.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,10 +65,10 @@ export default class StandardSlotSection extends SlotSection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Use the specified bulkhead
|
* Use the specified bulkhead
|
||||||
* @param {number} bulkheadIndex 0 - 4
|
* @param {Object} bulkhead Bulkhead module details
|
||||||
*/
|
*/
|
||||||
_selectBulkhead(bulkheadIndex) {
|
_selectBulkhead(bulkhead) {
|
||||||
this.props.ship.useBulkhead(bulkheadIndex);
|
this.props.ship.useBulkhead(bulkhead.index);
|
||||||
this.context.tooltip();
|
this.context.tooltip();
|
||||||
this.props.onChange();
|
this.props.onChange();
|
||||||
this._close();
|
this._close();
|
||||||
@@ -81,26 +81,6 @@ export default class StandardSlotSection extends SlotSection {
|
|||||||
this._optimizeStandard();
|
this._optimizeStandard();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the bulkhead diff tooltip
|
|
||||||
* @param {number} bhIndex Potential Bulkhead alternative
|
|
||||||
* @param {SyntheticEvent} event Event
|
|
||||||
*/
|
|
||||||
_bhDiff(bhIndex, event) {
|
|
||||||
let ship = this.props.ship;
|
|
||||||
this.context.tooltip(
|
|
||||||
diffDetails.call(ship, this.context.language, ModuleUtils.bulkheads(ship.id, bhIndex), ship.bulkheads.m),
|
|
||||||
event.currentTarget.getBoundingClientRect()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hide the diff tooltip
|
|
||||||
*/
|
|
||||||
_hideDiff() {
|
|
||||||
this.context.tooltip();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the slot React Components
|
* Generate the slot React Components
|
||||||
* @return {Array} Array of Slots
|
* @return {Array} Array of Slots
|
||||||
@@ -116,41 +96,15 @@ export default class StandardSlotSection extends SlotSection {
|
|||||||
let avail = ship.getAvailableModules().standard;
|
let avail = ship.getAvailableModules().standard;
|
||||||
let bh = ship.bulkheads;
|
let bh = ship.bulkheads;
|
||||||
|
|
||||||
slots[0] = (
|
slots[0] = <StandardSlot
|
||||||
<div key='bh' className={cn('slot', { selected: currentMenu === bh })} onClick={open.bind(this, bh)}>
|
key='bh'
|
||||||
<div className={'details-container'}>
|
slot={bh}
|
||||||
<div className={'details'}>
|
modules={ship.getAvailableModules().bulkheads}
|
||||||
<div className={'sz'}>8</div>
|
onOpen={open.bind(this, bh)}
|
||||||
<div>
|
onSelect={this._selectBulkhead}
|
||||||
<div className={'l'}>{translate('bh')}</div>
|
selected={currentMenu == bh}
|
||||||
<div className={'r'}>{bh.m.mass}{units.T}</div>
|
ship={ship}
|
||||||
<div className={'cl l'}>{translate(bh.m.name)}</div>
|
/>;
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{currentMenu === bh &&
|
|
||||||
<div className='select' onClick={ e => e.stopPropagation() }>
|
|
||||||
<ul>
|
|
||||||
<li onClick={selBulkhead.bind(this, 0)} onMouseOver={this._bhDiff.bind(this, 0)} onMouseLeave={this._hideDiff} className={cn('lc', { active: bh.index == 0 })}>
|
|
||||||
{translate('Lightweight Alloy')}
|
|
||||||
</li>
|
|
||||||
<li onClick={selBulkhead.bind(this, 1)} onMouseOver={this._bhDiff.bind(this, 1)} onMouseLeave={this._hideDiff} className={cn('lc', { active: bh.index == 1 })}>
|
|
||||||
{translate('Reinforced Alloy')}
|
|
||||||
</li>
|
|
||||||
<li onClick={selBulkhead.bind(this, 2)} onMouseOver={this._bhDiff.bind(this, 2)} onMouseLeave={this._hideDiff} className={cn('lc', { active: bh.index == 2 })}>
|
|
||||||
{translate('Military Grade Composite')}
|
|
||||||
</li>
|
|
||||||
<li onClick={selBulkhead.bind(this, 3)} onMouseOver={this._bhDiff.bind(this, 3)} onMouseLeave={this._hideDiff} className={cn('lc', { active: bh.index == 3 })}>
|
|
||||||
{translate('Mirrored Surface Composite')}
|
|
||||||
</li>
|
|
||||||
<li onClick={selBulkhead.bind(this, 4)} onMouseOver={this._bhDiff.bind(this, 4)} onMouseLeave={this._hideDiff} className={cn('lc', { active: bh.index == 4 })}>
|
|
||||||
{translate('Reactive Surface Composite')}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
slots[1] = <StandardSlot
|
slots[1] = <StandardSlot
|
||||||
key='pp'
|
key='pp'
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
import { BulkheadNames } from './Constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter eligble modules based on parameters
|
* Filter eligble modules based on parameters
|
||||||
* @param {Array} arr Available modules array
|
* @param {Array} arr Available modules array
|
||||||
@@ -19,12 +21,13 @@ export default class ModuleSet {
|
|||||||
/**
|
/**
|
||||||
* Instantiate the module set
|
* Instantiate the module set
|
||||||
* @param {Object} modules All Modules
|
* @param {Object} modules All Modules
|
||||||
* @param {number} mass Ship mass
|
* @param {Object} shipData Ship Specifications Data (see coriolis-data/Ships)
|
||||||
* @param {Array} maxStandardArr Array of standard slots classes/sizes
|
|
||||||
* @param {Array} maxInternal Array of internal slots classes/sizes
|
|
||||||
* @param {Array} maxHardPoint Array of hardpoint slots classes/sizes
|
|
||||||
*/
|
*/
|
||||||
constructor(modules, mass, maxStandardArr, maxInternal, maxHardPoint) {
|
constructor(modules, shipData) {
|
||||||
|
let maxInternal = isNaN(shipData.slots.internal[0]) ? shipData.slots.internal[0].class : shipData.slots.internal[0];
|
||||||
|
let mass = shipData.properties.hullMass + 6.5;
|
||||||
|
let maxStandardArr = shipData.slots.standard;
|
||||||
|
let maxHardPoint = shipData.slots.hardpoints[0];
|
||||||
let stnd = modules.standard;
|
let stnd = modules.standard;
|
||||||
this.mass = mass;
|
this.mass = mass;
|
||||||
this.standard = {};
|
this.standard = {};
|
||||||
@@ -33,6 +36,10 @@ export default class ModuleSet {
|
|||||||
this.hpClass = {};
|
this.hpClass = {};
|
||||||
this.intClass = {};
|
this.intClass = {};
|
||||||
|
|
||||||
|
this.bulkheads = shipData.bulkheads.map((b, i) => {
|
||||||
|
return Object.assign({ grp: 'bh', name: BulkheadNames[i], index: i, class: '', rating: '' }, b);
|
||||||
|
});
|
||||||
|
|
||||||
this.standard[0] = filter(stnd.pp, maxStandardArr[0], 0, mass); // Power Plant
|
this.standard[0] = filter(stnd.pp, maxStandardArr[0], 0, mass); // Power Plant
|
||||||
this.standard[2] = filter(stnd.fsd, maxStandardArr[2], 0, mass); // FSD
|
this.standard[2] = filter(stnd.fsd, maxStandardArr[2], 0, mass); // FSD
|
||||||
this.standard[4] = filter(stnd.pd, maxStandardArr[4], 0, mass); // Power Distributor
|
this.standard[4] = filter(stnd.pd, maxStandardArr[4], 0, mass); // Power Distributor
|
||||||
@@ -53,6 +60,15 @@ export default class ModuleSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the specified bulkhead
|
||||||
|
* @param {integer} index Bulkhead index
|
||||||
|
* @return {Object} Bulkhead module details
|
||||||
|
*/
|
||||||
|
getBulkhead(index) {
|
||||||
|
return this.bulkheads[index] || null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the modules that areeligible for an internal slot
|
* Determine the modules that areeligible for an internal slot
|
||||||
* @param {integer} c The max class module that can be mounted in the slot
|
* @param {integer} c The max class module that can be mounted in the slot
|
||||||
|
|||||||
@@ -171,21 +171,6 @@ export function findHardpointId(groupName, clss, rating, name, mount, missile) {
|
|||||||
return h ? h.id : 0;
|
return h ? h.id : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Looks up the bulkhead module for a specific ship and bulkhead
|
|
||||||
* @param {String} shipId Unique ship Id/Key
|
|
||||||
* @param {string|number} index Index for the specified bulkhead
|
|
||||||
* @return {Object} The bulkhead module object
|
|
||||||
*/
|
|
||||||
export function bulkheads(shipId, index) {
|
|
||||||
let bulkhead = Ships[shipId].bulkheads[index];
|
|
||||||
bulkhead.class = 1;
|
|
||||||
bulkhead.rating = 'I';
|
|
||||||
bulkhead.name = BulkheadNames[index];
|
|
||||||
|
|
||||||
return bulkhead;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the bulkhead index for the given bulkhead name
|
* Get the bulkhead index for the given bulkhead name
|
||||||
* @param {String} bulkheadName Bulkhead name in english
|
* @param {String} bulkheadName Bulkhead name in english
|
||||||
@@ -215,7 +200,5 @@ export function isShieldGenerator(g) {
|
|||||||
* @return {ModuleSet} The set of modules the ship can install
|
* @return {ModuleSet} The set of modules the ship can install
|
||||||
*/
|
*/
|
||||||
export function forShip(shipId) {
|
export function forShip(shipId) {
|
||||||
let ship = Ships[shipId];
|
return new ModuleSet(Modules, Ships[shipId]);
|
||||||
let maxInternal = isNaN(ship.slots.internal[0]) ? ship.slots.internal[0].class : ship.slots.internal[0];
|
|
||||||
return new ModuleSet(Modules, ship.properties.hullMass + 6.5, ship.slots.standard, maxInternal, ship.slots.hardpoints[0]);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export function toDetailedBuild(buildName, ship) {
|
|||||||
}],
|
}],
|
||||||
components: {
|
components: {
|
||||||
standard: {
|
standard: {
|
||||||
bulkheads: BulkheadNames[ship.bulkheads.index],
|
bulkheads: BulkheadNames[ship.bulkheads.m.index],
|
||||||
cargoHatch: { enabled: Boolean(ship.cargoHatch.enabled), priority: ship.cargoHatch.priority + 1 },
|
cargoHatch: { enabled: Boolean(ship.cargoHatch.enabled), priority: ship.cargoHatch.priority + 1 },
|
||||||
powerPlant: { class: standard[0].m.class, rating: standard[0].m.rating, enabled: Boolean(standard[0].enabled), priority: standard[0].priority + 1 },
|
powerPlant: { class: standard[0].m.class, rating: standard[0].m.rating, enabled: Boolean(standard[0].enabled), priority: standard[0].priority + 1 },
|
||||||
thrusters: { class: standard[1].m.class, rating: standard[1].m.rating, enabled: Boolean(standard[1].enabled), priority: standard[1].priority + 1 },
|
thrusters: { class: standard[1].m.class, rating: standard[1].m.rating, enabled: Boolean(standard[1].enabled), priority: standard[1].priority + 1 },
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ export default class Ship {
|
|||||||
*/
|
*/
|
||||||
getStandardString() {
|
getStandardString() {
|
||||||
if(!this.serialized.standard) {
|
if(!this.serialized.standard) {
|
||||||
this.serialized.standard = this.bulkheads.index + this.standard.reduce((arr, slot, i) => {
|
this.serialized.standard = this.bulkheads.m.index + this.standard.reduce((arr, slot, i) => {
|
||||||
arr[i] = slot.m ? slot.m.class + slot.m.rating : '-';
|
arr[i] = slot.m ? slot.m.class + slot.m.rating : '-';
|
||||||
return arr;
|
return arr;
|
||||||
}, new Array(this.standard.length)).join('');
|
}, new Array(this.standard.length)).join('');
|
||||||
@@ -855,8 +855,7 @@ export default class Ship {
|
|||||||
*/
|
*/
|
||||||
useBulkhead(index, preventUpdate) {
|
useBulkhead(index, preventUpdate) {
|
||||||
let oldBulkhead = this.bulkheads.m;
|
let oldBulkhead = this.bulkheads.m;
|
||||||
this.bulkheads.index = index;
|
this.bulkheads.m = this.availCS.getBulkhead(index);
|
||||||
this.bulkheads.m = ModuleUtils.bulkheads(this.id, index);
|
|
||||||
this.bulkheads.discountedCost = this.bulkheads.m.cost * this.moduleCostMultiplier;
|
this.bulkheads.discountedCost = this.bulkheads.m.cost * this.moduleCostMultiplier;
|
||||||
this.armourMultiplier = ArmourMultiplier[index];
|
this.armourMultiplier = ArmourMultiplier[index];
|
||||||
this.updateStats(this.bulkheads, this.bulkheads.m, oldBulkhead, preventUpdate);
|
this.updateStats(this.bulkheads, this.bulkheads.m, oldBulkhead, preventUpdate);
|
||||||
|
|||||||
Reference in New Issue
Block a user