mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-11 16:53:02 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2c32dd908 | ||
|
|
eb7383b31e | ||
|
|
2106ec0e93 | ||
|
|
5649dc9079 | ||
|
|
0d09607d30 | ||
|
|
d7415ea44a |
@@ -33,6 +33,8 @@ function($rootScope, $location, $window, $doc, $state, CArr, shipPurpose, sz, hp
|
|||||||
$rootScope.SZ = sz;
|
$rootScope.SZ = sz;
|
||||||
$rootScope.HPC = hpc;
|
$rootScope.HPC = hpc;
|
||||||
$rootScope.GMAP = GroupMap;
|
$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 = ['', 'DISABLED', 'OFF', 'ON'];
|
||||||
$rootScope.STATUS_CLASS = ['', 'disabled', 'warning', 'secondary-disabled'];
|
$rootScope.STATUS_CLASS = ['', 'disabled', 'warning', 'secondary-disabled'];
|
||||||
$rootScope.title = 'Coriolis';
|
$rootScope.title = 'Coriolis';
|
||||||
|
|||||||
@@ -12,17 +12,9 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
|||||||
scope.allComparisons = Persist.comparisons;
|
scope.allComparisons = Persist.comparisons;
|
||||||
scope.bs = Persist.state;
|
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());
|
var insIndex = _.findIndex($rootScope.insurance.opts, 'name', Persist.getInsurance());
|
||||||
$rootScope.insurance.current = $rootScope.insurance.opts[insIndex != -1 ? insIndex : 0];
|
$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
|
// Close menus if a navigation change event occurs
|
||||||
$rootScope.$on('$stateChangeStart', function() {
|
$rootScope.$on('$stateChangeStart', function() {
|
||||||
@@ -42,6 +34,13 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
|||||||
Persist.setInsurance($rootScope.insurance.current.name);
|
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) {
|
scope.openMenu = function(e, menu) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (menu == scope.openedMenu) {
|
if (menu == scope.openedMenu) {
|
||||||
|
|||||||
@@ -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
|
* Retrieve the last router state from local storage
|
||||||
* @param {object} state State object containing state name and params
|
* @param {object} state State object containing state name and params
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
function Ship(id, properties, slots) {
|
function Ship(id, properties, slots) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.cargoScoop = { c: Components.cargoScoop(), type: 'SYS' };
|
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
|
for (var p in properties) { this[p] = properties[p]; } // Copy all base properties from shipData
|
||||||
|
|
||||||
@@ -18,10 +18,10 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
var slotGroup = slots[slotType];
|
var slotGroup = slots[slotType];
|
||||||
var group = this[slotType] = []; // Initialize Slot group (Common, Hardpoints, Internal)
|
var group = this[slotType] = []; // Initialize Slot group (Common, Hardpoints, Internal)
|
||||||
for (var i = 0; i < slotGroup.length; i++) {
|
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 = _.union(this.internal, this.common, this.hardpoints);
|
||||||
this.costList.push(this.bulkheads); // Add The bulkheads
|
this.costList.push(this.bulkheads); // Add The bulkheads
|
||||||
@@ -43,16 +43,6 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
{ deployed: 0, retracted: 0 },
|
{ deployed: 0, retracted: 0 },
|
||||||
{ deployed: 0, retracted: 0 }
|
{ deployed: 0, retracted: 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 +57,17 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
cl = common.length,
|
cl = common.length,
|
||||||
i, l;
|
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.useBulkhead(comps.bulkheads || 0, true);
|
||||||
this.cargoScoop.priority = priorities ? priorities[0] * 1 : 0;
|
this.cargoScoop.priority = priorities ? priorities[0] * 1 : 0;
|
||||||
this.cargoScoop.enabled = enabled ? enabled[0] * 1 : true;
|
this.cargoScoop.enabled = enabled ? enabled[0] * 1 : true;
|
||||||
@@ -140,7 +141,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
*/
|
*/
|
||||||
Ship.prototype.use = function(slot, id, component, preventUpdate) {
|
Ship.prototype.use = function(slot, id, component, preventUpdate) {
|
||||||
if (slot.id != id) { // Selecting a different component
|
if (slot.id != id) { // Selecting a different component
|
||||||
var slotIndex = this.internal.indexOf(slot);
|
var slotIndex = preventUpdate ? -1 : this.internal.indexOf(slot);
|
||||||
// Slot is an internal slot, is not being emptied, and the selected component group/type must be of unique
|
// 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 (slotIndex != -1 && component && _.includes(['sg', 'rf', 'fs'], component.grp)) {
|
||||||
// Find another internal slot that already has this type/group installed
|
// Find another internal slot that already has this type/group installed
|
||||||
|
|||||||
@@ -51,6 +51,10 @@
|
|||||||
<ul>
|
<ul>
|
||||||
Insurance
|
Insurance
|
||||||
<li><select ng-model="insurance.current" ng-options="ins.name for (i,ins) in insurance.opts" ng-change="updateInsurance()"></select></li>
|
<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>
|
</ul>
|
||||||
<hr />
|
<hr />
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
@@ -242,21 +242,21 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<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)">
|
<tr ng-repeat="c in costList | orderBy:costPredicate:costDesc" ng-if="c.c.cost > 0" ng-class="{disabled:!c.incCost}">
|
||||||
<td style="width:1em;">{{c.c.class}}{{c.c.rating}}</td>
|
<td class="toggleable" style="width:1em;" ng-click="toggleCost(c)">{{c.c.class}}{{c.c.rating}}</td>
|
||||||
<td class="le shorten" ng-bind="cName(c)"></td>
|
<td class="le toggleable shorten" ng-bind="cName(c)" ng-click="toggleCost(c)"></td>
|
||||||
<td class="ri">{{fCrd(c.c.cost)}} <u>CR</u></td>
|
<td class="ri toggleable" ng-click="toggleCost(c)">{{fCrd(discounts.current.pct * c.c.cost)}} <u>CR</u></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<table class="total">
|
<table class="total">
|
||||||
<tr class="ri">
|
<tr class="ri">
|
||||||
<td class="lbl">Total</td>
|
<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>
|
||||||
<tr class="ri">
|
<tr class="ri">
|
||||||
<td class="lbl">Insurance</td>
|
<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>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"name": "Diamondback Scout",
|
"name": "Diamondback Scout",
|
||||||
"manufacturer": "Lakon",
|
"manufacturer": "Lakon",
|
||||||
"class": 1,
|
"class": 1,
|
||||||
"cost": 461312,
|
"cost": 461342,
|
||||||
"speed": 283,
|
"speed": 283,
|
||||||
"boost": 384,
|
"boost": 384,
|
||||||
"agility": 8,
|
"agility": 8,
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"fuelcost": 50,
|
"fuelcost": 50,
|
||||||
"mass": 170
|
"mass": 170
|
||||||
},
|
},
|
||||||
"retailCost": 564300,
|
"retailCost": 564330,
|
||||||
"slots": {
|
"slots": {
|
||||||
"common": [
|
"common": [
|
||||||
4,
|
4,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"name": "Diamondback Explorer",
|
"name": "Diamondback Explorer",
|
||||||
"manufacturer": "Lakon",
|
"manufacturer": "Lakon",
|
||||||
"class": 1,
|
"class": 1,
|
||||||
"cost": 1740931,
|
"cost": 1635691,
|
||||||
"speed": 242,
|
"speed": 242,
|
||||||
"boost": 316,
|
"boost": 316,
|
||||||
"agility": 5,
|
"agility": 5,
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"fuelcost": 50,
|
"fuelcost": 50,
|
||||||
"mass": 298
|
"mass": 298
|
||||||
},
|
},
|
||||||
"retailCost": 2000000,
|
"retailCost": 1894760,
|
||||||
"slots": {
|
"slots": {
|
||||||
"common": [
|
"common": [
|
||||||
4,
|
4,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"name": "Imperial Courier",
|
"name": "Imperial Courier",
|
||||||
"manufacturer": "Gutamaya",
|
"manufacturer": "Gutamaya",
|
||||||
"class": 1,
|
"class": 1,
|
||||||
"cost": 2481521,
|
"cost": 2481552,
|
||||||
"speed": 277,
|
"speed": 277,
|
||||||
"boost": 380,
|
"boost": 380,
|
||||||
"agility": 6,
|
"agility": 6,
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"fuelcost": 50,
|
"fuelcost": 50,
|
||||||
"mass": 35
|
"mass": 35
|
||||||
},
|
},
|
||||||
"retailCost": 2542900,
|
"retailCost": 2542931,
|
||||||
"slots": {
|
"slots": {
|
||||||
"common": [
|
"common": [
|
||||||
4,
|
4,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "coriolis_shipyard",
|
"name": "coriolis_shipyard",
|
||||||
"version": "0.11.0",
|
"version": "0.11.1",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/cmmcleod/coriolis"
|
"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