Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Commit

Permalink
Fix unique internal component regression bug, add tests, bump to 0.13.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin McLeod committed Jun 19, 2015
1 parent 4e7f1d3 commit 2502029
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 33 deletions.
4 changes: 2 additions & 2 deletions app/js/shipyard/factory-ship.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
Ship.prototype.use = function(slot, id, component, preventUpdate) {
if (slot.id != id) { // Selecting a different component
// Slot is an internal slot, is not being emptied, and the selected component group/type must be of unique
if (slot.cat != 2 && component && _.includes(['sg', 'rf', 'fs'], component.grp)) {
if (slot.cat == 2 && component && _.includes(['sg', 'rf', 'fs'], component.grp)) {
// Find another internal slot that already has this type/group installed
var similarSlot = this.findInternalByGroup(component.grp);
// If another slot has an installed component with of the same type
if (similarSlot && similarSlot !== slot) {
if (!preventUpdate && similarSlot && similarSlot !== slot) {
this.updateStats(similarSlot, null, similarSlot.c, true); // Update stats but don't trigger a global update
similarSlot.id = similarSlot.c = null; // Empty the slot
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coriolis_shipyard",
"version": "0.13.2",
"version": "0.13.3",
"repository": {
"type": "git",
"url": "https://github.com/cmmcleod/coriolis"
Expand Down
112 changes: 82 additions & 30 deletions test/tests/test-factory-ship.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
describe("Ship Factory", function() {

var Ship;
var Components;

beforeEach(module('shipyard'));
beforeEach(inject(['Ship', function (_Ship_) {
beforeEach(inject(['Ship', 'Components', function (_Ship_, _Components_) {
Ship = _Ship_;
Components = _Components_;
}]));

it("can build all ships", function() {
Expand Down Expand Up @@ -32,39 +34,89 @@ describe("Ship Factory", function() {
});

it("resets and rebuilds properly", function() {
var id = 'cobra_mk_iii';
var cobra = DB.ships[id];
var shipA = new Ship(id, cobra.properties, cobra.slots);
var shipB = new Ship(id, cobra.properties, cobra.slots);
var testShip = new Ship(id, cobra.properties, cobra.slots);

var buildA = cobra.defaults;
var buildB = {
common:['4A', '4A', '4A', '3D', '3A', '3A', '4C'],
hardpoints: ['0s', '0s', '2d', '2d', 0, '04'],
internal: ['45', '03', '2b', '2o', '27', '53']
};

shipA.buildWith(buildA); // Build A
shipB.buildWith(buildB);// Build B
testShip.buildWith(buildA);

for(var p in testShip) {
expect(testShip[p]).toEqual(shipA[p], p + ' does not match');
}
var id = 'cobra_mk_iii';
var cobra = DB.ships[id];
var shipA = new Ship(id, cobra.properties, cobra.slots);
var shipB = new Ship(id, cobra.properties, cobra.slots);
var testShip = new Ship(id, cobra.properties, cobra.slots);

var buildA = cobra.defaults;
var buildB = {
common:['4A', '4A', '4A', '3D', '3A', '3A', '4C'],
hardpoints: ['0s', '0s', '2d', '2d', 0, '04'],
internal: ['45', '03', '2b', '2o', '27', '53']
};

shipA.buildWith(buildA); // Build A
shipB.buildWith(buildB);// Build B
testShip.buildWith(buildA);

for(var p in testShip) {
expect(testShip[p]).toEqual(shipA[p], p + ' does not match');
}

testShip.buildWith(buildB);
testShip.buildWith(buildB);

for(var p in testShip) {
expect(testShip[p]).toEqual(shipB[p], p + ' does not match');
}
for(var p in testShip) {
expect(testShip[p]).toEqual(shipB[p], p + ' does not match');
}

testShip.buildWith(buildA);
testShip.buildWith(buildA);

for(var p in testShip) {
expect(testShip[p]).toEqual(shipA[p], p + ' does not match');
}
for(var p in testShip) {
expect(testShip[p]).toEqual(shipA[p], p + ' does not match');
}
});

it("enforces a single shield generator", function() {
var id = 'anaconda';
var anacondaData = DB.ships[id];
var anaconda = new Ship(id, anacondaData.properties, anacondaData.slots);
anaconda.buildWith(anacondaData.defaults);

expect(anaconda.internal[2].c.grp).toEqual('sg', 'Anaconda default shield generator slot');

anaconda.use(anaconda.internal[1], '4j', Components.internal('4j')); // 6E Shield Generator

expect(anaconda.internal[2].c).toEqual(null, 'Anaconda default shield generator slot is empty');
expect(anaconda.internal[2].id).toEqual(null, 'Anaconda default shield generator slot id is null');
expect(anaconda.internal[1].id).toEqual('4j', 'Slot 1 should have SG 4j in it');
expect(anaconda.internal[1].c.grp).toEqual('sg','Slot 1 should have SG 4j in it');

});

it("enforces a single shield fuel scoop", function() {
var id = 'anaconda';
var anacondaData = DB.ships[id];
var anaconda = new Ship(id, anacondaData.properties, anacondaData.slots);
anaconda.buildWith(anacondaData.defaults);

anaconda.use(anaconda.internal[4], '32', Components.internal('32')); // 4A Fuel Scoop
expect(anaconda.internal[4].c.grp).toEqual('fs', 'Anaconda fuel scoop slot');

anaconda.use(anaconda.internal[3], '32', Components.internal('32'));

expect(anaconda.internal[4].c).toEqual(null, 'Anaconda original fuel scoop slot is empty');
expect(anaconda.internal[4].id).toEqual(null, 'Anaconda original fuel scoop slot id is null');
expect(anaconda.internal[3].id).toEqual('32', 'Slot 1 should have FS 32 in it');
expect(anaconda.internal[3].c.grp).toEqual('fs','Slot 1 should have FS 32 in it');
});

it("enforces a single refinery", function() {
var id = 'anaconda';
var anacondaData = DB.ships[id];
var anaconda = new Ship(id, anacondaData.properties, anacondaData.slots);
anaconda.buildWith(anacondaData.defaults);

anaconda.use(anaconda.internal[4], '23', Components.internal('23')); // 4E Refinery
expect(anaconda.internal[4].c.grp).toEqual('rf', 'Anaconda refinery slot');

anaconda.use(anaconda.internal[3], '23', Components.internal('23'));

expect(anaconda.internal[4].c).toEqual(null, 'Anaconda original refinery slot is empty');
expect(anaconda.internal[4].id).toEqual(null, 'Anaconda original refinery slot id is null');
expect(anaconda.internal[3].id).toEqual('23', 'Slot 1 should have RF 23 in it');
expect(anaconda.internal[3].c.grp).toEqual('rf','Slot 1 should have RF 23 in it');
});

});
});

0 comments on commit 2502029

Please sign in to comment.