Custom comparisons, performance improvements

This commit is contained in:
Colin McLeod
2015-05-20 00:29:24 -07:00
parent 02fe76f43b
commit 6c1e3a7410
146 changed files with 1096 additions and 1062 deletions

View File

@@ -58,8 +58,8 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function (_) {
};
function filter (data, maxClass, minClass, mass) {
return _.filter(data, function (c, index, collection) {
return c.class <= maxClass && c.class >= minClass && (c.maxmass === undefined || mass <= c.maxmass)
return _.filter(data, function (c) {
return c.class <= maxClass && c.class >= minClass && (c.maxmass === undefined || mass <= c.maxmass);
});
}

View File

@@ -13,9 +13,9 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
this.cargoScoop = { enabled: true, c: Components.cargoScoop() };
this.bulkheads = { incCost: true, maxClass: 8 };
for (p in properties) { this[p] = properties[p]; } // Copy all base properties from shipData
for (var p in properties) { this[p] = properties[p]; } // Copy all base properties from shipData
for (slotType in slots) { // Initialize all slots
for (var slotType in slots) { // Initialize all slots
var slotGroup = slots[slotType];
var group = this[slotType] = []; // Initialize Slot group (Common, Hardpoints, Internal)
for(var i = 0; i < slotGroup.length; i++){
@@ -101,7 +101,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
* @return {object} The mutated sum object
*/
function optsSum(sum, slot) {
var c = slot.c
var c = slot.c;
if (c) { // The slot has a component installed
sum.cost += (slot.incCost && c.cost)? c.cost : 0;
sum.power += (slot.enabled && c.power)? c.power : 0;
@@ -121,7 +121,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
* @return {object} The mutated sum object
*/
function hpSum(sum, slot) {
var c = slot.c
var c = slot.c;
if (c) { // The slot has a component installed
sum.cost += (slot.incCost && c.cost)? c.cost : 0;
sum[c.passive? 'passive': 'active'] += slot.enabled? c.power : 0;
@@ -135,7 +135,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
this.bulkheads.id = index;
this.bulkheads.c = Components.bulkheads(this.id, index);
this.updateTotals(); // Update mass, range, shield strength, armor
}
};
/**
* Update a slot with a the component if the id is different from the current id for this slot.
@@ -166,6 +166,15 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
}
};
/**
* [jumpRange description]
* @param {number} mass [description]
* @return {number} Jump range in Light Years
*/
Ship.prototype.jumpRangeWithMass = function (mass) {
return calcJumpRange(mass, this.common[2].c);
};
/**
* Find an internal slot that has an installed component of the specific group.
*

View File

@@ -79,67 +79,67 @@ angular.module('shipyard', ['ngLodash'])
* @type {Array}
*/
.value('ShipFacets', [
{
{ // 0
title: 'Agility',
prop: 'agility',
props: ['agility'],
unit: '',
fmt: 'fCrd'
},
{
{ // 1
title: 'Speed',
props: ['speed', 'boost'],
lbls: ['Thrusters', 'Boost'],
unit: 'M/s',
fmt: 'fRound'
},
{
{ // 2
title: 'Armour',
prop: 'armour',
props: ['armour'],
unit: '',
fmt: 'fCrd'
},
{
{ // 3
title: 'Shields',
prop: 'shieldStrength',
props: ['shieldStrength'],
unit: 'Mj',
fmt: 'fRound'
},
{
{ // 4
title: 'Jump Range',
props: ['unladenJumpRange', 'ladenJumpRange'],
lbls: ['Unladen', 'Laden'],
unit: 'LY',
fmt: 'fRound'
},
{
{ // 5
title: 'Mass',
props: ['unladenMass', 'ladenMass'],
lbls: ['Unladen', 'Laden'],
unit: 'T',
fmt: 'fRound'
},
{
{ // 6
title: 'Cargo',
prop: 'cargoCapacity',
props: ['cargoCapacity'],
unit: 'T',
fmt: 'fRound'
},
{
{ // 7
title: 'Fuel',
prop: 'fuelCapacity',
props: ['fuelCapacity'],
unit: 'T',
fmt: 'fRound'
},
{
{ // 8
title: 'Power',
props: ['powerRetracted','powerDeployed','powerAvailable'],
lbls: ['Retracted', 'Deployed', 'Available'],
unit: 'MW',
fmt: 'fPwr'
},
{
{ // 9
title: 'Cost',
prop: 'totalCost',
props: ['totalCost'],
unit: 'CR',
fmt: 'fCrd'
}

View File

@@ -2,7 +2,7 @@ angular.module('shipyard').service('Components', ['lodash', 'ComponentsDB', 'Shi
this.cargoScoop = function() {
return { name: 'Cargo Scoop', class: 1, rating: 'H', power: 0.6};
}
};
this.common = function (typeIndex, componentId) {
return C.common[typeIndex][componentId];