Encode blueprint information event when no active modifications

This commit is contained in:
Cmdr McDonald
2017-04-15 18:11:09 +01:00
parent 0a26f76fb4
commit 22f83b79af
3 changed files with 63 additions and 27 deletions

View File

@@ -1,3 +1,6 @@
#2.3.3
* Remove unused blueprint when hitting reset
#2.3.2 #2.3.2
* Use scan range for DSS rather than scan time * Use scan range for DSS rather than scan time
* Fix companion API import of Dolphin * Fix companion API import of Dolphin

View File

@@ -130,10 +130,10 @@ export default class ModificationsMenu extends TranslatedComponent {
*/ */
_blueprintSelected(fdname, grade) { _blueprintSelected(fdname, grade) {
this.context.tooltip(null); this.context.tooltip(null);
const { m } = this.props; const { m, ship } = this.props;
const blueprint = getBlueprint(fdname, m); const blueprint = getBlueprint(fdname, m);
blueprint.grade = grade; blueprint.grade = grade;
m.blueprint = blueprint; ship.setModuleBlueprint(m, blueprint);
this.setState({ blueprintMenuOpened: false }); this.setState({ blueprintMenuOpened: false });
this.props.onChange(); this.props.onChange();
@@ -155,15 +155,10 @@ export default class ModificationsMenu extends TranslatedComponent {
this.context.tooltip(null); this.context.tooltip(null);
const { m, ship } = this.props; const { m, ship } = this.props;
if (m.blueprint) { if (special === null) {
if (special === null) { ship.clearModuelSpecial(m);
m.blueprint.special = null; } else {
} else { ship.setModuleSpecial(m, Modifications.specials[special]);
m.blueprint.special = Modifications.specials[special];
}
ship.recalculateDps();
ship.recalculateHps();
ship.recalculateEps();
} }
this.setState({ specialMenuOpened: false }); this.setState({ specialMenuOpened: false });
@@ -268,7 +263,7 @@ export default class ModificationsMenu extends TranslatedComponent {
_reset() { _reset() {
const { m, ship } = this.props; const { m, ship } = this.props;
ship.clearModifications(m); ship.clearModifications(m);
ship.clearBlueprint(m); ship.clearModuleBlueprint(m);
this.props.onChange(); this.props.onChange();
} }
@@ -294,7 +289,7 @@ export default class ModificationsMenu extends TranslatedComponent {
let blueprintLabel; let blueprintLabel;
let haveBlueprint = false; let haveBlueprint = false;
let blueprintTt; let blueprintTt;
if (m.blueprint && !isEmpty(m.blueprint)) { if (m.blueprint && m.blueprint.name) {
blueprintLabel = translate(m.blueprint.name) + ' ' + translate('grade') + ' ' + m.blueprint.grade; blueprintLabel = translate(m.blueprint.name) + ' ' + translate('grade') + ' ' + m.blueprint.grade;
haveBlueprint = true; haveBlueprint = true;
blueprintTt = blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade], Modifications.modules[m.grp].blueprints[m.blueprint.fdname].grades[m.blueprint.grade].engineers, m.grp); blueprintTt = blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade], Modifications.modules[m.grp].blueprints[m.blueprint.fdname].grades[m.blueprint.grade].engineers, m.grp);

View File

@@ -429,11 +429,45 @@ export default class Ship {
} }
/** /**
* Clear blueprint for a module * Set blueprint for a module
* @param {Number} m The module for which to clear the modifications * @param {Object} m The module for which to set the blueprint
* @param {Object} bp The blueprint
*/ */
clearBlueprint(m) { setModuleBlueprint(m, bp) {
m.blueprint = bp;
this.updateModificationsString();
}
/**
* Clear blueprint for a module
* @param {Object} m The module for which to clear the blueprint
*/
clearModuleBlueprint(m) {
m.blueprint = {}; m.blueprint = {};
this.updateModificationsString();
}
/**
* Set special for a module
* @param {Object} m The module for which to set the blueprint
* @param {Object} bp The blueprint
*/
setModuleSpecial(m, special) {
if (m.blueprint) {
m.blueprint.special = special;
}
this.recalculateDps().recalculateHps().recalculateEps();
}
/**
* Clear special for a module
* @param {Object} m The module for which to clear the blueprint
*/
clearModuleSpecial(m) {
if (m.blueprint) {
m.blueprint.special = null;
}
this.recalculateDps().recalculateHps().recalculateEps();
} }
/** /**
@@ -1445,16 +1479,20 @@ export default class Ship {
// Now work out the size of the binary buffer from our modifications array // Now work out the size of the binary buffer from our modifications array
let bufsize = 0; let bufsize = 0;
for (let slot of slots) { for (let i = 0; i < slots.length; i++) {
if (slot.length > 0) { if (slots[i].length > 0 || (blueprints[i] && blueprints[i].id)) {
// Length is 1 for the slot ID, 10 for the blueprint name and grade, 5 for each modification, and 1 for the end marker // Length is 1 for the slot ID, 5 for each modification, and 1 for the end marker
bufsize = bufsize + 1 + 10 + (5 * slot.length) + 1; bufsize = bufsize + 1 + (5 * slots[i].length) + 1;
}
} if (blueprints[i] && blueprints[i].id) {
for (let special of specials) { // Additional 10 for the blueprint and grade
if (special) { bufsize += 10;
// Length is 5 for each special }
bufsize += 5;
if (specials[i]) {
// Additional 5 for each special
bufsize += 5;
}
} }
} }
@@ -1465,7 +1503,7 @@ export default class Ship {
let curpos = 0; let curpos = 0;
let i = 0; let i = 0;
for (let slot of slots) { for (let slot of slots) {
if (slot.length > 0) { if (slot.length > 0 || (blueprints[i] && blueprints[i].id)) {
buffer.writeInt8(i, curpos++); buffer.writeInt8(i, curpos++);
if (blueprints[i] && blueprints[i].id) { if (blueprints[i] && blueprints[i].id) {
buffer.writeInt8(MODIFICATION_ID_BLUEPRINT, curpos++); buffer.writeInt8(MODIFICATION_ID_BLUEPRINT, curpos++);