Ensure that opponent piips are updated immediately when a new opponent is selecteD

This commit is contained in:
Cmdr McDonald
2017-04-03 13:46:14 +01:00
parent 171a84dd33
commit 1237833c7a

View File

@@ -267,15 +267,29 @@ export default class OutfittingPage extends Page {
*/
_opponentUpdated(opponent, opponentBuild) {
const opponentShip = new Ship(opponent, Ships[opponent].properties, Ships[opponent].slots);
let opponentSys = this.state.opponentSys;
let opponentEng = this.state.opponentEng;
let opponentWep = this.state.opponentWep;
if (opponentBuild && Persist.getBuild(opponent, opponentBuild)) {
// Ship is a particular build
opponentShip.buildFrom(Persist.getBuild(opponent, opponentBuild));
// Set pips for opponent
const opponentParts = Persist.getBuild(opponent, opponentBuild).split('.');
if (opponentParts.length >= 5) {
const opponentControl = LZString.decompressFromBase64(Utils.fromUrlSafe(opponentParts[4])).split('/');
opponentSys = parseFloat(opponentControl[0]);
opponentEng = parseFloat(opponentControl[1]);
opponentWep = parseFloat(opponentControl[2]);
}
} else {
// Ship is a stock build
opponentShip.buildWith(Ships[opponent].defaults);
opponentSys = 2;
opponentEng = 2;
opponentWep = 2;
}
this.setState({ opponent: opponentShip, opponentBuild }, () => this._updateRouteOnControlChange());
this.setState({ opponent: opponentShip, opponentBuild, opponentSys, opponentEng, opponentWep }, () => this._updateRouteOnControlChange());
}
/**