Tidy-ups for build changes

This commit is contained in:
Cmdr McDonald
2017-03-21 12:19:25 +00:00
parent 85f108556a
commit eb042b2778
3 changed files with 28 additions and 14 deletions

View File

@@ -126,7 +126,7 @@ export default class OutfittingSubpages extends TranslatedComponent {
const { ship, sys, eng, wep, cargo, fuel, boost, engagementRange, opponent, opponentBuild } = this.props;
Persist.setOutfittingTab('offence');
const marker = `${ship.toString()}:${opponent.name}:${opponentBuild}:${engagementRange}`;
const marker = `${ship.toString()}:${opponent.toString()}:${opponentBuild}:${engagementRange}`;
return <div>
<Offence marker={marker} ship={ship} opponent={opponent} wep={wep} engagementrange={engagementRange}/>
@@ -141,7 +141,7 @@ export default class OutfittingSubpages extends TranslatedComponent {
const { ship, sys, eng, wep, cargo, fuel, boost, engagementRange, opponent, opponentBuild } = this.props;
Persist.setOutfittingTab('defence');
const marker = `${ship.toString()}:${opponent.name}:${opponentBuild}:${engagementRange}`;
const marker = `${ship.toString()}:${opponent.toString()}:${opponentBuild}:${engagementRange}`;
return <div>
<Defence marker={marker} ship={ship} opponent={opponent} sys={sys} engagementrange={engagementRange}/>

View File

@@ -57,7 +57,6 @@ export default class ShipPicker extends TranslatedComponent {
_renderPickerMenu() {
const { ship, build } = this.props;
const _shipChange = this._shipChange;
const builds = Persist.getBuilds();
const buildList = [];
for (let shipId of this.shipOrder) {
@@ -68,7 +67,7 @@ export default class ShipPicker extends TranslatedComponent {
if (builds[shipId]) {
let buildNameOrder = Object.keys(builds[shipId]).sort();
for (let buildName of buildNameOrder) {
const buildSelected = ship.id == shipId && build == buildName;
const buildSelected = ship === shipId && build === buildName;
shipBuilds.push(<li key={shipId + '-' + buildName} className={ cn({ 'selected': buildSelected })} onClick={_shipChange.bind(this, shipId, buildName)}>{buildName}</li>);
}
}

View File

@@ -279,15 +279,19 @@ export default class OutfittingPage extends Page {
_saveBuild() {
const { code, buildName, newBuildName, shipId } = this.state;
if (buildName === newBuildName) {
Persist.saveBuild(shipId, buildName, code);
this._updateRoute(shipId, buildName, code);
} else {
Persist.saveBuild(shipId, newBuildName, code);
this._updateRoute(shipId, newBuildName, code);
}
this.setState({ buildName: newBuildName, code, savedCode: code, title: this._getTitle(newBuildName) });
let opponent, opponentBuild;
if (shipId === this.state.opponent.id && buildName === this.state.opponentBuild) {
// This is a save of our current opponent build; update it
opponentBuild = newBuildName;
opponent = new Ship(shipId, Ships[shipId].properties, Ships[shipId].slots).buildFrom(code);
} else {
opponentBuild = this.state.opponentBuild;
opponent = this.state.opponent;
}
this.setState({ buildName: newBuildName, code, savedCode: code, opponent, opponentBuild, title: this._getTitle(newBuildName) });
}
/**
@@ -299,7 +303,7 @@ export default class OutfittingPage extends Page {
Persist.deleteBuild(shipId, buildName);
Persist.saveBuild(shipId, newBuildName, code);
this._updateRoute(shipId, newBuildName, code);
this.setState({ buildName: newBuildName, code, savedCode: code });
this.setState({ buildName: newBuildName, code, savedCode: code, opponentBuild: newBuildName });
}
}
@@ -338,8 +342,19 @@ export default class OutfittingPage extends Page {
* Delete the build
*/
_deleteBuild() {
Persist.deleteBuild(this.state.shipId, this.state.buildName);
const { shipId, buildName } = this.state;
Persist.deleteBuild(shipId, buildName);
let opponentBuild;
if (shipId === this.state.opponent.id && buildName === this.state.opponentBuild) {
// Our current opponent has been deleted; revert to stock
opponentBuild = null;
} else {
opponentBuild = this.state.opponentBuild;
}
Router.go(outfitURL(this.state.shipId));
this.setState({ opponentBuild });
}
/**