mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-08 22:33:24 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d28e69b1c | ||
|
|
abfe1b4a68 | ||
|
|
59e400d7b8 | ||
|
|
4b3bb3bcde | ||
|
|
a4a562bd40 | ||
|
|
a1506d4f37 | ||
|
|
8b0f58cb69 | ||
|
|
1a14674352 | ||
|
|
a2c32dd908 | ||
|
|
eb7383b31e | ||
|
|
2106ec0e93 | ||
|
|
5649dc9079 | ||
|
|
0d09607d30 | ||
|
|
d7415ea44a |
@@ -28,12 +28,14 @@ See [Data wiki](https://github.com/cmmcleod/coriolis/wiki/Database) for details
|
||||
|
||||
## License
|
||||
|
||||
The MIT License
|
||||
All Data and [associated JSON](https://github.com/cmmcleod/coriolis/tree/master/data) files are intellectual property and copyright of Frontier Developments plc ('Frontier', 'Frontier Developments') and are subject to their
|
||||
[terms and conditions](https://www.frontierstore.net/terms-and-conditions/).
|
||||
|
||||
The code specificially for Coriolis.io is released under the MIT License.
|
||||
Copyright (c) 2015 Coriolis.io, Colin McLeod
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
of this software (Javascript, CSS, HTML, and SVG files only), and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
|
||||
@@ -33,6 +33,8 @@ function($rootScope, $location, $window, $doc, $state, CArr, shipPurpose, sz, hp
|
||||
$rootScope.SZ = sz;
|
||||
$rootScope.HPC = hpc;
|
||||
$rootScope.GMAP = GroupMap;
|
||||
$rootScope.insurance = { opts: [{ name: 'Standard', pct: 0.05 }, { name: 'Alpha', pct: 0.025 }, { name: 'Beta', pct: 0.035 }] };
|
||||
$rootScope.discounts = { opts: [{ name: 'None', pct: 1 }, { name: 'Founders World - 10%', pct: 0.90 }] };
|
||||
$rootScope.STATUS = ['', 'DISABLED', 'OFF', 'ON'];
|
||||
$rootScope.STATUS_CLASS = ['', 'disabled', 'warning', 'secondary-disabled'];
|
||||
$rootScope.title = 'Coriolis';
|
||||
|
||||
@@ -83,9 +83,9 @@ angular.module('app').controller('OutfitController', ['$window', '$rootScope', '
|
||||
* @param {[type]} slot The slot object belonging to the ship instance
|
||||
* @param {[type]} e The event object
|
||||
*/
|
||||
$scope.select = function(type, slot, e) {
|
||||
$scope.select = function(type, slot, e, id) {
|
||||
e.stopPropagation();
|
||||
var id = angular.element(e.target).attr('cpid'); // Get component ID
|
||||
id = id || angular.element(e.target).attr('cpid'); // Get component ID
|
||||
|
||||
if (id) {
|
||||
if (id == 'empty') {
|
||||
|
||||
12
app/js/directives/directive-context-menu.js
Normal file
12
app/js/directives/directive-context-menu.js
Normal file
@@ -0,0 +1,12 @@
|
||||
angular.module('app').directive('contextMenu', ['$parse', function($parse) {
|
||||
return function(scope, element, attrs) {
|
||||
var fn = $parse(attrs.contextMenu);
|
||||
|
||||
element.bind('contextmenu', function(e) {
|
||||
scope.$apply(function() {
|
||||
e.preventDefault();
|
||||
fn(scope, { $event: e });
|
||||
});
|
||||
});
|
||||
};
|
||||
}]);
|
||||
@@ -12,17 +12,9 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
||||
scope.allComparisons = Persist.comparisons;
|
||||
scope.bs = Persist.state;
|
||||
|
||||
// Insurance options and management here for now.
|
||||
$rootScope.insurance = {
|
||||
opts: [
|
||||
{ name: 'Standard', pct: 0.05 },
|
||||
{ name: 'Alpha', pct: 0.025 },
|
||||
{ name: 'Beta', pct: 0.035 }
|
||||
]
|
||||
};
|
||||
|
||||
var insIndex = _.findIndex($rootScope.insurance.opts, 'name', Persist.getInsurance());
|
||||
$rootScope.insurance.current = $rootScope.insurance.opts[insIndex != -1 ? insIndex : 0];
|
||||
$rootScope.discounts.current = $rootScope.discounts.opts[Persist.getDiscount() || 0];
|
||||
|
||||
// Close menus if a navigation change event occurs
|
||||
$rootScope.$on('$stateChangeStart', function() {
|
||||
@@ -42,6 +34,13 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
||||
Persist.setInsurance($rootScope.insurance.current.name);
|
||||
};
|
||||
|
||||
/**
|
||||
* Save selected discount option
|
||||
*/
|
||||
scope.updateDiscount = function() {
|
||||
Persist.setDiscount($rootScope.discounts.opts.indexOf($rootScope.discounts.current));
|
||||
};
|
||||
|
||||
scope.openMenu = function(e, menu) {
|
||||
e.stopPropagation();
|
||||
if (menu == scope.openedMenu) {
|
||||
|
||||
@@ -8,6 +8,7 @@ angular.module('app').directive('powerBands', ['$window', function($window) {
|
||||
link: function(scope, element) {
|
||||
var margin = { top: 20, right: 130, bottom: 20, left: 40 },
|
||||
barHeight = 20,
|
||||
bands = null,
|
||||
innerHeight = (barHeight * 2) + 3,
|
||||
height = innerHeight + margin.top + margin.bottom + 1,
|
||||
wattScale = d3.scale.linear(),
|
||||
@@ -19,8 +20,17 @@ angular.module('app').directive('powerBands', ['$window', function($window) {
|
||||
// Create chart
|
||||
svg = d3.select(element[0]).append('svg'),
|
||||
vis = svg.append('g').attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'),
|
||||
deployed = vis.append('g'),
|
||||
retracted = vis.append('g');
|
||||
deployed = vis.append('g').attr('class', 'power-band'),
|
||||
retracted = vis.append('g').attr('class', 'power-band');
|
||||
|
||||
svg.on('contextmenu', function() {
|
||||
d3.event.preventDefault();
|
||||
for (var i = 0, l = bands.length; i < l; i++) {
|
||||
bands[i].retSelected = false;
|
||||
bands[i].depSelected = false;
|
||||
}
|
||||
render();
|
||||
});
|
||||
|
||||
// Create Y Axis SVG Elements
|
||||
vis.append('g').attr('class', 'watt axis');
|
||||
@@ -36,12 +46,17 @@ angular.module('app').directive('powerBands', ['$window', function($window) {
|
||||
angular.element($window).bind('orientationchange resize pwrchange', render);
|
||||
|
||||
function render() {
|
||||
var bands = scope.bands,
|
||||
available = scope.available,
|
||||
bands = scope.bands;
|
||||
|
||||
var available = scope.available,
|
||||
width = element[0].offsetWidth,
|
||||
w = width - margin.left - margin.right,
|
||||
maxBand = bands[bands.length - 1],
|
||||
maxPwr = Math.max(available, maxBand.deployedSum);
|
||||
deployedSum = 0,
|
||||
retractedSum = 0,
|
||||
retBandsSelected = false,
|
||||
depBandsSelected = false,
|
||||
maxPwr = Math.max(available, maxBand.retractedSum, maxBand.deployedSum);
|
||||
|
||||
// Update chart size
|
||||
svg.attr('width', width).attr('height', height);
|
||||
@@ -55,50 +70,80 @@ angular.module('app').directive('powerBands', ['$window', function($window) {
|
||||
// Update X & Y Axis
|
||||
wattScale.range([0, w]).domain([0, maxPwr]).clamp(true);
|
||||
pctScale.range([0, w]).domain([0, maxPwr / available]).clamp(true);
|
||||
|
||||
vis.selectAll('.watt.axis').call(wattAxis);
|
||||
vis.selectAll('.pct.axis').attr('transform', 'translate(0,' + innerHeight + ')').call(pctAxis);
|
||||
|
||||
retLbl
|
||||
.attr('x', w + 5 )
|
||||
.attr('class', maxBand.retractedSum > available ? 'warning' : 'primary')
|
||||
.text(wattFmt(Math.max(0, maxBand.retractedSum)) + ' (' + pctFmt(Math.max(0, maxBand.retractedSum / available)) + ')');
|
||||
for (var b = 0, l = bands.length; b < l; b++) {
|
||||
if (bands[b].retSelected) {
|
||||
retractedSum += bands[b].retracted + bands[b].retOnly;
|
||||
retBandsSelected = true;
|
||||
}
|
||||
if (bands[b].depSelected) {
|
||||
deployedSum += bands[b].deployed + bands[b].retracted;
|
||||
depBandsSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
depLbl
|
||||
.attr('x', w + 5 )
|
||||
.attr('class', maxBand.deployedSum > available ? 'warning' : 'primary')
|
||||
.text(wattFmt(Math.max(0, maxBand.deployedSum)) + ' (' + pctFmt(Math.max(0, maxBand.deployedSum / available)) + ')');
|
||||
updateLabel(retLbl, w, retBandsSelected, retBandsSelected ? retractedSum : maxBand.retractedSum, available);
|
||||
updateLabel(depLbl, w, depBandsSelected, depBandsSelected ? deployedSum : maxBand.deployedSum, available);
|
||||
|
||||
retracted.selectAll('rect').data(bands).enter().append('rect')
|
||||
.attr('height', barHeight)
|
||||
.attr('width', function(d) { return Math.max(wattScale(d.retracted) - 1, 0); })
|
||||
.attr('x', function(d) { return wattScale(d.retractedSum) - wattScale(d.retracted); })
|
||||
.attr('width', function(d) { return Math.max(wattScale(d.retracted + d.retOnly) - 1, 0); })
|
||||
.attr('x', function(d) { return wattScale(d.retractedSum) - wattScale(d.retracted + d.retOnly); })
|
||||
.attr('y', 1)
|
||||
.attr('class', function(d) { return (d.retractedSum > available) ? 'warning' : 'primary'; });
|
||||
.on('click', function(d) {
|
||||
d.retSelected = !d.retSelected;
|
||||
render();
|
||||
})
|
||||
.attr('class', function(d) { return getClass(d.retSelected, d.retractedSum, available); });
|
||||
|
||||
retracted.selectAll('text').data(bands).enter().append('text')
|
||||
.attr('x', function(d) { return wattScale(d.retractedSum) - (wattScale(d.retracted) / 2); })
|
||||
.attr('x', function(d) { return wattScale(d.retractedSum) - (wattScale(d.retracted + d.retOnly) / 2); })
|
||||
.attr('y', 15)
|
||||
.style('text-anchor', 'middle')
|
||||
.attr('class', 'primary-bg')
|
||||
.text(function(d, i) { return bandText(d.retracted, i); });
|
||||
.on('click', function(d) {
|
||||
d.retSelected = !d.retSelected;
|
||||
render();
|
||||
})
|
||||
.text(function(d, i) { return bandText(d.retracted + d.retOnly, i); });
|
||||
|
||||
deployed.selectAll('rect').data(bands).enter().append('rect')
|
||||
.attr('height', barHeight)
|
||||
.attr('width', function(d) { return Math.max(wattScale(d.deployed + d.retracted) - 1, 0); })
|
||||
.attr('x', function(d) { return wattScale(d.deployedSum) - wattScale(d.retracted) - wattScale(d.deployed); })
|
||||
.attr('y', barHeight + 2)
|
||||
.attr('class', function(d) { return (d.deployedSum > available) ? 'warning' : 'primary'; });
|
||||
.on('click', function(d) {
|
||||
d.depSelected = !d.depSelected;
|
||||
render();
|
||||
})
|
||||
.attr('class', function(d) { return getClass(d.depSelected, d.deployedSum, available); });
|
||||
|
||||
deployed.selectAll('text').data(bands).enter().append('text')
|
||||
.attr('x', function(d) { return wattScale(d.deployedSum) - ((wattScale(d.retracted) + wattScale(d.deployed)) / 2); })
|
||||
.attr('y', barHeight + 17)
|
||||
.style('text-anchor', 'middle')
|
||||
.attr('class', 'primary-bg')
|
||||
.on('click', function(d) {
|
||||
d.depSelected = !d.depSelected;
|
||||
render();
|
||||
})
|
||||
.text(function(d, i) { return bandText(d.deployed + d.retracted, i); });
|
||||
|
||||
}
|
||||
|
||||
function updateLabel(lbl, width, selected, sum, available) {
|
||||
lbl
|
||||
.attr('x', width + 5 )
|
||||
.attr('class', getClass(selected, sum, available))
|
||||
.text(wattFmt(Math.max(0, sum)) + ' (' + pctFmt(Math.max(0, sum / available)) + ')');
|
||||
}
|
||||
|
||||
function getClass(selected, sum, available) {
|
||||
return selected ? 'secondary' : (sum > available) ? 'warning' : 'primary';
|
||||
}
|
||||
|
||||
function bandText(val, index) {
|
||||
if (val > 0 && wattScale(val) > 13) {
|
||||
return index + 1;
|
||||
|
||||
@@ -183,6 +183,27 @@ angular.module('app').service('Persist', ['$window', 'lodash', function($window,
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Persist selected discount
|
||||
* @param {number} val Discount value/amount
|
||||
*/
|
||||
this.setDiscount = function(val) {
|
||||
if (this.lsEnabled) {
|
||||
return localStorage.setItem('discount', val);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the saved discount
|
||||
* @return {number} val Discount value/amount
|
||||
*/
|
||||
this.getDiscount = function() {
|
||||
if (this.lsEnabled) {
|
||||
return localStorage.getItem('discount');
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the last router state from local storage
|
||||
* @param {object} state State object containing state name and params
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength', 'calcJumpRange', 'lodash', function(Components, calcShieldStrength, calcJumpRange, _) {
|
||||
|
||||
/**
|
||||
* Returns the power usage type of a slot and it's particular component
|
||||
* @param {object} slot The Slot
|
||||
* @param {object} component The component in the slot
|
||||
* @return {string} The key for the power usage type
|
||||
*/
|
||||
function powerUsageType(slot, component) {
|
||||
if (component) {
|
||||
if (component.retractedOnly) {
|
||||
return 'retOnly';
|
||||
}
|
||||
if (component.passive) {
|
||||
return 'retracted';
|
||||
}
|
||||
}
|
||||
return slot.cat != 1 ? 'retracted' : 'deployed';
|
||||
}
|
||||
|
||||
/**
|
||||
* Ship model used to track all ship components and properties.
|
||||
*
|
||||
@@ -10,7 +28,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
function Ship(id, properties, slots) {
|
||||
this.id = id;
|
||||
this.cargoScoop = { c: Components.cargoScoop(), type: 'SYS' };
|
||||
this.bulkheads = { incCost: true, maxClass: 8 };
|
||||
this.bulkheads = { incCost: true, maxClass: 8, discount: 1 };
|
||||
|
||||
for (var p in properties) { this[p] = properties[p]; } // Copy all base properties from shipData
|
||||
|
||||
@@ -18,10 +36,10 @@ 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] });
|
||||
group.push({ id: null, c: null, incCost: true, maxClass: slotGroup[i], discount: 1 });
|
||||
}
|
||||
}
|
||||
this.c = { incCost: true, c: { name: this.name, cost: this.cost } }; // Make a 'Ship' component similar to other components
|
||||
this.c = { incCost: true, discount: 1, c: { name: this.name, cost: this.cost } }; // Make a 'Ship' component similar to other components
|
||||
|
||||
this.costList = _.union(this.internal, this.common, this.hardpoints);
|
||||
this.costList.push(this.bulkheads); // Add The bulkheads
|
||||
@@ -37,22 +55,12 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
this.powerList.unshift(this.common[0]); // Add Power Plant
|
||||
|
||||
this.priorityBands = [
|
||||
{ deployed: 0, retracted: 0 },
|
||||
{ deployed: 0, retracted: 0 },
|
||||
{ deployed: 0, retracted: 0 },
|
||||
{ deployed: 0, retracted: 0 },
|
||||
{ deployed: 0, retracted: 0 }
|
||||
{ deployed: 0, retracted: 0, retOnly: 0 },
|
||||
{ deployed: 0, retracted: 0, retOnly: 0 },
|
||||
{ deployed: 0, retracted: 0, retOnly: 0 },
|
||||
{ deployed: 0, retracted: 0, retOnly: 0 },
|
||||
{ deployed: 0, retracted: 0, retOnly: 0 }
|
||||
];
|
||||
|
||||
// Cumulative and aggragate stats
|
||||
this.fuelCapacity = 0;
|
||||
this.cargoCapacity = 0;
|
||||
this.ladenMass = 0;
|
||||
this.armourAdded = 0;
|
||||
this.shieldMultiplier = 1;
|
||||
this.totalCost = this.cost;
|
||||
this.unladenMass = this.mass;
|
||||
this.armourTotal = this.armour;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,6 +75,17 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
cl = common.length,
|
||||
i, l;
|
||||
|
||||
// Reset Cumulative stats
|
||||
this.fuelCapacity = 0;
|
||||
this.cargoCapacity = 0;
|
||||
this.ladenMass = 0;
|
||||
this.armourAdded = 0;
|
||||
this.shieldMultiplier = 1;
|
||||
this.totalCost = this.cost;
|
||||
this.unladenMass = this.mass;
|
||||
this.armourTotal = this.armour;
|
||||
|
||||
this.bulkheads.c = null;
|
||||
this.useBulkhead(comps.bulkheads || 0, true);
|
||||
this.cargoScoop.priority = priorities ? priorities[0] * 1 : 0;
|
||||
this.cargoScoop.enabled = enabled ? enabled[0] * 1 : true;
|
||||
@@ -74,6 +93,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
for (i = 0, l = this.priorityBands.length; i < l; i++) {
|
||||
this.priorityBands[i].deployed = 0;
|
||||
this.priorityBands[i].retracted = 0;
|
||||
this.priorityBands[i].retOnly = 0;
|
||||
}
|
||||
|
||||
if (this.cargoScoop.enabled) {
|
||||
@@ -81,6 +101,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
}
|
||||
|
||||
for (i = 0; i < cl; i++) {
|
||||
common[i].cat = 0;
|
||||
common[i].enabled = enabled ? enabled[i + 1] * 1 : true;
|
||||
common[i].priority = priorities ? priorities[i + 1] * 1 : 0;
|
||||
common[i].type = 'SYS';
|
||||
@@ -93,6 +114,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
cl++; // Increase accounts for Cargo Scoop
|
||||
|
||||
for (i = 0, l = hps.length; i < l; i++) {
|
||||
hps[i].cat = 1;
|
||||
hps[i].enabled = enabled ? enabled[cl + i] * 1 : true;
|
||||
hps[i].priority = priorities ? priorities[cl + i] * 1 : 0;
|
||||
hps[i].type = hps[i].maxClass ? 'WEP' : 'SYS';
|
||||
@@ -106,6 +128,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
cl += hps.length; // Increase accounts for hardpoints
|
||||
|
||||
for (i = 0, l = internal.length; i < l; i++) {
|
||||
internal[i].cat = 2;
|
||||
internal[i].enabled = enabled ? enabled[cl + i] * 1 : true;
|
||||
internal[i].priority = priorities ? priorities[cl + i] * 1 : 0;
|
||||
internal[i].type = 'SYS';
|
||||
@@ -140,18 +163,14 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
*/
|
||||
Ship.prototype.use = function(slot, id, component, preventUpdate) {
|
||||
if (slot.id != id) { // Selecting a different component
|
||||
var slotIndex = this.internal.indexOf(slot);
|
||||
// Slot is an internal slot, is not being emptied, and the selected component group/type must be of unique
|
||||
if (slotIndex != -1 && 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 similarSlotIndex = this.findInternalByGroup(component.grp);
|
||||
var similarSlot = this.findInternalByGroup(component.grp);
|
||||
// If another slot has an installed component with of the same type
|
||||
if (similarSlotIndex != -1 && similarSlotIndex != slotIndex) {
|
||||
// Empty the slot
|
||||
var similarSlot = this.internal[similarSlotIndex];
|
||||
if (similarSlot && similarSlot !== slot) {
|
||||
this.updateStats(similarSlot, null, similarSlot.c, true); // Update stats but don't trigger a global update
|
||||
similarSlot.id = null;
|
||||
similarSlot.c = null;
|
||||
similarSlot.id = similarSlot.c = null; // Empty the slot
|
||||
}
|
||||
}
|
||||
var oldComponent = slot.c;
|
||||
@@ -180,9 +199,13 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
* @return {number} The index of the slot in ship.internal
|
||||
*/
|
||||
Ship.prototype.findInternalByGroup = function(group) {
|
||||
return _.findIndex(this.internal, function(slot) {
|
||||
var index = _.findIndex(this.internal, function(slot) {
|
||||
return slot.c && slot.c.grp == group;
|
||||
});
|
||||
if (index !== -1) {
|
||||
return this.internal[index];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -197,7 +220,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
slot.priority = newPriority;
|
||||
|
||||
if (slot.enabled) { // Only update power if the slot is enabled
|
||||
var usage = (slot.c.passive || this.hardpoints.indexOf(slot) == -1) ? 'retracted' : 'deployed';
|
||||
var usage = powerUsageType(slot, slot.c);
|
||||
this.priorityBands[oldPriority][usage] -= slot.c.power;
|
||||
this.priorityBands[newPriority][usage] += slot.c.power;
|
||||
this.updatePower();
|
||||
@@ -216,8 +239,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
|
||||
Ship.prototype.setSlotEnabled = function(slot, enabled) {
|
||||
if (slot.enabled != enabled && slot.c) { // Enabled state is changing
|
||||
var usage = (slot.c.passive || this.hardpoints.indexOf(slot) == -1) ? 'retracted' : 'deployed';
|
||||
this.priorityBands[slot.priority][usage] += enabled ? slot.c.power : -slot.c.power;
|
||||
this.priorityBands[slot.priority][powerUsageType(slot, slot.c)] += enabled ? slot.c.power : -slot.c.power;
|
||||
this.updatePower();
|
||||
}
|
||||
slot.enabled = enabled;
|
||||
@@ -228,9 +250,10 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
return 0; // No Status (Not possible)
|
||||
} else if (!slot.enabled) {
|
||||
return 1; // Disabled
|
||||
} else if (deployed) {
|
||||
} else if (deployed && !slot.c.retractedOnly) { // Certain component (e.g. Detaild Surface scanner) are power only while retracted
|
||||
return this.priorityBands[slot.priority].deployedSum > this.powerAvailable ? 2 : 3; // Offline : Online
|
||||
} else if (this.hardpoints.indexOf(slot) != -1 && !slot.c.passive) { // Active hardpoints have no retracted status
|
||||
// Active hardpoints have no retracted status
|
||||
} else if ((deployed && slot.c.retractedOnly) || (slot.cat === 1 && !slot.c.passive)) {
|
||||
return 0; // No Status (Not possible)
|
||||
}
|
||||
return this.priorityBands[slot.priority].retractedSum > this.powerAvailable ? 2 : 3; // Offline : Online
|
||||
@@ -240,7 +263,6 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
* Updates the ship's cumulative and aggregated stats based on the component change.
|
||||
*/
|
||||
Ship.prototype.updateStats = function(slot, n, old, preventUpdate) {
|
||||
var isHardPoint = this.hardpoints.indexOf(slot) != -1;
|
||||
var powerChange = slot == this.common[0];
|
||||
|
||||
if (old) { // Old component now being removed
|
||||
@@ -264,7 +286,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
}
|
||||
|
||||
if (old.power && slot.enabled) {
|
||||
this.priorityBands[slot.priority][(isHardPoint && !old.passive) ? 'deployed' : 'retracted'] -= old.power;
|
||||
this.priorityBands[slot.priority][powerUsageType(slot, old)] -= old.power;
|
||||
powerChange = true;
|
||||
}
|
||||
this.unladenMass -= old.mass || 0;
|
||||
@@ -294,7 +316,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
}
|
||||
|
||||
if (n.power && slot.enabled) {
|
||||
this.priorityBands[slot.priority][(isHardPoint && !n.passive) ? 'deployed' : 'retracted'] += n.power;
|
||||
this.priorityBands[slot.priority][powerUsageType(slot, n)] += n.power;
|
||||
powerChange = true;
|
||||
}
|
||||
this.unladenMass += n.mass || 0;
|
||||
@@ -318,7 +340,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
|
||||
for (var i = 0, l = bands.length; i < l; i++) {
|
||||
var band = bands[i];
|
||||
prevRetracted = band.retractedSum = prevRetracted + band.retracted;
|
||||
prevRetracted = band.retractedSum = prevRetracted + band.retracted + band.retOnly;
|
||||
prevDeployed = band.deployedSum = prevDeployed + band.deployed + band.retracted;
|
||||
}
|
||||
|
||||
@@ -328,8 +350,8 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
};
|
||||
|
||||
Ship.prototype.updateShieldStrength = function() {
|
||||
var sgSI = this.findInternalByGroup('sg'); // Find Shield Generator slot Index if any
|
||||
this.shieldStrength = sgSI != -1 ? calcShieldStrength(this.mass, this.shields, this.internal[sgSI].c, this.shieldMultiplier) : 0;
|
||||
var sgSlot = this.findInternalByGroup('sg'); // Find Shield Generator slot Index if any
|
||||
this.shieldStrength = sgSlot ? calcShieldStrength(this.mass, this.shields, sgSlot.c, this.shieldMultiplier) : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -169,6 +169,12 @@ table.total {
|
||||
}
|
||||
}
|
||||
|
||||
.power-band {
|
||||
text, rect {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
#componentPriority {
|
||||
.tablet({
|
||||
text.primary, text.warning, text.primary-bg {
|
||||
|
||||
@@ -51,6 +51,10 @@
|
||||
<ul>
|
||||
Insurance
|
||||
<li><select ng-model="insurance.current" ng-options="ins.name for (i,ins) in insurance.opts" ng-change="updateInsurance()"></select></li>
|
||||
</ul><br>
|
||||
<ul>
|
||||
Discount
|
||||
<li><select ng-model="discounts.current" ng-options="d.name for (i,d) in discounts.opts" ng-change="updateDiscount()"></select></li>
|
||||
</ul>
|
||||
<hr />
|
||||
<ul>
|
||||
|
||||
@@ -165,7 +165,7 @@
|
||||
|
||||
<div id="internal" class="group">
|
||||
<h1>Internal Compartments</h1>
|
||||
<div class="slot" ng-repeat="i in ship.internal" ng-click="selectSlot($event, i)" ng-class="{selected: selectedSlot==i}">
|
||||
<div class="slot" ng-repeat="i in ship.internal" ng-click="selectSlot($event, i)" context-menu="select('i', i, $event, 'empty')" ng-class="{selected: selectedSlot==i}">
|
||||
<div slot-internal class="details" slot="i" lbl="GMAP[i.c.grp]" fuel="ship.fuelCapacity"></div>
|
||||
<div class="select" ng-if="selectedSlot==i" ng-click="select('i',i,$event)">
|
||||
<div component-select s="i" groups="availCS.getInts(i.maxClass)"></div>
|
||||
@@ -175,7 +175,7 @@
|
||||
|
||||
<div id="hardpoints" class="group">
|
||||
<h1>HardPoints</h1>
|
||||
<div class="slot" ng-repeat="h in ship.hardpoints | filter:{maxClass: '!0'}" ng-click="selectSlot($event, h)" ng-class="{selected: selectedSlot==h}">
|
||||
<div class="slot" ng-repeat="h in ship.hardpoints | filter:{maxClass: '!0'}" ng-click="selectSlot($event, h)" context-menu="select('h', h, $event, 'empty')" ng-class="{selected: selectedSlot==h}">
|
||||
<div slot-hardpoint class="details" hp="h" size="HPC[h.maxClass]" lbl="GMAP[h.c.grp]"></div>
|
||||
<div class="select" ng-class="{hardpoint: h.maxClass > 0}" ng-if="selectedSlot==h" ng-click="select('h',h,$event)">
|
||||
<div component-select s="h" groups="availCS.getHps(h.maxClass)"></div>
|
||||
@@ -185,7 +185,7 @@
|
||||
|
||||
<div id="utility" class="group">
|
||||
<h1>Utility Mounts</h1>
|
||||
<div class="slot" ng-repeat="h in ship.hardpoints | filter:{maxClass: '0'}" ng-click="selectSlot($event, h)" ng-class="{selected: selectedSlot==h}">
|
||||
<div class="slot" ng-repeat="h in ship.hardpoints | filter:{maxClass: '0'}" ng-click="selectSlot($event, h)" context-menu="select('h', h, $event, 'empty')" ng-class="{selected: selectedSlot==h}">
|
||||
<div slot-hardpoint class="details" hp="h" size="HPC[h.maxClass]" lbl="GMAP[h.c.grp]"></div>
|
||||
<div class="select" ng-class="{hardpoint: h.maxClass > 0}" ng-if="selectedSlot==h" ng-click="select('h',h,$event)">
|
||||
<div component-select s="h" groups="availCS.getHps(h.maxClass)"></div>
|
||||
@@ -242,21 +242,21 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="toggleable" ng-repeat="c in costList | orderBy:costPredicate:costDesc" ng-if="c.c.cost > 0" ng-class="{disabled:!c.incCost}" ng-click="toggleCost(c)">
|
||||
<td style="width:1em;">{{c.c.class}}{{c.c.rating}}</td>
|
||||
<td class="le shorten" ng-bind="cName(c)"></td>
|
||||
<td class="ri">{{fCrd(c.c.cost)}} <u>CR</u></td>
|
||||
<tr ng-repeat="c in costList | orderBy:costPredicate:costDesc" ng-if="c.c.cost > 0" ng-class="{disabled:!c.incCost}">
|
||||
<td class="toggleable" style="width:1em;" ng-click="toggleCost(c)">{{c.c.class}}{{c.c.rating}}</td>
|
||||
<td class="le toggleable shorten" ng-bind="cName(c)" ng-click="toggleCost(c)"></td>
|
||||
<td class="ri toggleable" ng-click="toggleCost(c)">{{fCrd(discounts.current.pct * c.c.cost)}} <u>CR</u></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="total">
|
||||
<tr class="ri">
|
||||
<td class="lbl">Total</td>
|
||||
<td>{{fCrd(ship.totalCost)}} <u>CR</u></td>
|
||||
<td>{{fCrd(ship.totalCost * discounts.current.pct)}} <u>CR</u></td>
|
||||
</tr>
|
||||
<tr class="ri">
|
||||
<td class="lbl">Insurance</td>
|
||||
<td>{{fCrd(ship.totalCost * insurance.current.pct)}} <u>CR</u></td>
|
||||
<td>{{fCrd(ship.totalCost * discounts.current.pct * insurance.current.pct)}} <u>CR</u></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
"grp": "sc",
|
||||
"name": "Detailed Surface Scanner",
|
||||
"class": 1,
|
||||
"retractedOnly": 1,
|
||||
"rating": "C",
|
||||
"cost": 250000,
|
||||
"mass": 1.3,
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
"name": "Diamondback Scout",
|
||||
"manufacturer": "Lakon",
|
||||
"class": 1,
|
||||
"cost": 461312,
|
||||
"cost": 461342,
|
||||
"speed": 283,
|
||||
"boost": 384,
|
||||
"agility": 8,
|
||||
"shields": 93,
|
||||
"shields": 118,
|
||||
"armour": 216,
|
||||
"fuelcost": 50,
|
||||
"mass": 170
|
||||
},
|
||||
"retailCost": 564300,
|
||||
"retailCost": 564330,
|
||||
"slots": {
|
||||
"common": [
|
||||
4,
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
"name": "Diamondback Explorer",
|
||||
"manufacturer": "Lakon",
|
||||
"class": 1,
|
||||
"cost": 1740931,
|
||||
"cost": 1635691,
|
||||
"speed": 242,
|
||||
"boost": 316,
|
||||
"agility": 5,
|
||||
"shields": 115,
|
||||
"shields": 146,
|
||||
"armour": 270,
|
||||
"fuelcost": 50,
|
||||
"mass": 298
|
||||
},
|
||||
"retailCost": 2000000,
|
||||
"retailCost": 1894760,
|
||||
"slots": {
|
||||
"common": [
|
||||
4,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"name": "Imperial Courier",
|
||||
"manufacturer": "Gutamaya",
|
||||
"class": 1,
|
||||
"cost": 2481521,
|
||||
"cost": 2481552,
|
||||
"speed": 277,
|
||||
"boost": 380,
|
||||
"agility": 6,
|
||||
@@ -14,7 +14,7 @@
|
||||
"fuelcost": 50,
|
||||
"mass": 35
|
||||
},
|
||||
"retailCost": 2542900,
|
||||
"retailCost": 2542931,
|
||||
"slots": {
|
||||
"common": [
|
||||
4,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "coriolis_shipyard",
|
||||
"version": "0.11.0",
|
||||
"version": "0.12.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cmmcleod/coriolis"
|
||||
|
||||
@@ -31,4 +31,40 @@ 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');
|
||||
}
|
||||
|
||||
testShip.buildWith(buildB);
|
||||
|
||||
for(var p in testShip) {
|
||||
expect(testShip[p]).toEqual(shipB[p], p + ' does not match');
|
||||
}
|
||||
|
||||
testShip.buildWith(buildA);
|
||||
|
||||
for(var p in testShip) {
|
||||
expect(testShip[p]).toEqual(shipA[p], p + ' does not match');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user