From 623be748c07e367d6fc4c3264fb1fab3d2ff8ffc Mon Sep 17 00:00:00 2001 From: Colin McLeod Date: Tue, 6 Oct 2015 20:05:51 -0700 Subject: [PATCH] New and improved shipyard/home page --- app/js/controllers/controller-shipyard.js | 61 ++++++++++++++- app/views/page-shipyard.html | 92 +++++++++++++++++++++-- 2 files changed, 143 insertions(+), 10 deletions(-) diff --git a/app/js/controllers/controller-shipyard.js b/app/js/controllers/controller-shipyard.js index 1cc5477f..49638254 100755 --- a/app/js/controllers/controller-shipyard.js +++ b/app/js/controllers/controller-shipyard.js @@ -1,4 +1,59 @@ -angular.module('app').controller('ShipyardController', ['$rootScope', 'ShipsDB', function($rootScope, ships) { - $rootScope.title = 'Coriolis'; - $rootScope.ships = ships; +angular.module('app').controller('ShipyardController', ['$rootScope', '$scope', 'ShipsDB', 'Ship', 'Components', function($rootScope, $scope, ShipsDB, Ship, Components) { + $rootScope.title = 'Coriolis - Shipyard'; + $scope.shipPredicate = 'properties.name'; + $scope.shipDesc = false; + + function countHp(slot) { + this.hp[slot.maxClass]++; + this.hpCount++; + } + + function countInt(slot) { + var crEligible = !slot.eligible || slot.eligible.cr; + this.int[slot.maxClass - 1]++; // Subtract 1 since there is no Class 0 Internal compartment + this.intCount++; + this.maxCargo += crEligible ? Components.findInternal('cr', slot.maxClass, 'E').capacity : 0; + } + + function shipSummary(shipId, shipData) { + var summary = angular.copy(shipData.properties); + var ship = new Ship(shipId, shipData.properties, shipData.slots); + summary.id = s; + summary.hpCount = 0; + summary.intCount = 0; + summary.maxCargo = 0; + summary.hp = [0, 0, 0, 0, 0]; // Utility, Small, Medium, Large, Huge + summary.int = [0, 0, 0, 0, 0, 0, 0, 0]; // Sizes 1 - 8 + // Build Ship + ship.buildWith(shipData.defaults); // Populate with stock/default components + ship.hardpoints.forEach(countHp.bind(summary)); // Count Hardpoints by class + ship.internal.forEach(countInt.bind(summary)); // Count Internal Compartments by class + summary.retailCost = ship.totalCost; // Record Stock/Default/retail cost + ship.optimizeMass({ pd: '1D' }); // Optimize Mass with 1D PD for maximum possible jump range + summary.maxJumpRange = ship.unladenRange; // Record Jump Range + ship.optimizeMass({ th: ship.common[1].maxClass + 'A' }); // Optmize mass with Max Thrusters + summary.topSpeed = ship.topSpeed; + summary.topBoost = ship.topBoost; + + return summary; + } + + /* Initialization */ + + if (!$rootScope.shipsOverview) { // Only generate this once + $rootScope.shipsOverview = []; + for (var s in ShipsDB) { + $scope.shipsOverview.push(shipSummary(s, ShipsDB[s])); + } + } + + /** + * Sort ships + * @param {object} key Sort predicate + */ + $scope.sortShips = function(key) { + $scope.shipDesc = $scope.shipPredicate == key ? !$scope.shipDesc : $scope.shipDesc; + $scope.shipPredicate = key; + }; + }]); diff --git a/app/views/page-shipyard.html b/app/views/page-shipyard.html index 68da17a5..14a205ce 100755 --- a/app/views/page-shipyard.html +++ b/app/views/page-shipyard.html @@ -1,9 +1,87 @@
- -

-
- -
- {{fCrd(s.retailCost)}} CR -
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{fCrd(s.speed)}} m/s{{fCrd(s.boost)}} m/s{{fCrd(s.baseShieldStrength)}} Mj{{fCrd(s.topSpeed)}} m/s{{fCrd(s.topBoost)}} m/s{{fRound(s.maxJumpRange)}} LY{{fCrd(s.maxCargo)}} T{{fCrd(s.hullMass)}} T{{fCrd(s.retailCost)}} CR
+
+ +
\ No newline at end of file