mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-10 15:15:34 +00:00
More refactoring and porting to React
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import React from 'react';
|
||||
import cn from 'classnames';
|
||||
import SlotSection from './SlotSection';
|
||||
import InternalSlot from './InternalSlot';
|
||||
import cn from 'classnames';
|
||||
import * as ModuleUtils from '../shipyard/ModuleUtils';
|
||||
|
||||
|
||||
export default class InternalSlotSection extends SlotSection {
|
||||
@@ -16,36 +17,70 @@ export default class InternalSlotSection extends SlotSection {
|
||||
}
|
||||
|
||||
_empty() {
|
||||
|
||||
this.props.ship.emptyInternal();
|
||||
this.props.onChange();
|
||||
this._close();
|
||||
}
|
||||
|
||||
_fillWithCargo() {
|
||||
|
||||
_fillWithCargo(event) {
|
||||
let clobber = event.getModifierState('Alt');
|
||||
let ship = this.props.ship;
|
||||
ship.internal.forEach((slot) => {
|
||||
if (clobber || !slot.m) {
|
||||
ship.use(slot, ModuleUtils.findInternal('cr', slot.maxClass, 'E'));
|
||||
}
|
||||
});
|
||||
this.props.onChange();
|
||||
this._close();
|
||||
}
|
||||
|
||||
_fillWithCells() {
|
||||
|
||||
_fillWithCells(event) {
|
||||
let clobber = event.getModifierState('Alt');
|
||||
let ship = this.props.ship;
|
||||
let chargeCap = 0; // Capacity of single activation
|
||||
ship.internal.forEach(function(slot) {
|
||||
if ((!slot.m || (clobber && !ModuleUtils.isShieldGenerator(slot.m.grp))) && (!slot.eligible || slot.eligible.scb)) { // Check eligibility due to Orca special case
|
||||
ship.use(slot, ModuleUtils.findInternal('scb', slot.maxClass, 'A'));
|
||||
ship.setSlotEnabled(slot, chargeCap <= ship.shieldStrength); // Don't waste cell capacity on overcharge
|
||||
chargeCap += slot.m.recharge;
|
||||
}
|
||||
});
|
||||
this.props.onChange();
|
||||
this._close();
|
||||
}
|
||||
|
||||
_fillWithArmor() {
|
||||
_fillWithArmor(event) {
|
||||
let clobber = event.getModifierState('Alt');
|
||||
let ship = this.props.ship;
|
||||
ship.internal.forEach((slot) => {
|
||||
if (clobber || !slot.c) {
|
||||
ship.use(slot, ModuleUtils.findInternal('hr', Math.min(slot.maxClass, 5), 'D')); // Hull reinforcements top out at 5D
|
||||
}
|
||||
});
|
||||
this.props.onChange();
|
||||
this._close();
|
||||
}
|
||||
|
||||
_contextMenu() {
|
||||
this._empty();
|
||||
}
|
||||
|
||||
_getSlots() {
|
||||
let slots = [];
|
||||
let {internal, fuelCapacity, ladenMass } = this.props.ship;
|
||||
let availableModules = this.props.ship.getAvailableModules();
|
||||
let currentMenu = this.state.currentMenu;
|
||||
let { currentMenu, ship } = this.props;
|
||||
let {internal, fuelCapacity, ladenMass } = ship;
|
||||
let availableModules = ship.getAvailableModules();
|
||||
|
||||
for (let i = 0, l = internal.length; i < l; i++) {
|
||||
let s = internal[i];
|
||||
slots.push(<InternalSlot
|
||||
key={i}
|
||||
size={s.maxClass}
|
||||
modules={availableModules.getInts(s.maxClass, s.eligible)}
|
||||
maxClass={s.maxClass}
|
||||
availableModules={() => availableModules.getInts(s.maxClass, s.eligible)}
|
||||
onOpen={this._openMenu.bind(this,s)}
|
||||
onSelect={this._selectModule.bind(this, i, s)}
|
||||
onSelect={this._selectModule.bind(this, s)}
|
||||
selected={currentMenu == s}
|
||||
enabled={s.enabled}
|
||||
m={s.m}
|
||||
fuel={fuelCapacity}
|
||||
shipMass={ladenMass}
|
||||
|
||||
Reference in New Issue
Block a user