diff --git a/app/js/app.js b/app/js/app.js index 3dc49a95..fda622f0 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -13,7 +13,6 @@ angular.module('app', ['ui.router', 'shipyard', 'ngLodash', 'app.templates']) $rootScope.HPC = hpc; $rootScope.igMap = igMap; $rootScope.hgMap = hgMap; - $rootScope.ships = DB.ships; $rootScope.title = 'Coriolis'; // Formatters diff --git a/app/js/config.js b/app/js/config.js index 73af2293..d275ad1d 100644 --- a/app/js/config.js +++ b/app/js/config.js @@ -1,7 +1,7 @@ /** * Sets up the routes and handlers before the Angular app is kicked off. */ -angular.module('app').config(['$provide','$stateProvider', '$urlRouterProvider', '$locationProvider', function ($provide, $stateProvider, $urlRouterProvider, $locationProvider) { +angular.module('app').config(['$provide','$stateProvider', '$urlRouterProvider', '$locationProvider', 'ShipsDB', function ($provide, $stateProvider, $urlRouterProvider, $locationProvider, ships) { // Use HTML5 push and replace state if possible $locationProvider.html5Mode(true); /** @@ -19,7 +19,7 @@ angular.module('app').config(['$provide','$stateProvider', '$urlRouterProvider', controller: 'OutfitController', resolve: { shipId: ['$stateParams',function ($p) { // Ensure ship exists before loading controller - if (!DB.ships[$p.shipId]) { + if (!ships[$p.shipId]) { throw { type: 'no-ship', message: $p.shipId }; } }] diff --git a/app/js/controllers/controller-outfit.js b/app/js/controllers/controller-outfit.js index 0cdf0615..1f336f0f 100644 --- a/app/js/controllers/controller-outfit.js +++ b/app/js/controllers/controller-outfit.js @@ -1,5 +1,5 @@ -angular.module('app').controller('OutfitController', ['$rootScope','$scope', '$state', '$stateParams', 'Ship', 'Components', 'Serializer', 'Persist', function ($rootScope, $scope, $state, $p, Ship, Components, Serializer, Persist) { - var data = DB.ships[$p.shipId]; // Retrieve the basic ship properties, slots and defaults +angular.module('app').controller('OutfitController', ['$rootScope','$scope', '$state', '$stateParams', 'ShipsDB', 'Ship', 'Components', 'Serializer', 'Persist', function ($rootScope, $scope, $state, $p, Ships, Ship, Components, Serializer, Persist) { + var data = Ships[$p.shipId]; // Retrieve the basic ship properties, slots and defaults var ship = new Ship($p.shipId, data.properties, data.slots); // Create a new Ship instance // Update the ship instance with the code (if provided) or the 'factory' defaults. diff --git a/app/js/controllers/controller-shipyard.js b/app/js/controllers/controller-shipyard.js index b5353f57..ec9929f7 100644 --- a/app/js/controllers/controller-shipyard.js +++ b/app/js/controllers/controller-shipyard.js @@ -1,4 +1,5 @@ -angular.module('app').controller('ShipyardController', ['$rootScope', function ($rootScope) { +angular.module('app').controller('ShipyardController', ['$rootScope', 'ShipsDB', function ($rootScope, ships) { $rootScope.title = 'Coriolis'; $rootScope.bodyClass = 'docking-bay'; + $rootScope.ships = ships; }]); \ No newline at end of file diff --git a/app/js/directives/directive-header.js b/app/js/directives/directive-header.js index a385d73c..706e1eaa 100644 --- a/app/js/directives/directive-header.js +++ b/app/js/directives/directive-header.js @@ -1,4 +1,4 @@ -angular.module('app').directive('shipyardHeader', ['lodash','$rootScope', 'Persist', function (_, $rootScope, Persist) { +angular.module('app').directive('shipyardHeader', ['lodash','$rootScope', 'Persist', 'ShipsDB', function (_, $rootScope, Persist, ships) { return { restrict: 'E', @@ -6,7 +6,7 @@ angular.module('app').directive('shipyardHeader', ['lodash','$rootScope', 'Persi scope: true, link: function (scope) { scope.openedMenu = null; - scope.ships = DB.ships; + scope.ships = ships; scope.allBuilds = Persist.builds; scope.bs = Persist.state; diff --git a/app/js/shipyard/factory-ship.js b/app/js/shipyard/factory-ship.js index 05857dde..939763db 100644 --- a/app/js/shipyard/factory-ship.js +++ b/app/js/shipyard/factory-ship.js @@ -117,7 +117,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength', Ship.prototype.useBulkhead = function(index) { this.bulkheads.id = index; - this.bulkheads.c = DB.components.bulkheads[this.id][index]; + this.bulkheads.c = Components.bulkheads(this.id, index); this.updateTotals(); // Update mass, range, shield strength, armor } diff --git a/app/js/shipyard/module-shipyard.js b/app/js/shipyard/module-shipyard.js index 39af3db4..9031e9dc 100644 --- a/app/js/shipyard/module-shipyard.js +++ b/app/js/shipyard/module-shipyard.js @@ -7,6 +7,9 @@ * @requires ngLodash is a dependency of this module. */ angular.module('shipyard', ['ngLodash']) + // Create 'angularized' references to DB.This will aid testing + .constant('ShipsDB', DB.ships) + .constant('ComponentsDB', DB.components) .value('commonArray', [ 'Power Plant', 'Thrusters', diff --git a/app/js/shipyard/service-components.js b/app/js/shipyard/service-components.js index 8c7b0e2e..4c086766 100644 --- a/app/js/shipyard/service-components.js +++ b/app/js/shipyard/service-components.js @@ -1,5 +1,4 @@ -angular.module('shipyard').service('Components', ['lodash', 'ComponentSet', function (_, ComponentSet) { - var C = DB.components; +angular.module('shipyard').service('Components', ['lodash', 'ComponentsDB', 'ShipsDB', 'ComponentSet', function (_, C, Ships, ComponentSet) { this.cargoScoop = function() { return { name: 'Cargo Scoop', class: 1, rating: 'H', power: 0.6}; @@ -38,7 +37,7 @@ angular.module('shipyard').service('Components', ['lodash', 'ComponentSet', func }; this.forShip = function (shipId) { - var ship = DB.ships[shipId]; + var ship = Ships[shipId]; return new ComponentSet(C, ship.properties.mass, ship.slots.common, ship.slots.internal[0], ship.slots.hardpoints[0]); };