diff --git a/app/js/shipyard/factory-component-set.js b/app/js/shipyard/factory-component-set.js index 59009639..26fdd3df 100755 --- a/app/js/shipyard/factory-component-set.js +++ b/app/js/shipyard/factory-component-set.js @@ -6,6 +6,13 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function(_) { }); } + function getKey(maxClass, eligible) { + if (eligible) { + return maxClass + Object.keys(eligible).join('-'); + } + return maxClass; + } + function ComponentSet(components, mass, maxCommonArr, maxInternal, maxHardPoint) { this.mass = mass; this.common = {}; @@ -36,34 +43,57 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function(_) { for (var g in components.internal) { this.internal[g] = filter(components.internal[g], maxInternal, 0, mass); } + + /** + * Create a memoized function for determining the components that are + * eligible for an internal slot + * @param {integer} c The max class component that can be mounted in the slot + * @param {Object} eligible) The map of eligible internal groups + * @return {object} A map of all eligible components by group + */ + this.getInts = _.memoize( + function(c, eligible) { + var o = {}; + for (var key in this.internal) { + if (eligible && !eligible[key]) { + continue; + } + var data = filter(this.internal[key], c, 0, this.mass); + if (data.length) { // If group is not empty + o[key] = data; + } + } + return o; + }, + getKey + ); + + /** + * Create a memoized function for determining the components that are + * eligible for an hardpoint slot + * @param {integer} c The max class component that can be mounted in the slot + * @param {Object} eligible) The map of eligible hardpoint groups + * @return {object} A map of all eligible components by group + */ + this.getHps = _.memoize( + function(c, eligible) { + var o = {}; + for (var key in this.hardpoints) { + if (eligible && !eligible[key]) { + continue; + } + var data = filter(this.hardpoints[key], c, c ? 1 : 0, this.mass); + if (data.length) { // If group is not empty + o[key] = data; + } + } + return o; + }, + getKey + ); + } - ComponentSet.prototype.getHps = function(c) { - if (!this.hpClass[c]) { - var o = this.hpClass[c] = {}; - for (var key in this.hardpoints) { - var data = filter(this.hardpoints[key], c, c ? 1 : 0, this.mass); - if (data.length) { // If group is not empty - o[key] = data; - } - } - } - return this.hpClass[c]; - }; - - ComponentSet.prototype.getInts = function(c) { - if (!this.intClass[c]) { - var o = this.intClass[c] = {}; - for (var key in this.internal) { - var data = filter(this.internal[key], c, 0, this.mass); - if (data.length) { // If group is not empty - o[key] = data; - } - } - } - return this.intClass[c]; - }; - return ComponentSet; }]); diff --git a/app/js/shipyard/factory-ship.js b/app/js/shipyard/factory-ship.js index f930ee70..dc0b10ec 100755 --- a/app/js/shipyard/factory-ship.js +++ b/app/js/shipyard/factory-ship.js @@ -36,7 +36,11 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength', var slotGroup = slots[slotType]; var group = this[slotType] = []; // Initialize Slot group (Common, Hardpoints, Internal) for (var i = 0; i < slotGroup.length; i++) { - group.push({ id: null, c: null, incCost: true, maxClass: slotGroup[i] }); + if (typeof slotGroup[i] == 'object') { + group.push({ id: null, c: null, incCost: true, maxClass: slotGroup[i].class, eligible: slotGroup[i].eligible }); + } else { + group.push({ id: null, c: null, incCost: true, maxClass: slotGroup[i] }); + } } } // Make a Ship 'slot'/item similar to other slots diff --git a/app/js/shipyard/service-components.js b/app/js/shipyard/service-components.js index b5e8847a..2a387c68 100755 --- a/app/js/shipyard/service-components.js +++ b/app/js/shipyard/service-components.js @@ -90,7 +90,8 @@ angular.module('shipyard').service('Components', ['lodash', 'ComponentsDB', 'Shi */ this.forShip = function(shipId) { var ship = Ships[shipId]; - return new ComponentSet(C, ship.minMassFilter || ship.properties.hullMass + 5, ship.slots.common, ship.slots.internal[0], ship.slots.hardpoints[0]); + var maxInternal = isNaN(ship.slots.internal[0]) ? ship.slots.internal[0].class : ship.slots.internal[0]; + return new ComponentSet(C, ship.minMassFilter || ship.properties.hullMass + 5, ship.slots.common, maxInternal, ship.slots.hardpoints[0]); }; }]); diff --git a/app/views/page-outfit.html b/app/views/page-outfit.html index a4379dd8..faf4f282 100644 --- a/app/views/page-outfit.html +++ b/app/views/page-outfit.html @@ -187,7 +187,7 @@