Bug fixes, component ordering

This commit is contained in:
Colin McLeod
2015-05-04 19:42:30 -07:00
parent f4df56e34a
commit 326bb13e41
31 changed files with 1145 additions and 814 deletions

View File

@@ -36,7 +36,7 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function (_) {
var o = this.hpClass[c] = {};
for(var key in this.hardpoints) {
var data = filter(this.hardpoints[key], c, c? 1 : 0, this.mass);
if(Object.keys(data).length) { // If group is not empty
if(data.length) { // If group is not empty
o[key] = data;
}
}
@@ -49,7 +49,7 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function (_) {
var o = this.intClass[c] = {};
for(var key in this.internal) {
var data = filter(this.internal[key], c, 0, this.mass);
if(Object.keys(data).length) { // If group is not empty
if(data.length) { // If group is not empty
o[key] = data;
}
}
@@ -58,13 +58,9 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function (_) {
};
function filter (data, maxClass, minClass, mass) {
var set = {};
_.forEach(data, function (c,id) {
if (c.class <= maxClass && c.class >= minClass && (c.maxmass === undefined || mass <= c.maxmass) ) {
set[id] = c;
}
return _.filter(data, function (c) {
return c.class <= maxClass && c.class >= minClass && (c.maxmass === undefined || mass <= c.maxmass)
});
return set;
}
return ComponentSet;

View File

@@ -10,17 +10,27 @@ angular.module('shipyard').service('Components', ['lodash', 'ComponentSet', func
};
this.hardpoints = function(id) {
var c = _.find(C.hardpoints, function(o) {
return o[id];
})
return c[id];
for (var n in C.hardpoints) {
var group = C.hardpoints[n];
for (var i = 0; i < group.length; i++) {
if (group[i].id == id) {
return group[i];
}
}
}
return null;
};
this.internal = function(id) {
var c = _.find(C.internal, function(o) {
return o[id];
})
return c[id];
for (var n in C.internal) {
var group = C.internal[n];
for (var i = 0; i < group.length; i++) {
if (group[i].id == id) {
return group[i];
}
}
}
return null;
};
this.bulkheads = function(shipId, bulkheadsId) {