mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 06:43:24 +00:00
Linting fixes
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
angular.module('app', ['ui.router', 'ct.ui.router.extras.sticky', 'ui.sortable', 'shipyard', 'ngLodash', 'app.templates'])
|
angular.module('app', ['ui.router', 'ct.ui.router.extras.sticky', 'ui.sortable', 'shipyard', 'ngLodash', 'app.templates'])
|
||||||
.run(['$rootScope', '$location', '$window', '$document','$state','commonArray','shipPurpose','shipSize','hardPointClass','GroupMap', 'Persist', function ($rootScope, $location, $window, $doc, $state, CArr, shipPurpose, sz, hpc, GroupMap, Persist) {
|
.run(['$rootScope', '$location', '$window', '$document', '$state', 'commonArray', 'shipPurpose', 'shipSize', 'hardPointClass', 'GroupMap', 'Persist',
|
||||||
|
function($rootScope, $location, $window, $doc, $state, CArr, shipPurpose, sz, hpc, GroupMap, Persist) {
|
||||||
// App is running as a standalone web app on tablet/mobile
|
// App is running as a standalone web app on tablet/mobile
|
||||||
var isStandAlone = $window.navigator.standalone || ($window.external && $window.external.msIsSiteMode && $window.external.msIsSiteMode());
|
var isStandAlone = $window.navigator.standalone || ($window.external && $window.external.msIsSiteMode && $window.external.msIsSiteMode());
|
||||||
|
|
||||||
// Redirect any state transition errors to the error controller/state
|
// Redirect any state transition errors to the error controller/state
|
||||||
$rootScope.$on('$stateChangeError', function(e, toState, toParams, fromState, fromParams, error){
|
$rootScope.$on('$stateChangeError', function(e, toState, toParams, fromState, fromParams, error) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
$state.go('error', error, {location:false, reload:true}); // Go to error state, reload the controller, keep the current URL
|
$state.go('error', error, { location: false, reload: true }); // Go to error state, reload the controller, keep the current URL
|
||||||
});
|
});
|
||||||
|
|
||||||
// Track on Google analytics if available
|
// Track on Google analytics if available
|
||||||
@@ -16,12 +17,12 @@ angular.module('app', ['ui.router', 'ct.ui.router.extras.sticky', 'ui.sortable',
|
|||||||
if (to.url) { // Only track states that have a URL
|
if (to.url) { // Only track states that have a URL
|
||||||
|
|
||||||
if ($window.ga) {
|
if ($window.ga) {
|
||||||
ga('send', 'pageview', {page: $location.path()});
|
ga('send', 'pageview', { page: $location.path() });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isStandAlone) {
|
if (isStandAlone) {
|
||||||
// Persist the current state
|
// Persist the current state
|
||||||
Persist.setState({name: to.name, params: toParams});
|
Persist.setState({ name: to.name, params: toParams });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -32,12 +33,12 @@ angular.module('app', ['ui.router', 'ct.ui.router.extras.sticky', 'ui.sortable',
|
|||||||
$rootScope.SZ = sz;
|
$rootScope.SZ = sz;
|
||||||
$rootScope.HPC = hpc;
|
$rootScope.HPC = hpc;
|
||||||
$rootScope.GMAP = GroupMap;
|
$rootScope.GMAP = GroupMap;
|
||||||
$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';
|
||||||
|
|
||||||
$rootScope.cName = function (c) {
|
$rootScope.cName = function(c) {
|
||||||
return c.c? c.c.name? c.c.name : GroupMap[c.c.grp] : null;
|
return c.c ? c.c.name ? c.c.name : GroupMap[c.c.grp] : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Formatters
|
// Formatters
|
||||||
@@ -48,21 +49,21 @@ angular.module('app', ['ui.router', 'ct.ui.router.extras.sticky', 'ui.sortable',
|
|||||||
$rootScope.fPct = d3.format('.2%');
|
$rootScope.fPct = d3.format('.2%');
|
||||||
$rootScope.f1Pct = d3.format('.1%');
|
$rootScope.f1Pct = d3.format('.1%');
|
||||||
$rootScope.fRPct = d3.format('%');
|
$rootScope.fRPct = d3.format('%');
|
||||||
$rootScope.fTime = function(d) { return Math.floor(d/60) + ":" + ("00" + Math.floor(d%60)).substr(-2,2); };
|
$rootScope.fTime = function(d) { return Math.floor(d / 60) + ':' + ('00' + Math.floor(d % 60)).substr(-2, 2); };
|
||||||
|
|
||||||
if (isStandAlone) {
|
if (isStandAlone) {
|
||||||
var state = Persist.getState();
|
var state = Persist.getState();
|
||||||
// If a previous state has been stored, load that state
|
// If a previous state has been stored, load that state
|
||||||
if (state && state.name && state.params) {
|
if (state && state.name && state.params) {
|
||||||
$state.go(state.name, state.params, {location:'replace'});
|
$state.go(state.name, state.params, { location: 'replace' });
|
||||||
} else {
|
} else {
|
||||||
$state.go('shipyard', null, {location:'replace'}); // Default to home page
|
$state.go('shipyard', null, { location: 'replace' }); // Default to home page
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global Event Listeners
|
// Global Event Listeners
|
||||||
$doc.bind('keyup', function (e) {
|
$doc.bind('keyup', function(e) {
|
||||||
if(e.keyCode == 27) { // Escape Key
|
if (e.keyCode == 27) { // Escape Key
|
||||||
$rootScope.$broadcast('close', e);
|
$rootScope.$broadcast('close', e);
|
||||||
$rootScope.$apply();
|
$rootScope.$apply();
|
||||||
} else {
|
} else {
|
||||||
@@ -70,7 +71,7 @@ angular.module('app', ['ui.router', 'ct.ui.router.extras.sticky', 'ui.sortable',
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.bgClicked = function (e) {
|
$rootScope.bgClicked = function(e) {
|
||||||
$rootScope.$broadcast('close', e);
|
$rootScope.$broadcast('close', e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* Sets up the routes and handlers before the Angular app is kicked off.
|
* Sets up the routes and handlers before the Angular app is kicked off.
|
||||||
*/
|
*/
|
||||||
angular.module('app').config(['$provide','$stateProvider', '$urlRouterProvider', '$locationProvider', 'ShipsDB', function ($provide, $stateProvider, $urlRouterProvider, $locationProvider, ships) {
|
angular.module('app').config(['$provide', '$stateProvider', '$urlRouterProvider', '$locationProvider', 'ShipsDB', function($provide, $stateProvider, $urlRouterProvider, $locationProvider, ships) {
|
||||||
// Use HTML5 push and replace state if possible
|
// Use HTML5 push and replace state if possible
|
||||||
$locationProvider.html5Mode({enabled: true, requireBase: false});
|
$locationProvider.html5Mode({ enabled: true, requireBase: false });
|
||||||
/**
|
/**
|
||||||
* Set up all states and their routes.
|
* Set up all states and their routes.
|
||||||
*/
|
*/
|
||||||
@@ -11,13 +11,13 @@ angular.module('app').config(['$provide','$stateProvider', '$urlRouterProvider',
|
|||||||
.state('outfit', {
|
.state('outfit', {
|
||||||
url: '/outfit/:shipId/:code?bn',
|
url: '/outfit/:shipId/:code?bn',
|
||||||
params: {
|
params: {
|
||||||
shipId: { value: 'sidewinder', squash: false}, // Allow 'shipId' parameter to default to sidewinder
|
shipId: { value: 'sidewinder', squash: false }, // Allow 'shipId' parameter to default to sidewinder
|
||||||
code: { value: null, squash: true } // Allow 'code' parameter to be empty/optional
|
code: { value: null, squash: true } // Allow 'code' parameter to be empty/optional
|
||||||
},
|
},
|
||||||
templateUrl: 'views/page-outfit.html',
|
templateUrl: 'views/page-outfit.html',
|
||||||
controller: 'OutfitController',
|
controller: 'OutfitController',
|
||||||
resolve: {
|
resolve: {
|
||||||
shipId: ['$stateParams',function ($p) { // Ensure ship exists before loading controller
|
shipId: ['$stateParams', function($p) { // Ensure ship exists before loading controller
|
||||||
if (!ships[$p.shipId]) {
|
if (!ships[$p.shipId]) {
|
||||||
throw { type: 'no-ship', message: $p.shipId };
|
throw { type: 'no-ship', message: $p.shipId };
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ angular.module('app').config(['$provide','$stateProvider', '$urlRouterProvider',
|
|||||||
.state('compare', {
|
.state('compare', {
|
||||||
url: '/compare/:name',
|
url: '/compare/:name',
|
||||||
params: {
|
params: {
|
||||||
name: {value: null, squash: true }
|
name: { value: null, squash: true }
|
||||||
},
|
},
|
||||||
templateUrl: 'views/page-comparison.html',
|
templateUrl: 'views/page-comparison.html',
|
||||||
controller: 'ComparisonController',
|
controller: 'ComparisonController',
|
||||||
@@ -41,26 +41,26 @@ angular.module('app').config(['$provide','$stateProvider', '$urlRouterProvider',
|
|||||||
sticky: true
|
sticky: true
|
||||||
})
|
})
|
||||||
.state('shipyard', { url: '/', templateUrl: 'views/page-shipyard.html', controller: 'ShipyardController', sticky: true })
|
.state('shipyard', { url: '/', templateUrl: 'views/page-shipyard.html', controller: 'ShipyardController', sticky: true })
|
||||||
.state('error', { params: {type:null, message:null, details: null }, templateUrl: 'views/page-error.html', controller: 'ErrorController', sticky: true })
|
.state('error', { params: { type: null, message: null, details: null }, templateUrl: 'views/page-error.html', controller: 'ErrorController', sticky: true })
|
||||||
|
|
||||||
// Modal States and views
|
// Modal States and views
|
||||||
.state('modal', { abstract: true, views:{ "modal": { templateUrl: "views/_modal.html", controller: 'ModalController' } } })
|
.state('modal', { abstract: true, views: { 'modal': { templateUrl: 'views/_modal.html', controller: 'ModalController' } } })
|
||||||
.state('modal.about', { views: { "modal-content": { templateUrl: "views/modal-about.html" } } })
|
.state('modal.about', { views: { 'modal-content': { templateUrl: 'views/modal-about.html' } } })
|
||||||
.state('modal.export', { params: {title:null, data: null, promise: null}, views: { "modal-content": { templateUrl: "views/modal-export.html", controller: 'ExportController' } } })
|
.state('modal.export', { params: { title: null, data: null, promise: null }, views: { 'modal-content': { templateUrl: 'views/modal-export.html', controller: 'ExportController' } } })
|
||||||
.state('modal.import', { params: {obj:null}, views: { "modal-content": { templateUrl: "views/modal-import.html", controller: 'ImportController' } } })
|
.state('modal.import', { params: { obj: null }, views: { 'modal-content': { templateUrl: 'views/modal-import.html', controller: 'ImportController' } } })
|
||||||
.state('modal.link', { params: {url:null}, views: { "modal-content": { templateUrl: "views/modal-link.html", controller: 'LinkController' } } })
|
.state('modal.link', { params: { url: null }, views: { 'modal-content': { templateUrl: 'views/modal-link.html', controller: 'LinkController' } } })
|
||||||
.state('modal.delete', { views: { "modal-content": { templateUrl: "views/modal-delete.html", controller: 'DeleteController' } } });
|
.state('modal.delete', { views: { 'modal-content': { templateUrl: 'views/modal-delete.html', controller: 'DeleteController' } } });
|
||||||
|
|
||||||
|
|
||||||
// Redirects
|
// Redirects
|
||||||
$urlRouterProvider.when('/outfit','/outfit/sidewinder');
|
$urlRouterProvider.when('/outfit', '/outfit/sidewinder');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 404 Handler - Keep current URL/ do not redirect, change to error state.
|
* 404 Handler - Keep current URL/ do not redirect, change to error state.
|
||||||
*/
|
*/
|
||||||
$urlRouterProvider.otherwise(function ($injector, $location) {
|
$urlRouterProvider.otherwise(function($injector, $location) {
|
||||||
// Go to error state, reload the controller, keep the current URL
|
// Go to error state, reload the controller, keep the current URL
|
||||||
$injector.get('$state').go('error', { type: 404, message: null, details: null }, {location:false, reload:true});
|
$injector.get('$state').go('error', { type: 404, message: null, details: null }, { location: false, reload: true });
|
||||||
return $location.path;
|
return $location.path;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -69,10 +69,10 @@ angular.module('app').config(['$provide','$stateProvider', '$urlRouterProvider',
|
|||||||
* redirects uncaught errors to the error page.
|
* redirects uncaught errors to the error page.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$provide.decorator('$exceptionHandler', ['$delegate', '$injector', function ($delegate, $injector) {
|
$provide.decorator('$exceptionHandler', ['$delegate', '$injector', function($delegate, $injector) {
|
||||||
return function(err, cause) {
|
return function(err, cause) {
|
||||||
// Go to error state, reload the controller, keep the current URL
|
// Go to error state, reload the controller, keep the current URL
|
||||||
$injector.get('$state').go('error', {type:null, message: err.message, details: err.stack }, {location:false, reload:true});
|
$injector.get('$state').go('error', { type: null, message: err.message, details: err.stack }, { location: false, reload: true });
|
||||||
$delegate(err, cause);
|
$delegate(err, cause);
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,48 +1,49 @@
|
|||||||
angular.module('app').controller('ComparisonController', ['lodash', '$rootScope', '$filter', '$scope', '$state', '$stateParams', 'Utils', 'ShipFacets', 'ShipsDB', 'Ship', 'Persist', 'Serializer', function (_, $rootScope, $filter, $scope, $state, $stateParams, Utils, ShipFacets, Ships, Ship, Persist, Serializer) {
|
angular.module('app').controller('ComparisonController', ['lodash', '$rootScope', '$filter', '$scope', '$state', '$stateParams', 'Utils', 'ShipFacets', 'ShipsDB', 'Ship', 'Persist', 'Serializer', function(_, $rootScope, $filter, $scope, $state, $stateParams, Utils, ShipFacets, Ships, Ship, Persist, Serializer) {
|
||||||
$rootScope.title = 'Coriolis - Compare';
|
$rootScope.title = 'Coriolis - Compare';
|
||||||
$scope.predicate = 'name'; // Sort by ship name as default
|
$scope.predicate = 'name'; // Sort by ship name as default
|
||||||
$scope.desc = false;
|
$scope.desc = false;
|
||||||
$scope.facetSortOpts = { containment: '#facet-container', orderChanged: function () { $scope.saved = false; } };
|
$scope.facetSortOpts = { containment: '#facet-container', orderChanged: function() { $scope.saved = false; } };
|
||||||
$scope.builds = [];
|
$scope.builds = [];
|
||||||
$scope.unusedBuilds = [];
|
$scope.unusedBuilds = [];
|
||||||
$scope.name = $stateParams.name;
|
$scope.name = $stateParams.name;
|
||||||
$scope.compareMode = !$stateParams.code;
|
$scope.compareMode = !$stateParams.code;
|
||||||
$scope.importObj = {}; // Used for importing comparison builds (from permalinked comparison)
|
$scope.importObj = {}; // Used for importing comparison builds (from permalinked comparison)
|
||||||
var defaultFacets = [9,6,4,1,3,2]; // Reverse order of Armour, Shields, Speed, Jump Range, Cargo Capacity, Cost
|
var defaultFacets = [9, 6, 4, 1, 3, 2]; // Reverse order of Armour, Shields, Speed, Jump Range, Cargo Capacity, Cost
|
||||||
var facets = $scope.facets = angular.copy(ShipFacets);
|
var facets = $scope.facets = angular.copy(ShipFacets);
|
||||||
|
var shipId, buildName, comparisonData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an existing build to the comparison. The build must be saved locally.
|
* Add an existing build to the comparison. The build must be saved locally.
|
||||||
* @param {string} shipId The unique ship key/id
|
* @param {string} id The unique ship key/id
|
||||||
* @param {string} buildName The build name
|
* @param {string} name The build name
|
||||||
*/
|
*/
|
||||||
$scope.addBuild = function (shipId, buildName, code) {
|
$scope.addBuild = function(id, name, code) {
|
||||||
var data = Ships[shipId]; // Get ship properties
|
var data = Ships[id]; // Get ship properties
|
||||||
code = code? code : Persist.builds[shipId][buildName]; // Retrieve build code if not passed
|
code = code ? code : Persist.builds[id][name]; // Retrieve build code if not passed
|
||||||
var b = new Ship(shipId, data.properties, data.slots); // Create a new Ship instance
|
var b = new Ship(id, data.properties, data.slots); // Create a new Ship instance
|
||||||
Serializer.toShip(b, code); // Populate components from code
|
Serializer.toShip(b, code); // Populate components from code
|
||||||
// Extend ship instance and add properties below
|
// Extend ship instance and add properties below
|
||||||
b.buildName = buildName;
|
b.buildName = name;
|
||||||
b.code = code;
|
b.code = code;
|
||||||
b.pctRetracted = b.powerRetracted / b.powerAvailable;
|
b.pctRetracted = b.powerRetracted / b.powerAvailable;
|
||||||
b.pctDeployed = b.powerDeployed / b.powerAvailable;
|
b.pctDeployed = b.powerDeployed / b.powerAvailable;
|
||||||
$scope.builds.push(b); // Add ship build to comparison
|
$scope.builds.push(b); // Add ship build to comparison
|
||||||
$scope.builds = $filter('orderBy')($scope.builds, $scope.predicate, $scope.desc); // Resort
|
$scope.builds = $filter('orderBy')($scope.builds, $scope.predicate, $scope.desc); // Resort
|
||||||
_.remove($scope.unusedBuilds, function (b) { // Remove from unused builds
|
_.remove($scope.unusedBuilds, function(o) { // Remove from unused builds
|
||||||
return b.id == shipId && b.buildName == buildName;
|
return o.id == id && o.buildName == name;
|
||||||
});
|
});
|
||||||
$scope.saved = false;
|
$scope.saved = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a build from the comparison
|
* Removes a build from the comparison
|
||||||
* @param {string} shipId The unique ship key/id
|
* @param {string} id The unique ship key/id
|
||||||
* @param {string} buildName The build name
|
* @param {string} name The build name
|
||||||
*/
|
*/
|
||||||
$scope.removeBuild = function (shipId, buildName) {
|
$scope.removeBuild = function(id, name) {
|
||||||
_.remove($scope.builds, function (b) {
|
_.remove($scope.builds, function(s) {
|
||||||
if (b.id == shipId && b.buildName == buildName) {
|
if (s.id == id && s.buildName == name) {
|
||||||
$scope.unusedBuilds.push({id: shipId, buildName: buildName, name: b.name}); // Add build back to unused builds
|
$scope.unusedBuilds.push({ id: id, buildName: name, name: s.name }); // Add build back to unused builds
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -54,7 +55,7 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
* Toggles the selected the set of facets used in the comparison
|
* Toggles the selected the set of facets used in the comparison
|
||||||
* @param {number} i The index of the facet in facets
|
* @param {number} i The index of the facet in facets
|
||||||
*/
|
*/
|
||||||
$scope.toggleFacet = function (i) {
|
$scope.toggleFacet = function(i) {
|
||||||
facets[i].active = !facets[i].active;
|
facets[i].active = !facets[i].active;
|
||||||
$scope.tblUpdate = !$scope.tblUpdate; // Simple switch to trigger the table to update
|
$scope.tblUpdate = !$scope.tblUpdate; // Simple switch to trigger the table to update
|
||||||
$scope.saved = false;
|
$scope.saved = false;
|
||||||
@@ -64,12 +65,12 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
* Click handler for sorting by facets in the table
|
* Click handler for sorting by facets in the table
|
||||||
* @param {object} e Event object
|
* @param {object} e Event object
|
||||||
*/
|
*/
|
||||||
$scope.handleClick = function (e) {
|
$scope.handleClick = function(e) {
|
||||||
var elem = angular.element(e.target);
|
var elem = angular.element(e.target);
|
||||||
if(elem.attr('prop')) { // Get component ID
|
if (elem.attr('prop')) { // Get component ID
|
||||||
$scope.sort(elem.attr('prop'));
|
$scope.sort(elem.attr('prop'));
|
||||||
}
|
|
||||||
else if (elem.attr('del')) { // Delete index
|
} else if (elem.attr('del')) { // Delete index
|
||||||
$scope.removeBuild(elem.attr('del'));
|
$scope.removeBuild(elem.attr('del'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -78,8 +79,8 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
* Sort the comparison array based on the selected facet / ship property
|
* Sort the comparison array based on the selected facet / ship property
|
||||||
* @param {string} key Ship property
|
* @param {string} key Ship property
|
||||||
*/
|
*/
|
||||||
$scope.sort = function (key) {
|
$scope.sort = function(key) {
|
||||||
$scope.desc = ($scope.predicate == key)? !$scope.desc : $scope.desc;
|
$scope.desc = $scope.predicate == key ? !$scope.desc : $scope.desc;
|
||||||
$scope.predicate = key;
|
$scope.predicate = key;
|
||||||
$scope.builds = $filter('orderBy')($scope.builds, $scope.predicate, $scope.desc);
|
$scope.builds = $filter('orderBy')($scope.builds, $scope.predicate, $scope.desc);
|
||||||
};
|
};
|
||||||
@@ -94,12 +95,12 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
}
|
}
|
||||||
var selectedFacets = [];
|
var selectedFacets = [];
|
||||||
facets.forEach(function(f) {
|
facets.forEach(function(f) {
|
||||||
if(f.active) {
|
if (f.active) {
|
||||||
selectedFacets.unshift(f.index);
|
selectedFacets.unshift(f.index);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Persist.saveComparison($scope.name, $scope.builds, selectedFacets);
|
Persist.saveComparison($scope.name, $scope.builds, selectedFacets);
|
||||||
$state.go('compare', {name: $scope.name}, {location:'replace', notify:false});
|
$state.go('compare', { name: $scope.name }, { location: 'replace', notify: false });
|
||||||
$scope.saved = true;
|
$scope.saved = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -108,7 +109,7 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
*/
|
*/
|
||||||
$scope.delete = function() {
|
$scope.delete = function() {
|
||||||
Persist.deleteComparison($scope.name);
|
Persist.deleteComparison($scope.name);
|
||||||
$state.go('compare', {name: null}, {location:'replace', reload:true});
|
$state.go('compare', { name: null }, { location: 'replace', reload: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,7 +135,7 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
*/
|
*/
|
||||||
$scope.permalink = function(e) {
|
$scope.permalink = function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
$state.go('modal.link', {url: genPermalink()});
|
$state.go('modal.link', { url: genPermalink() });
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,14 +148,14 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
// Make a request to goo.gl to shorten the URL, returns a promise
|
// Make a request to goo.gl to shorten the URL, returns a promise
|
||||||
var promise = Utils.shortenUrl( genPermalink()).then(
|
var promise = Utils.shortenUrl( genPermalink()).then(
|
||||||
function (shortUrl) {
|
function(shortUrl) {
|
||||||
return Utils.comparisonBBCode(facets, $scope.builds, shortUrl);
|
return Utils.comparisonBBCode(facets, $scope.builds, shortUrl);
|
||||||
},
|
},
|
||||||
function (e) {
|
function(err) {
|
||||||
return 'Error - ' + e.statusText;
|
return 'Error - ' + err.statusText;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$state.go('modal.export', {promise: promise, title:'Forum BBCode'});
|
$state.go('modal.export', { promise: promise, title: 'Forum BBCode' });
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,7 +165,7 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
function genPermalink() {
|
function genPermalink() {
|
||||||
var selectedFacets = [];
|
var selectedFacets = [];
|
||||||
facets.forEach(function(f) {
|
facets.forEach(function(f) {
|
||||||
if(f.active) {
|
if (f.active) {
|
||||||
selectedFacets.unshift(f.index);
|
selectedFacets.unshift(f.index);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -175,7 +176,7 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
$scope.predicate,
|
$scope.predicate,
|
||||||
$scope.desc
|
$scope.desc
|
||||||
);
|
);
|
||||||
return $state.href('comparison', {code: code}, {absolute:true});
|
return $state.href('comparison', { code: code }, { absolute: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Event listeners */
|
/* Event listeners */
|
||||||
@@ -184,7 +185,6 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* Initialization */
|
/* Initialization */
|
||||||
var shipId, buildName, comparisonData;
|
|
||||||
if ($scope.compareMode) {
|
if ($scope.compareMode) {
|
||||||
if ($scope.name == 'all') {
|
if ($scope.name == 'all') {
|
||||||
for (shipId in Persist.builds) {
|
for (shipId in Persist.builds) {
|
||||||
@@ -195,13 +195,13 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
} else {
|
} else {
|
||||||
for (shipId in Persist.builds) {
|
for (shipId in Persist.builds) {
|
||||||
for (buildName in Persist.builds[shipId]) {
|
for (buildName in Persist.builds[shipId]) {
|
||||||
$scope.unusedBuilds.push({id: shipId, buildName: buildName, name: Ships[shipId].properties.name});
|
$scope.unusedBuilds.push({ id: shipId, buildName: buildName, name: Ships[shipId].properties.name });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
comparisonData = Persist.getComparison($scope.name);
|
comparisonData = Persist.getComparison($scope.name);
|
||||||
if (comparisonData) {
|
if (comparisonData) {
|
||||||
defaultFacets = comparisonData.facets;
|
defaultFacets = comparisonData.facets;
|
||||||
comparisonData.builds.forEach(function (b) {
|
comparisonData.builds.forEach(function(b) {
|
||||||
$scope.addBuild(b.shipId, b.buildName);
|
$scope.addBuild(b.shipId, b.buildName);
|
||||||
});
|
});
|
||||||
$scope.saved = true;
|
$scope.saved = true;
|
||||||
@@ -214,9 +214,9 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
$scope.name = comparisonData.n;
|
$scope.name = comparisonData.n;
|
||||||
$scope.predicate = comparisonData.p;
|
$scope.predicate = comparisonData.p;
|
||||||
$scope.desc = comparisonData.d;
|
$scope.desc = comparisonData.d;
|
||||||
comparisonData.b.forEach(function (build) {
|
comparisonData.b.forEach(function(build) {
|
||||||
$scope.addBuild(build.s, build.n, build.c);
|
$scope.addBuild(build.s, build.n, build.c);
|
||||||
if(!$scope.importObj[build.s]) {
|
if (!$scope.importObj[build.s]) {
|
||||||
$scope.importObj[build.s] = {};
|
$scope.importObj[build.s] = {};
|
||||||
}
|
}
|
||||||
$scope.importObj[build.s][build.n] = build.c;
|
$scope.importObj[build.s][build.n] = build.c;
|
||||||
@@ -226,9 +226,9 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Replace fmt with actual format function as defined in rootScope and retain original index
|
// Replace fmt with actual format function as defined in rootScope and retain original index
|
||||||
facets.forEach(function(f,i) { f.fmt = $rootScope[f.fmt]; f.index = i; });
|
facets.forEach(function(f, i) { f.fmt = $rootScope[f.fmt]; f.index = i; });
|
||||||
// Remove default facets, mark as active, and add them back in selected order
|
// Remove default facets, mark as active, and add them back in selected order
|
||||||
_.pullAt(facets, defaultFacets).forEach(function (f) { f.active = true; facets.unshift(f); });
|
_.pullAt(facets, defaultFacets).forEach(function(f) { f.active = true; facets.unshift(f); });
|
||||||
$scope.builds = $filter('orderBy')($scope.builds, $scope.predicate, $scope.desc);
|
$scope.builds = $filter('orderBy')($scope.builds, $scope.predicate, $scope.desc);
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
angular.module('app').controller('DeleteController', ['$scope', 'Persist', function ($scope, Persist) {
|
angular.module('app').controller('DeleteController', ['$scope', 'Persist', function($scope, Persist) {
|
||||||
$scope.deleteAll = function () {
|
$scope.deleteAll = function() {
|
||||||
Persist.deleteAll();
|
Persist.deleteAll();
|
||||||
$scope.$parent.dismiss();
|
$scope.$parent.dismiss();
|
||||||
};
|
};
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
angular.module('app')
|
angular.module('app')
|
||||||
.controller('ErrorController', ['$window','$rootScope','$scope','$stateParams', '$location', function ($window, $rootScope, $scope, $p, $location) {
|
.controller('ErrorController', ['$window', '$rootScope', '$scope', '$stateParams', '$location', function($window, $rootScope, $scope, $p, $location) {
|
||||||
$rootScope.title = 'Error';
|
$rootScope.title = 'Error';
|
||||||
$scope.path = $location.path();
|
$scope.path = $location.path();
|
||||||
$scope.type = $p.type || 'unknown';
|
$scope.type = $p.type || 'unknown';
|
||||||
@@ -21,9 +21,9 @@ angular.module('app')
|
|||||||
$scope.details = $p.details;
|
$scope.details = $p.details;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$scope.msgPre = "Uh, Jameson, we have a problem..";
|
$scope.msgPre = 'Uh, Jameson, we have a problem..';
|
||||||
$scope.errorMessage = $p.message;
|
$scope.errorMessage = $p.message;
|
||||||
$scope.details = $p.details;
|
$scope.details = $p.details;
|
||||||
}
|
}
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
angular.module('app').controller('ExportController', ['$scope', '$stateParams', function ($scope, $stateParams) {
|
angular.module('app').controller('ExportController', ['$scope', '$stateParams', function($scope, $stateParams) {
|
||||||
|
|
||||||
$scope.title = $stateParams.title || 'Export';
|
$scope.title = $stateParams.title || 'Export';
|
||||||
|
|
||||||
if ($stateParams.promise) {
|
if ($stateParams.promise) {
|
||||||
$scope.export = 'Generating...';
|
$scope.export = 'Generating...';
|
||||||
$stateParams.promise.then(function(data){
|
$stateParams.promise.then(function(data) {
|
||||||
$scope.export = data;
|
$scope.export = data;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$scope.export = angular.toJson($stateParams.data, true);
|
$scope.export = angular.toJson($stateParams.data, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.onTextClick = function ($event) {
|
$scope.onTextClick = function($event) {
|
||||||
$event.target.select();
|
$event.target.select();
|
||||||
};
|
};
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
angular.module('app').controller('ImportController', ['$scope', '$stateParams', 'ShipsDB', 'Ship', 'Persist', 'Serializer', function ($scope, $stateParams, Ships, Ship, Persist, Serializer) {
|
angular.module('app').controller('ImportController', ['$scope', '$stateParams', 'ShipsDB', 'Ship', 'Persist', 'Serializer', function($scope, $stateParams, Ships, Ship, Persist, Serializer) {
|
||||||
$scope.jsonValid = false;
|
$scope.jsonValid = false;
|
||||||
$scope.importData = null;
|
$scope.importData = null;
|
||||||
$scope.errorMsg = null;
|
$scope.errorMsg = null;
|
||||||
@@ -21,7 +21,7 @@ angular.module('app').controller('ImportController', ['$scope', '$stateParams',
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof importObj != 'object') {
|
if (typeof importObj != 'object') {
|
||||||
$scope.errorMsg = 'Must be an object!';
|
$scope.errorMsg = 'Must be an object!';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ angular.module('app').controller('ImportController', ['$scope', '$stateParams',
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$scope.errorMsg = '"' + shipId + '" is not a valid Ship Id!';
|
$scope.errorMsg = '"' + shipId + '"" is not a valid Ship Id!';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$scope.builds = importObj.builds;
|
$scope.builds = importObj.builds;
|
||||||
@@ -57,7 +57,7 @@ angular.module('app').controller('ImportController', ['$scope', '$stateParams',
|
|||||||
$scope.jsonValid = true;
|
$scope.jsonValid = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.hasBuild = function (shipId, name) {
|
$scope.hasBuild = function(shipId, name) {
|
||||||
return Persist.getBuild(shipId, name) !== null;
|
return Persist.getBuild(shipId, name) !== null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -98,4 +98,4 @@ angular.module('app').controller('ImportController', ['$scope', '$stateParams',
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
angular.module('app').controller('LinkController', ['$scope', 'Utils', '$stateParams', function ($scope, Utils, $stateParams) {
|
angular.module('app').controller('LinkController', ['$scope', 'Utils', '$stateParams', function($scope, Utils, $stateParams) {
|
||||||
$scope.url = $stateParams.url;
|
$scope.url = $stateParams.url;
|
||||||
$scope.shortenedUrl = 'Shortening...';
|
$scope.shortenedUrl = 'Shortening...';
|
||||||
|
|
||||||
$scope.onTextClick = function ($event) {
|
$scope.onTextClick = function($event) {
|
||||||
$event.target.select();
|
$event.target.select();
|
||||||
};
|
};
|
||||||
|
|
||||||
Utils.shortenUrl($scope.url)
|
Utils.shortenUrl($scope.url)
|
||||||
.then(function(url) {
|
.then(function(url) {
|
||||||
$scope.shortenedUrl = url;
|
$scope.shortenedUrl = url;
|
||||||
},function(e) {
|
}, function(e) {
|
||||||
$scope.shortenedUrl = 'Error - ' + e.statusText;
|
$scope.shortenedUrl = 'Error - ' + e.statusText;
|
||||||
});
|
});
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
angular.module('app').controller('ModalController', ['$rootScope','$scope', '$state', function ($rootScope, $scope, $state) {
|
angular.module('app').controller('ModalController', ['$rootScope', '$scope', '$state', function($rootScope, $scope, $state) {
|
||||||
|
|
||||||
$scope.dismiss = function() {
|
$scope.dismiss = function() {
|
||||||
if ($rootScope.prevState) {
|
if ($rootScope.prevState) {
|
||||||
var state = $rootScope.prevState;
|
var state = $rootScope.prevState;
|
||||||
$state.go(state.name, state.params, {location: 'replace', reload: false});
|
$state.go(state.name, state.params, { location: 'replace', reload: false });
|
||||||
} else {
|
} else {
|
||||||
$state.go('shipyard');
|
$state.go('shipyard');
|
||||||
}
|
}
|
||||||
@@ -11,4 +11,4 @@ angular.module('app').controller('ModalController', ['$rootScope','$scope', '$st
|
|||||||
|
|
||||||
$scope.$on('close', $scope.dismiss);
|
$scope.$on('close', $scope.dismiss);
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
angular.module('app').controller('OutfitController', ['$window','$rootScope','$scope', '$state', '$stateParams', 'ShipsDB', 'Ship', 'Components', 'Serializer', 'Persist', function ($window, $rootScope, $scope, $state, $p, Ships, Ship, Components, Serializer, Persist) {
|
angular.module('app').controller('OutfitController', ['$window', '$rootScope', '$scope', '$state', '$stateParams', 'ShipsDB', 'Ship', 'Components', 'Serializer', 'Persist', function($window, $rootScope, $scope, $state, $p, Ships, Ship, Components, Serializer, Persist) {
|
||||||
var data = Ships[$p.shipId]; // Retrieve the basic ship properties, slots and defaults
|
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
|
var ship = new Ship($p.shipId, data.properties, data.slots); // Create a new Ship instance
|
||||||
var win = angular.element($window); // Angularized window object for event triggering
|
var win = angular.element($window); // Angularized window object for event triggering
|
||||||
@@ -12,7 +12,7 @@ angular.module('app').controller('OutfitController', ['$window','$rootScope','$s
|
|||||||
}
|
}
|
||||||
|
|
||||||
$scope.buildName = $p.bn;
|
$scope.buildName = $p.bn;
|
||||||
$rootScope.title = ship.name + ($scope.buildName? ' - ' + $scope.buildName : '');
|
$rootScope.title = ship.name + ($scope.buildName ? ' - ' + $scope.buildName : '');
|
||||||
$scope.ship = ship;
|
$scope.ship = ship;
|
||||||
$scope.pp = ship.common[0]; // Power Plant
|
$scope.pp = ship.common[0]; // Power Plant
|
||||||
$scope.th = ship.common[1]; // Thruster
|
$scope.th = ship.common[1]; // Thruster
|
||||||
@@ -49,11 +49,11 @@ angular.module('app').controller('OutfitController', ['$window','$rootScope','$s
|
|||||||
$scope.jrChart = {
|
$scope.jrChart = {
|
||||||
labels: {
|
labels: {
|
||||||
xAxis: {
|
xAxis: {
|
||||||
title:'Cargo',
|
title: 'Cargo',
|
||||||
unit: 'T'
|
unit: 'T'
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
title:'Jump Range',
|
title: 'Jump Range',
|
||||||
unit: 'LY'
|
unit: 'LY'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -90,7 +90,7 @@ angular.module('app').controller('OutfitController', ['$window','$rootScope','$s
|
|||||||
if (id) {
|
if (id) {
|
||||||
if (id == 'empty') {
|
if (id == 'empty') {
|
||||||
ship.use(slot, null, null);
|
ship.use(slot, null, null);
|
||||||
} else if(type == 'h') {
|
} else if (type == 'h') {
|
||||||
ship.use(slot, id, Components.hardpoints(id));
|
ship.use(slot, id, Components.hardpoints(id));
|
||||||
} else if (type == 'c') {
|
} else if (type == 'c') {
|
||||||
ship.use(slot, id, Components.common(ship.common.indexOf(slot), id));
|
ship.use(slot, id, Components.common(ship.common.indexOf(slot), id));
|
||||||
@@ -142,13 +142,13 @@ angular.module('app').controller('OutfitController', ['$window','$rootScope','$s
|
|||||||
*/
|
*/
|
||||||
$scope.deleteBuild = function() {
|
$scope.deleteBuild = function() {
|
||||||
Persist.deleteBuild(ship.id, $scope.buildName);
|
Persist.deleteBuild(ship.id, $scope.buildName);
|
||||||
$state.go('outfit', {shipId: ship.id, code: null, bn: null}, {location:'replace', reload:true});
|
$state.go('outfit', { shipId: ship.id, code: null, bn: null }, { location: 'replace', reload: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On build name change, retrieve the existing saved code if there is one
|
* On build name change, retrieve the existing saved code if there is one
|
||||||
*/
|
*/
|
||||||
$scope.bnChange = function(){
|
$scope.bnChange = function() {
|
||||||
$scope.savedCode = Persist.getBuild(ship.id, $scope.buildName);
|
$scope.savedCode = Persist.getBuild(ship.id, $scope.buildName);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -165,13 +165,13 @@ angular.module('app').controller('OutfitController', ['$window','$rootScope','$s
|
|||||||
* @param {[type]} key [description]
|
* @param {[type]} key [description]
|
||||||
* @return {[type]} [description]
|
* @return {[type]} [description]
|
||||||
*/
|
*/
|
||||||
$scope.sortCost = function (key) {
|
$scope.sortCost = function(key) {
|
||||||
$scope.costDesc = ($scope.costPredicate == key)? !$scope.costDesc : $scope.costDesc;
|
$scope.costDesc = $scope.costPredicate == key ? !$scope.costDesc : $scope.costDesc;
|
||||||
$scope.costPredicate = key;
|
$scope.costPredicate = key;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.sortPwr = function (key) {
|
$scope.sortPwr = function(key) {
|
||||||
$scope.pwrDesc = ($scope.pwrPredicate == key)? !$scope.pwrDesc : $scope.pwrDesc;
|
$scope.pwrDesc = $scope.pwrPredicate == key ? !$scope.pwrDesc : $scope.pwrDesc;
|
||||||
$scope.pwrPredicate = key;
|
$scope.pwrPredicate = key;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -185,37 +185,37 @@ angular.module('app').controller('OutfitController', ['$window','$rootScope','$s
|
|||||||
updateState();
|
updateState();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.incPriority = function (c) {
|
$scope.incPriority = function(c) {
|
||||||
if (ship.changePriority(c, c.priority + 1)) {
|
if (ship.changePriority(c, c.priority + 1)) {
|
||||||
$scope.code = Serializer.fromShip(ship);
|
$scope.code = Serializer.fromShip(ship);
|
||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.decPriority = function (c) {
|
$scope.decPriority = function(c) {
|
||||||
if (ship.changePriority(c, c.priority - 1)) {
|
if (ship.changePriority(c, c.priority - 1)) {
|
||||||
$scope.code = Serializer.fromShip(ship);
|
$scope.code = Serializer.fromShip(ship);
|
||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.fuelChange = function (fuel) {
|
$scope.fuelChange = function(fuel) {
|
||||||
$scope.fuel = fuel;
|
$scope.fuel = fuel;
|
||||||
win.triggerHandler('render');
|
win.triggerHandler('render');
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.statusRetracted = function (slot) {
|
$scope.statusRetracted = function(slot) {
|
||||||
return ship.getSlotStatus(slot, false);
|
return ship.getSlotStatus(slot, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.statusDeployed = function (slot) {
|
$scope.statusDeployed = function(slot) {
|
||||||
return ship.getSlotStatus(slot, true);
|
return ship.getSlotStatus(slot, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Utilify functions
|
// Utilify functions
|
||||||
|
|
||||||
function updateState() {
|
function updateState() {
|
||||||
$state.go('outfit', {shipId: ship.id, code: $scope.code, bn: $scope.buildName}, {location:'replace', notify:false});
|
$state.go('outfit', { shipId: ship.id, code: $scope.code, bn: $scope.buildName }, { location: 'replace', notify: false });
|
||||||
$scope.jrSeries.xMax = ship.cargoCapacity;
|
$scope.jrSeries.xMax = ship.cargoCapacity;
|
||||||
$scope.jrSeries.yMax = ship.jumpRangeWithMass(ship.unladenMass);
|
$scope.jrSeries.yMax = ship.jumpRangeWithMass(ship.unladenMass);
|
||||||
$scope.jrSeries.mass = ship.unladenMass;
|
$scope.jrSeries.mass = ship.unladenMass;
|
||||||
@@ -223,7 +223,7 @@ angular.module('app').controller('OutfitController', ['$window','$rootScope','$s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hide any open menu/slot/etc if the background is clicked
|
// Hide any open menu/slot/etc if the background is clicked
|
||||||
$scope.$on('close', function () {
|
$scope.$on('close', function() {
|
||||||
$scope.selectedSlot = null;
|
$scope.selectedSlot = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
angular.module('app').controller('ShipyardController', ['$rootScope', 'ShipsDB', function ($rootScope, ships) {
|
angular.module('app').controller('ShipyardController', ['$rootScope', 'ShipsDB', function($rootScope, ships) {
|
||||||
$rootScope.title = 'Coriolis';
|
$rootScope.title = 'Coriolis';
|
||||||
$rootScope.ships = ships;
|
$rootScope.ships = ships;
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
angular.module('app').directive('areaChart', ['$window', function ($window) {
|
angular.module('app').directive('areaChart', ['$window', function($window) {
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
scope:{
|
scope: {
|
||||||
config: '=',
|
config: '=',
|
||||||
series: '='
|
series: '='
|
||||||
},
|
},
|
||||||
@@ -11,64 +9,64 @@ angular.module('app').directive('areaChart', ['$window', function ($window) {
|
|||||||
var series = scope.series,
|
var series = scope.series,
|
||||||
config = scope.config,
|
config = scope.config,
|
||||||
labels = config.labels,
|
labels = config.labels,
|
||||||
margin = {top: 15, right: 15, bottom: 35, left: 60},
|
margin = { top: 15, right: 15, bottom: 35, left: 60 },
|
||||||
fmt = d3.format('.3r'),
|
fmt = d3.format('.3r'),
|
||||||
fmtLong = d3.format('.2f'),
|
fmtLong = d3.format('.2f'),
|
||||||
func = series.func,
|
func = series.func,
|
||||||
drag = d3.behavior.drag(),
|
drag = d3.behavior.drag(),
|
||||||
dragging = false,
|
dragging = false,
|
||||||
// Define Axes
|
// Define Axes
|
||||||
xAxis = d3.svg.axis().outerTickSize(0).orient("bottom").tickFormat(d3.format('.2r')),
|
xAxis = d3.svg.axis().outerTickSize(0).orient('bottom').tickFormat(d3.format('.2r')),
|
||||||
yAxis = d3.svg.axis().ticks(6).outerTickSize(0).orient("left").tickFormat(fmt),
|
yAxis = d3.svg.axis().ticks(6).outerTickSize(0).orient('left').tickFormat(fmt),
|
||||||
x = d3.scale.linear(),
|
x = d3.scale.linear(),
|
||||||
y = d3.scale.linear();
|
y = d3.scale.linear();
|
||||||
|
|
||||||
// Create chart
|
// Create chart
|
||||||
var svg = d3.select(element[0]).append("svg");
|
var svg = d3.select(element[0]).append('svg');
|
||||||
var vis = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
var vis = svg.append('g').attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
||||||
|
|
||||||
// Define Area
|
// Define Area
|
||||||
var area = d3.svg.area();
|
var area = d3.svg.area();
|
||||||
|
|
||||||
var gradient = vis.append("defs")
|
var gradient = vis.append('defs')
|
||||||
.append("linearGradient")
|
.append('linearGradient')
|
||||||
.attr("id", "gradient")
|
.attr('id', 'gradient')
|
||||||
.attr("x1", "0%").attr("y1", "0%")
|
.attr('x1', '0%').attr('y1', '0%')
|
||||||
.attr("x2", "100%").attr("y2", "100%")
|
.attr('x2', '100%').attr('y2', '100%')
|
||||||
.attr("spreadMethod", "pad");
|
.attr('spreadMethod', 'pad');
|
||||||
gradient.append("stop")
|
gradient.append('stop')
|
||||||
.attr("offset", "0%")
|
.attr('offset', '0%')
|
||||||
.attr("stop-color", "#ff8c0d")
|
.attr('stop-color', '#ff8c0d')
|
||||||
.attr("stop-opacity", 1);
|
.attr('stop-opacity', 1);
|
||||||
gradient.append("stop")
|
gradient.append('stop')
|
||||||
.attr("offset", "100%")
|
.attr('offset', '100%')
|
||||||
.attr("stop-color", "#ff3b00")
|
.attr('stop-color', '#ff3b00')
|
||||||
.attr("stop-opacity", 1);
|
.attr('stop-opacity', 1);
|
||||||
|
|
||||||
// Create Y Axis SVG Elements
|
// Create Y Axis SVG Elements
|
||||||
var yTxt = vis.append("g").attr("class", "y axis")
|
var yTxt = vis.append('g').attr('class', 'y axis')
|
||||||
.append("text")
|
.append('text')
|
||||||
.attr("transform", "rotate(-90)")
|
.attr('transform', 'rotate(-90)')
|
||||||
.attr("y", -50)
|
.attr('y', -50)
|
||||||
.attr("dy", ".1em")
|
.attr('dy', '.1em')
|
||||||
.style("text-anchor", "middle")
|
.style('text-anchor', 'middle')
|
||||||
.text(labels.yAxis.title + ' (' + labels.yAxis.unit + ')');
|
.text(labels.yAxis.title + ' (' + labels.yAxis.unit + ')');
|
||||||
// Create X Axis SVG Elements
|
// Create X Axis SVG Elements
|
||||||
var xLbl = vis.append("g").attr("class", "x axis");
|
var xLbl = vis.append('g').attr('class', 'x axis');
|
||||||
var xTxt = xLbl.append("text")
|
var xTxt = xLbl.append('text')
|
||||||
.attr("y", 30)
|
.attr('y', 30)
|
||||||
.attr("dy", ".1em")
|
.attr('dy', '.1em')
|
||||||
.style("text-anchor", "middle")
|
.style('text-anchor', 'middle')
|
||||||
.text(labels.xAxis.title + ' (' + labels.xAxis.unit + ')');
|
.text(labels.xAxis.title + ' (' + labels.xAxis.unit + ')');
|
||||||
|
|
||||||
// Create and Add tooltip
|
// Create and Add tooltip
|
||||||
var tip = vis.append("g").style("display", "none");
|
var tip = vis.append('g').style('display', 'none');
|
||||||
tip.append("rect").attr("width","4em").attr("height", "2em").attr("x", "0.5em").attr("y","-1em").attr("class","tip");
|
tip.append('rect').attr('width', '4em').attr('height', '2em').attr('x', '0.5em').attr('y', '-1em').attr('class', 'tip');
|
||||||
tip.append("circle")
|
tip.append('circle')
|
||||||
.attr("class", "marker")
|
.attr('class', 'marker')
|
||||||
.attr("r", 4);
|
.attr('r', 4);
|
||||||
tip.append("text").attr("class", 'label x').attr("y", "-0.25em");
|
tip.append('text').attr('class', 'label x').attr('y', '-0.25em');
|
||||||
tip.append("text").attr("class", 'label y').attr("y", '0.85em');
|
tip.append('text').attr('class', 'label y').attr('y', '0.85em');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch for changes in the series data (mass changes, etc)
|
* Watch for changes in the series data (mass changes, etc)
|
||||||
@@ -87,35 +85,35 @@ angular.module('app').directive('areaChart', ['$window', function ($window) {
|
|||||||
var yVal = func(series.xMin);
|
var yVal = func(series.xMin);
|
||||||
data.push([ series.xMin, yVal ]);
|
data.push([ series.xMin, yVal ]);
|
||||||
data.push([ series.xMin, yVal ]);
|
data.push([ series.xMin, yVal ]);
|
||||||
area.x(function(d,i) { return i * w; }).y0(h).y1(function(d) { return y(d[1]); });
|
area.x(function(d, i) { return i * w; }).y0(h).y1(function(d) { return y(d[1]); });
|
||||||
} else {
|
} else {
|
||||||
for (var d = series.xMin; d <= series.xMax; d += 1) {
|
for (var val = series.xMin; val <= series.xMax; val += 1) {
|
||||||
data.push([ d, func(d) ]);
|
data.push([ val, func(val) ]);
|
||||||
}
|
}
|
||||||
area.x(function(d) { return x(d[0]); }).y0(h).y1(function(d) { return y(d[1]); });
|
area.x(function(d) { return x(d[0]); }).y0(h).y1(function(d) { return y(d[1]); });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Chart Size
|
// Update Chart Size
|
||||||
svg.attr("width", width).attr("height", height);
|
svg.attr('width', width).attr('height', height);
|
||||||
// Update domain and scale for axes;
|
// Update domain and scale for axes;
|
||||||
x.range([0, w]).domain([series.xMin, series.xMax]).clamp(true);
|
x.range([0, w]).domain([series.xMin, series.xMax]).clamp(true);
|
||||||
xAxis.scale(x);
|
xAxis.scale(x);
|
||||||
xLbl.attr("transform", "translate(0," + h + ")");
|
xLbl.attr('transform', 'translate(0,' + h + ')');
|
||||||
xTxt.attr("x", w/2);
|
xTxt.attr('x', w / 2);
|
||||||
y.range([h, 0]).domain([series.yMin, series.yMax]);
|
y.range([h, 0]).domain([series.yMin, series.yMax]);
|
||||||
yAxis.scale(y);
|
yAxis.scale(y);
|
||||||
yTxt.attr("x", -h/2);
|
yTxt.attr('x', -h / 2);
|
||||||
vis.selectAll(".y.axis").call(yAxis);
|
vis.selectAll('.y.axis').call(yAxis);
|
||||||
vis.selectAll(".x.axis").call(xAxis);
|
vis.selectAll('.x.axis').call(xAxis);
|
||||||
|
|
||||||
// Remove existing elements
|
// Remove existing elements
|
||||||
vis.selectAll('path.area').remove();
|
vis.selectAll('path.area').remove();
|
||||||
|
|
||||||
vis.insert("path",':first-child') // Area/Path to appear behind everything else
|
vis.insert('path', ':first-child') // Area/Path to appear behind everything else
|
||||||
.datum(data)
|
.datum(data)
|
||||||
.attr("class", "area")
|
.attr('class', 'area')
|
||||||
.attr('fill', 'url(#gradient)')
|
.attr('fill', 'url(#gradient)')
|
||||||
.attr("d", area)
|
.attr('d', area)
|
||||||
.on('mouseover', showTip)
|
.on('mouseover', showTip)
|
||||||
.on('mouseout', hideTip)
|
.on('mouseout', hideTip)
|
||||||
.on('mousemove', moveTip)
|
.on('mousemove', moveTip)
|
||||||
@@ -127,7 +125,7 @@ angular.module('app').directive('areaChart', ['$window', function ($window) {
|
|||||||
moveTip.call(this);
|
moveTip.call(this);
|
||||||
showTip();
|
showTip();
|
||||||
})
|
})
|
||||||
.on("dragend", function() {
|
.on('dragend', function() {
|
||||||
dragging = false;
|
dragging = false;
|
||||||
hideTip();
|
hideTip();
|
||||||
})
|
})
|
||||||
@@ -135,20 +133,20 @@ angular.module('app').directive('areaChart', ['$window', function ($window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function showTip() {
|
function showTip() {
|
||||||
tip.style("display", null);
|
tip.style('display', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideTip() {
|
function hideTip() {
|
||||||
if (!dragging) {
|
if (!dragging) {
|
||||||
tip.style("display", "none");
|
tip.style('display', 'none');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveTip() {
|
function moveTip() {
|
||||||
var xPos = d3.mouse(this)[0], x0 = x.invert(xPos), y0 = func(x0), flip = (x0 / x.domain()[1] > 0.75);
|
var xPos = d3.mouse(this)[0], x0 = x.invert(xPos), y0 = func(x0), flip = (x0 / x.domain()[1] > 0.75);
|
||||||
tip.attr("transform", "translate(" + x(x0) + "," + y(y0) + ")");
|
tip.attr('transform', 'translate(' + x(x0) + ',' + y(y0) + ')');
|
||||||
tip.selectAll('rect').attr("x", flip? '-4.5em' : "0.5em").style("text-anchor", flip? 'end' : 'start');
|
tip.selectAll('rect').attr('x', flip ? '-4.5em' : '0.5em').style('text-anchor', flip ? 'end' : 'start');
|
||||||
tip.selectAll('text.label').attr("x", flip? "-1em" : "1em").style("text-anchor", flip? 'end' : 'start');
|
tip.selectAll('text.label').attr('x', flip ? '-1em' : '1em').style('text-anchor', flip ? 'end' : 'start');
|
||||||
tip.select('text.label.x').text(fmtLong(x0) + ' ' + labels.xAxis.unit);
|
tip.select('text.label.x').text(fmtLong(x0) + ' ' + labels.xAxis.unit);
|
||||||
tip.select('text.label.y').text(fmtLong(y0) + ' ' + labels.yAxis.unit);
|
tip.select('text.label.y').text(fmtLong(y0) + ' ' + labels.yAxis.unit);
|
||||||
}
|
}
|
||||||
@@ -159,4 +157,4 @@ angular.module('app').directive('areaChart', ['$window', function ($window) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
angular.module('app').directive('barChart', ['$window', function ($window) {
|
angular.module('app').directive('barChart', ['$window', function($window) {
|
||||||
|
|
||||||
function bName (build) {
|
function bName(build) {
|
||||||
return build.buildName + '\n' + build.name;
|
return build.buildName + '\n' + build.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
var insertLinebreaks = function (d) {
|
function insertLinebreaks(d) {
|
||||||
var el = d3.select(this);
|
var el = d3.select(this);
|
||||||
var words = d.split('\n');
|
var words = d.split('\n');
|
||||||
el.text('').attr('y', -6);
|
el.text('').attr('y', -6);
|
||||||
@@ -14,11 +14,11 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
|||||||
tspan.attr('x', -9).attr('dy', 12);
|
tspan.attr('x', -9).attr('dy', 12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
scope:{
|
scope: {
|
||||||
data: '=',
|
data: '=',
|
||||||
facet: '='
|
facet: '='
|
||||||
},
|
},
|
||||||
@@ -28,7 +28,7 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
|||||||
fmt = scope.facet.fmt,
|
fmt = scope.facet.fmt,
|
||||||
properties = scope.facet.props,
|
properties = scope.facet.props,
|
||||||
unit = scope.facet.unit,
|
unit = scope.facet.unit,
|
||||||
margin = {top: 10, right: 20, bottom: 35, left: 150},
|
margin = { top: 10, right: 20, bottom: 35, left: 150 },
|
||||||
y0 = d3.scale.ordinal(),
|
y0 = d3.scale.ordinal(),
|
||||||
y1 = d3.scale.ordinal(),
|
y1 = d3.scale.ordinal(),
|
||||||
x = d3.scale.linear(),
|
x = d3.scale.linear(),
|
||||||
@@ -43,7 +43,7 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
|||||||
var tip = d3.tip()
|
var tip = d3.tip()
|
||||||
.attr('class', 'd3-tip')
|
.attr('class', 'd3-tip')
|
||||||
.html(function(property, propertyIndex) {
|
.html(function(property, propertyIndex) {
|
||||||
return (labels? (labels[propertyIndex] + ': ') : '') + fmt(property.value) + ' ' + unit;
|
return (labels ? (labels[propertyIndex] + ': ') : '') + fmt(property.value) + ' ' + unit;
|
||||||
});
|
});
|
||||||
|
|
||||||
vis.call(tip);
|
vis.call(tip);
|
||||||
@@ -52,13 +52,13 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
|||||||
vis.append('g').attr('class', 'y axis');
|
vis.append('g').attr('class', 'y axis');
|
||||||
vis.selectAll('g.y.axis g text').each(insertLinebreaks);
|
vis.selectAll('g.y.axis g text').each(insertLinebreaks);
|
||||||
// Create X Axis SVG Elements
|
// Create X Axis SVG Elements
|
||||||
var xAxisLbl = vis.append('g')
|
var xAxisLbl = vis.append('g')
|
||||||
.attr('class', 'x axis')
|
.attr('class', 'x axis')
|
||||||
.append('text')
|
.append('text')
|
||||||
.attr('y', 30)
|
.attr('y', 30)
|
||||||
.attr('dy', '.1em')
|
.attr('dy', '.1em')
|
||||||
.style('text-anchor', 'middle')
|
.style('text-anchor', 'middle')
|
||||||
.text(scope.facet.title + (unit? (' (' + unit + ')') : ''));
|
.text(scope.facet.title + (unit ? (' (' + unit + ')') : ''));
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,11 +84,11 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
|||||||
|
|
||||||
// Update X & Y Axis
|
// Update X & Y Axis
|
||||||
x.range([0, w]).domain([0, maxVal]);
|
x.range([0, w]).domain([0, maxVal]);
|
||||||
y0.domain(data.map(bName)).rangeRoundBands([0, h],0.3);
|
y0.domain(data.map(bName)).rangeRoundBands([0, h], 0.3);
|
||||||
y1.domain(properties).rangeRoundBands([0, y0.rangeBand()]);
|
y1.domain(properties).rangeRoundBands([0, y0.rangeBand()]);
|
||||||
vis.selectAll('.y.axis').call(yAxis);
|
vis.selectAll('.y.axis').call(yAxis);
|
||||||
vis.selectAll('.x.axis').attr('transform', 'translate(0,' + h + ')').call(xAxis);
|
vis.selectAll('.x.axis').attr('transform', 'translate(0,' + h + ')').call(xAxis);
|
||||||
xAxisLbl.attr('x', w/2);
|
xAxisLbl.attr('x', w / 2);
|
||||||
// Update Y-Axis labels
|
// Update Y-Axis labels
|
||||||
vis.selectAll('g.y.axis g text').each(insertLinebreaks);
|
vis.selectAll('g.y.axis g text').each(insertLinebreaks);
|
||||||
|
|
||||||
@@ -102,13 +102,13 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
|||||||
.data(function(build) {
|
.data(function(build) {
|
||||||
var o = [];
|
var o = [];
|
||||||
for (var i = 0; i < properties.length; i++) {
|
for (var i = 0; i < properties.length; i++) {
|
||||||
o.push({name: properties[i], value:build[properties[i]]});
|
o.push({ name: properties[i], value: build[properties[i]] });
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
})
|
})
|
||||||
.enter().append('rect')
|
.enter().append('rect')
|
||||||
.attr('height', y1.rangeBand())
|
.attr('height', y1.rangeBand())
|
||||||
.attr('x',0)
|
.attr('x', 0)
|
||||||
.attr('y', function(d) {return y1(d.name); })
|
.attr('y', function(d) {return y1(d.name); })
|
||||||
.attr('width', function(d) { return x(d.value); })
|
.attr('width', function(d) { return x(d.value); })
|
||||||
.on('mouseover', tip.show)
|
.on('mouseover', tip.show)
|
||||||
@@ -124,4 +124,4 @@ angular.module('app').directive('barChart', ['$window', function ($window) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
angular.module('app').directive('comparisonTable', ['$state', function ($state) {
|
angular.module('app').directive('comparisonTable', ['$state', function($state) {
|
||||||
|
|
||||||
function tblHeader(facets) {
|
function tblHeader(facets) {
|
||||||
var r1 = ['<tr class="main"><th rowspan="2" class="prop" prop="name">Ship</th><th rowspan="2" class="prop" prop="buildName">Build</th>'];
|
var r1 = ['<tr class="main"><th rowspan="2" class="prop" prop="name">Ship</th><th rowspan="2" class="prop" prop="buildName">Build</th>'];
|
||||||
@@ -8,17 +8,17 @@ angular.module('app').directive('comparisonTable', ['$state', function ($state)
|
|||||||
var f = facets[i];
|
var f = facets[i];
|
||||||
var p = f.props;
|
var p = f.props;
|
||||||
var pl = p.length;
|
var pl = p.length;
|
||||||
r1.push('<th rowspan="', f.props.length == 1 ? 2 : 1,'" colspan="',pl,'"');
|
r1.push('<th rowspan="', f.props.length == 1 ? 2 : 1, '" colspan="', pl, '"');
|
||||||
|
|
||||||
if (pl == 1) {
|
if (pl == 1) {
|
||||||
r1.push(' prop="',p[0],'" class="prop"');
|
r1.push(' prop="', p[0], '" class="prop"');
|
||||||
} else {
|
} else {
|
||||||
for (var j = 0; j < pl; j++) {
|
for (var j = 0; j < pl; j++) {
|
||||||
r2.push('<th prop="', p[j], '" class="prop ', j === 0? 'lft' : '', ' ">' , f.lbls[j], '</th>');
|
r2.push('<th prop="', p[j], '" class="prop ', j === 0 ? 'lft' : '', '">', f.lbls[j], '</th>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r1.push('>', f.title ,'</th>');
|
r1.push('>', f.title, '</th>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r1.push('</tr><tr>');
|
r1.push('</tr><tr>');
|
||||||
@@ -30,16 +30,16 @@ angular.module('app').directive('comparisonTable', ['$state', function ($state)
|
|||||||
function tblBody(facets, builds) {
|
function tblBody(facets, builds) {
|
||||||
var body = [];
|
var body = [];
|
||||||
|
|
||||||
if(builds.length === 0) {
|
if (builds.length === 0) {
|
||||||
return '<td colspan="100" class="cen">No builds added to comparison!</td';
|
return '<td colspan="100" class="cen">No builds added to comparison!</td';
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0, l = builds.length; i < l; i++) {
|
for (var i = 0, l = builds.length; i < l; i++) {
|
||||||
var b = builds[i];
|
var b = builds[i];
|
||||||
body.push('<tr class="tr">');
|
body.push('<tr class="tr">');
|
||||||
var href = $state.href('outfit',{shipId: b.id, code: b.code, bn: b.buildName});
|
var href = $state.href('outfit', { shipId: b.id, code: b.code, bn: b.buildName });
|
||||||
body.push('<td class="tl"><a href="', href,'">', b.name,'</a></td>');
|
body.push('<td class="tl"><a href="', href, '">', b.name, '</a></td>');
|
||||||
body.push('<td class="tl"><a href="', href,'">', b.buildName,'</a></td>');
|
body.push('<td class="tl"><a href="', href, '">', b.buildName, '</a></td>');
|
||||||
|
|
||||||
for (var j = 0, fl = facets.length; j < fl; j++) {
|
for (var j = 0, fl = facets.length; j < fl; j++) {
|
||||||
if (facets[j].active) {
|
if (facets[j].active) {
|
||||||
@@ -59,13 +59,13 @@ angular.module('app').directive('comparisonTable', ['$state', function ($state)
|
|||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
|
|
||||||
link: function (scope, element) {
|
link: function(scope, element) {
|
||||||
var header = angular.element('<thead></thead>');
|
var header = angular.element('<thead></thead>');
|
||||||
var body = angular.element('<tbody></tbody>');
|
var body = angular.element('<tbody></tbody>');
|
||||||
element.append(header);
|
element.append(header);
|
||||||
element.append(body);
|
element.append(body);
|
||||||
|
|
||||||
var updateAll = function (){
|
var updateAll = function() {
|
||||||
header.html(tblHeader(scope.facets));
|
header.html(tblHeader(scope.facets));
|
||||||
body.html(tblBody(scope.facets, scope.builds));
|
body.html(tblBody(scope.facets, scope.builds));
|
||||||
};
|
};
|
||||||
@@ -77,4 +77,4 @@ angular.module('app').directive('comparisonTable', ['$state', function ($state)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
angular.module('app').directive('componentSelect', function () {
|
angular.module('app').directive('componentSelect', function() {
|
||||||
|
|
||||||
// Generting the HTML in this manner is MUCH faster than using an angular template.
|
// Generting the HTML in this manner is MUCH faster than using an angular template.
|
||||||
|
|
||||||
@@ -8,42 +8,42 @@ angular.module('app').directive('componentSelect', function () {
|
|||||||
var o = opts[i];
|
var o = opts[i];
|
||||||
var id = o.id || (o.class + o.rating); // Common components' ID is their class and rating
|
var id = o.id || (o.class + o.rating); // Common components' ID is their class and rating
|
||||||
|
|
||||||
if(i > 0 && opts.length > 3 && o.class != prevClass && (!o.grp || o.rating != prevRating || o.mode)) {
|
if (i > 0 && opts.length > 3 && o.class != prevClass && (!o.grp || o.rating != prevRating || o.mode)) {
|
||||||
list.push('<br/>');
|
list.push('<br/>');
|
||||||
}
|
}
|
||||||
|
|
||||||
list.push('<li class="', o.name? 'lc' : 'c');
|
list.push('<li class="', o.name ? 'lc' : 'c');
|
||||||
|
|
||||||
if (cid == id) {
|
if (cid == id) {
|
||||||
list.push(' active');
|
list.push(' active');
|
||||||
}
|
}
|
||||||
|
|
||||||
list.push((o.maxmass && mass > o.maxmass)? ' disabled"' : '" cpid="', id, '">');
|
list.push((o.maxmass && mass > o.maxmass) ? ' disabled"' : '" cpid="', id, '">');
|
||||||
|
|
||||||
if(o.mode) {
|
if (o.mode) {
|
||||||
list.push('<svg cpid="', id, '" class="icon lg"><use xlink:href="#mount-', o.mode , '"></use></svg> ');
|
list.push('<svg cpid="', id, '" class="icon lg"><use xlink:href="#mount-', o.mode, '"></use></svg> ');
|
||||||
}
|
}
|
||||||
|
|
||||||
list.push(o.class, o.rating);
|
list.push(o.class, o.rating);
|
||||||
|
|
||||||
if(o.missile) {
|
if (o.missile) {
|
||||||
list.push('/' + o.missile);
|
list.push('/' + o.missile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(o.name) {
|
if (o.name) {
|
||||||
list.push(' ' + o.name);
|
list.push(' ' + o.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
list.push('</li>');
|
list.push('</li>');
|
||||||
prevClass = o.class;
|
prevClass = o.class;
|
||||||
prevRating= o.rating;
|
prevRating = o.rating;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
scope:{
|
scope: {
|
||||||
opts: '=', // Component Options object
|
opts: '=', // Component Options object
|
||||||
groups: '=', // Groups of Component Options
|
groups: '=', // Groups of Component Options
|
||||||
mass: '=', // Current ship unladen mass
|
mass: '=', // Current ship unladen mass
|
||||||
@@ -57,13 +57,13 @@ angular.module('app').directive('componentSelect', function () {
|
|||||||
var groups = scope.groups;
|
var groups = scope.groups;
|
||||||
var mass = scope.mass || 0;
|
var mass = scope.mass || 0;
|
||||||
|
|
||||||
if(groups) {
|
if (groups) {
|
||||||
// At present time slots with grouped options (Hardpoints and Internal) can be empty
|
// At present time slots with grouped options (Hardpoints and Internal) can be empty
|
||||||
list.push('<div class="empty-c" cpid="empty">EMPTY</div>');
|
list.push('<div class="empty-c" cpid="empty">EMPTY</div>');
|
||||||
for (var g in groups) {
|
for (var g in groups) {
|
||||||
var grp = groups[g];
|
var grp = groups[g];
|
||||||
var grpCode = grp[Object.keys(grp)[0]].grp; // Nasty operation to get the grp property of the first/any single component
|
var grpCode = grp[Object.keys(grp)[0]].grp; // Nasty operation to get the grp property of the first/any single component
|
||||||
list.push('<div id="', grpCode ,'" class="select-group">', g, '</div><ul>');
|
list.push('<div id="', grpCode, '" class="select-group">', g, '</div><ul>');
|
||||||
appendGroup(list, grp, cid, mass);
|
appendGroup(list, grp, cid, mass);
|
||||||
list.push('</ul>');
|
list.push('</ul>');
|
||||||
}
|
}
|
||||||
@@ -77,9 +77,9 @@ angular.module('app').directive('componentSelect', function () {
|
|||||||
// If groups are present and a component is already selectd
|
// If groups are present and a component is already selectd
|
||||||
if (groups && component && component.grp) {
|
if (groups && component && component.grp) {
|
||||||
var groupElement = angular.element(document.getElementById(component.grp));
|
var groupElement = angular.element(document.getElementById(component.grp));
|
||||||
var parentElem = element[0].parentElement;
|
var parentElem = element[0].parentElement;
|
||||||
parentElem.scrollTop = groupElement[0].offsetTop; // Scroll to currently selected group
|
parentElem.scrollTop = groupElement[0].offsetTop; // Scroll to currently selected group
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Persist', 'ShipsDB', function (_, $rootScope, Persist, ships) {
|
angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Persist', 'ShipsDB', function(_, $rootScope, Persist, ships) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
templateUrl: 'views/_header.html',
|
templateUrl: 'views/_header.html',
|
||||||
scope: true,
|
scope: true,
|
||||||
link: function (scope) {
|
link: function(scope) {
|
||||||
scope.openedMenu = null;
|
scope.openedMenu = null;
|
||||||
scope.ships = ships;
|
scope.ships = ships;
|
||||||
scope.allBuilds = Persist.builds;
|
scope.allBuilds = Persist.builds;
|
||||||
@@ -15,22 +15,22 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
|||||||
// Insurance options and management here for now.
|
// Insurance options and management here for now.
|
||||||
$rootScope.insurance = {
|
$rootScope.insurance = {
|
||||||
opts: [
|
opts: [
|
||||||
{ name:'Standard', pct: 0.05 },
|
{ name: 'Standard', pct: 0.05 },
|
||||||
{ name:'Alpha', pct: 0.025 },
|
{ name: 'Alpha', pct: 0.025 },
|
||||||
{ name:'Beta', pct: 0.035 }
|
{ 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];
|
||||||
|
|
||||||
// Close menus if a navigation change event occurs
|
// Close menus if a navigation change event occurs
|
||||||
$rootScope.$on('$stateChangeStart',function(){
|
$rootScope.$on('$stateChangeStart', function() {
|
||||||
scope.openedMenu = null;
|
scope.openedMenu = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen to close event to close opened menus or modals
|
// Listen to close event to close opened menus or modals
|
||||||
$rootScope.$on('close', function () {
|
$rootScope.$on('close', function() {
|
||||||
scope.openedMenu = null;
|
scope.openedMenu = null;
|
||||||
$rootScope.showAbout = false;
|
$rootScope.showAbout = false;
|
||||||
});
|
});
|
||||||
@@ -38,13 +38,13 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
|||||||
/**
|
/**
|
||||||
* Save selected insurance option
|
* Save selected insurance option
|
||||||
*/
|
*/
|
||||||
scope.updateInsurance = function(){
|
scope.updateInsurance = function() {
|
||||||
Persist.setInsurance($rootScope.insurance.current.name);
|
Persist.setInsurance($rootScope.insurance.current.name);
|
||||||
};
|
};
|
||||||
|
|
||||||
scope.openMenu = function (e, menu) {
|
scope.openMenu = function(e, menu) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if(menu == scope.openedMenu) {
|
if (menu == scope.openedMenu) {
|
||||||
scope.openedMenu = null;
|
scope.openedMenu = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
|||||||
$rootScope.showAbout = true;
|
$rootScope.showAbout = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
$rootScope.hideAbout = function (){
|
$rootScope.hideAbout = function() {
|
||||||
$rootScope.showAbout = false;
|
$rootScope.showAbout = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -72,4 +72,4 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
angular.module('app').directive('powerBands', ['$window', function ($window) {
|
angular.module('app').directive('powerBands', ['$window', function($window) {
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
scope:{
|
scope: {
|
||||||
bands: '=',
|
bands: '=',
|
||||||
available: '='
|
available: '='
|
||||||
},
|
},
|
||||||
link: function(scope, element) {
|
link: function(scope, element) {
|
||||||
var margin = {top: 20, right: 130, bottom: 20, left: 40},
|
var margin = { top: 20, right: 130, bottom: 20, left: 40 },
|
||||||
barHeight = 20,
|
barHeight = 20,
|
||||||
innerHeight = (barHeight * 2) + 3,
|
innerHeight = (barHeight * 2) + 3,
|
||||||
height = innerHeight + margin.top + margin.bottom + 1,
|
height = innerHeight + margin.top + margin.bottom + 1,
|
||||||
@@ -25,11 +25,11 @@ angular.module('app').directive('powerBands', ['$window', function ($window) {
|
|||||||
// Create Y Axis SVG Elements
|
// Create Y Axis SVG Elements
|
||||||
vis.append('g').attr('class', 'watt axis');
|
vis.append('g').attr('class', 'watt axis');
|
||||||
vis.append('g').attr('class', 'pct axis');
|
vis.append('g').attr('class', 'pct axis');
|
||||||
vis.append("text").attr('x', -35).attr('y', 16).attr('class','primary').text('RET');
|
vis.append('text').attr('x', -35).attr('y', 16).attr('class', 'primary').text('RET');
|
||||||
vis.append("text").attr('x', -35).attr('y', barHeight + 18).attr('class','primary').text('DEP');
|
vis.append('text').attr('x', -35).attr('y', barHeight + 18).attr('class', 'primary').text('DEP');
|
||||||
|
|
||||||
var retLbl = vis.append("text").attr('y', 16);
|
var retLbl = vis.append('text').attr('y', 16);
|
||||||
var depLbl = vis.append("text").attr('y', barHeight + 18);
|
var depLbl = vis.append('text').attr('y', barHeight + 18);
|
||||||
|
|
||||||
// Watch for changes to data and events
|
// Watch for changes to data and events
|
||||||
scope.$watchCollection('available', render);
|
scope.$watchCollection('available', render);
|
||||||
@@ -61,40 +61,41 @@ angular.module('app').directive('powerBands', ['$window', function ($window) {
|
|||||||
|
|
||||||
retLbl
|
retLbl
|
||||||
.attr('x', w + 5 )
|
.attr('x', w + 5 )
|
||||||
.attr('class',maxBand.retractedSum > available? 'warning': 'primary')
|
.attr('class', maxBand.retractedSum > available ? 'warning' : 'primary')
|
||||||
.text(wattFmt(Math.max(0,maxBand.retractedSum)) + ' (' + pctFmt(Math.max(0,maxBand.retractedSum / available)) + ')');
|
.text(wattFmt(Math.max(0, maxBand.retractedSum)) + ' (' + pctFmt(Math.max(0, maxBand.retractedSum / available)) + ')');
|
||||||
|
|
||||||
depLbl
|
depLbl
|
||||||
.attr('x', w + 5 )
|
.attr('x', w + 5 )
|
||||||
.attr('class',maxBand.deployedSum > available? 'warning': 'primary')
|
.attr('class', maxBand.deployedSum > available ? 'warning' : 'primary')
|
||||||
.text(wattFmt(Math.max(0,maxBand.deployedSum)) + ' (' + pctFmt(Math.max(0,maxBand.deployedSum / available)) + ')');
|
.text(wattFmt(Math.max(0, maxBand.deployedSum)) + ' (' + pctFmt(Math.max(0, maxBand.deployedSum / available)) + ')');
|
||||||
|
|
||||||
retracted.selectAll("rect").data(bands).enter().append("rect")
|
retracted.selectAll('rect').data(bands).enter().append('rect')
|
||||||
.attr("height", barHeight)
|
.attr('height', barHeight)
|
||||||
.attr("width", function(d) { return Math.max(wattScale(d.retracted) - 1, 0); })
|
.attr('width', function(d) { return Math.max(wattScale(d.retracted) - 1, 0); })
|
||||||
.attr("x", function(d) { return wattScale(d.retractedSum) - wattScale(d.retracted); })
|
.attr('x', function(d) { return wattScale(d.retractedSum) - wattScale(d.retracted); })
|
||||||
.attr('y', 1)
|
.attr('y', 1)
|
||||||
.attr('class',function(d){ return (d.retractedSum > available)? 'warning' :'primary'; });
|
.attr('class', function(d) { return (d.retractedSum > available) ? 'warning' : 'primary'; });
|
||||||
|
|
||||||
retracted.selectAll("text").data(bands).enter().append("text")
|
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) / 2); })
|
||||||
.attr('y', 15)
|
.attr('y', 15)
|
||||||
.style('text-anchor', 'middle')
|
.style('text-anchor', 'middle')
|
||||||
.attr('class','primary-bg')
|
.attr('class', 'primary-bg')
|
||||||
.text(function(d,i) { return bandText(d.retracted, i); });
|
.text(function(d, i) { return bandText(d.retracted, i); });
|
||||||
|
|
||||||
deployed.selectAll("rect").data(bands).enter().append("rect")
|
deployed.selectAll('rect').data(bands).enter().append('rect')
|
||||||
.attr("height", barHeight)
|
.attr('height', barHeight)
|
||||||
.attr("width", function(d) { return Math.max(wattScale(d.deployed + d.retracted) - 1, 0); })
|
.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('x', function(d) { return wattScale(d.deployedSum) - wattScale(d.retracted) - wattScale(d.deployed); })
|
||||||
.attr('y', barHeight + 2)
|
.attr('y', barHeight + 2)
|
||||||
.attr('class',function(d){ return (d.deployedSum > available)? 'warning' :'primary'; });
|
.attr('class', function(d) { return (d.deployedSum > available) ? 'warning' : 'primary'; });
|
||||||
|
|
||||||
deployed.selectAll("text").data(bands).enter().append("text")
|
deployed.selectAll('text').data(bands).enter().append('text')
|
||||||
.attr('x', function(d) { return wattScale(d.deployedSum) - ((wattScale(d.retracted) + wattScale(d.deployed)) / 2); })
|
.attr('x', function(d) { return wattScale(d.deployedSum) - ((wattScale(d.retracted) + wattScale(d.deployed)) / 2); })
|
||||||
.attr('y', barHeight + 17)
|
.attr('y', barHeight + 17)
|
||||||
.style('text-anchor', 'middle')
|
.style('text-anchor', 'middle')
|
||||||
.attr('class','primary-bg')
|
.attr('class', 'primary-bg')
|
||||||
.text(function(d,i) { return bandText(d.deployed + d.retracted, i); });
|
.text(function(d, i) { return bandText(d.deployed + d.retracted, i); });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,4 +111,4 @@ angular.module('app').directive('powerBands', ['$window', function ($window) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
angular.module('app').directive('slider', ['$window', function ($window) {
|
angular.module('app').directive('slider', ['$window', function($window) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
scope:{
|
scope: {
|
||||||
max: '=',
|
max: '=',
|
||||||
unit: '=',
|
unit: '=',
|
||||||
change: '&onChange'
|
change: '&onChange'
|
||||||
},
|
},
|
||||||
link: function(scope, element) {
|
link: function(scope, element) {
|
||||||
var margin = {top: -10, right: 140, bottom: 0, left: 50},
|
var margin = { top: -10, right: 140, bottom: 0, left: 50 },
|
||||||
height = 40, // Height is fixed
|
height = 40, // Height is fixed
|
||||||
h = height - margin.top - margin.bottom,
|
h = height - margin.top - margin.bottom,
|
||||||
fmt = d3.format('.2f'),
|
fmt = d3.format('.2f'),
|
||||||
pct = d3.format('.1%'),
|
pct = d3.format('.1%'),
|
||||||
unit = scope.unit,
|
unit = scope.unit,
|
||||||
val = scope.max,
|
val = scope.max,
|
||||||
svg = d3.select(element[0]).append("svg"),
|
svg = d3.select(element[0]).append('svg'),
|
||||||
vis = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"),
|
vis = svg.append('g').attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'),
|
||||||
xAxis = vis.append("g").attr("class", "x slider-axis").attr("transform", "translate(0," + h / 2 + ")"),
|
xAxis = vis.append('g').attr('class', 'x slider-axis').attr('transform', 'translate(0,' + h / 2 + ')'),
|
||||||
x = d3.scale.linear(),
|
x = d3.scale.linear(),
|
||||||
slider = vis.append("g").attr("class", "slider"),
|
slider = vis.append('g').attr('class', 'slider'),
|
||||||
filled = slider.append('path').attr('class', 'filled').attr("transform", "translate(0," + h/2 + ")"),
|
filled = slider.append('path').attr('class', 'filled').attr('transform', 'translate(0,' + h / 2 + ')'),
|
||||||
brush = d3.svg.brush().x(x).extent([scope.max, scope.max]).on("brush", brushed),
|
brush = d3.svg.brush().x(x).extent([scope.max, scope.max]).on('brush', brushed),
|
||||||
handle = slider.append("circle").attr("class", "handle").attr("r", '0.6em'),
|
handle = slider.append('circle').attr('class', 'handle').attr('r', '0.6em'),
|
||||||
lbl = slider.append("g").append("text").attr("y", h/2);
|
lbl = slider.append('g').append('text').attr('y', h / 2);
|
||||||
|
|
||||||
slider.call(brush);
|
slider.call(brush);
|
||||||
slider.select(".background").attr("height", h);
|
slider.select('.background').attr('height', h);
|
||||||
handle.attr("transform", "translate(0," + h / 2 + ")");
|
handle.attr('transform', 'translate(0,' + h / 2 + ')');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch for changes in the max, window size
|
* Watch for changes in the max, window size
|
||||||
@@ -42,21 +42,21 @@ angular.module('app').directive('slider', ['$window', function ($window) {
|
|||||||
function render() {
|
function render() {
|
||||||
var width = element[0].offsetWidth, w = width - margin.left - margin.right;
|
var width = element[0].offsetWidth, w = width - margin.left - margin.right;
|
||||||
|
|
||||||
svg.attr("width", width).attr("height", height);
|
svg.attr('width', width).attr('height', height);
|
||||||
x.domain([0, scope.max]).range([0, w]).clamp(true);
|
x.domain([0, scope.max]).range([0, w]).clamp(true);
|
||||||
handle.attr("cx", x(val));
|
handle.attr('cx', x(val));
|
||||||
xAxis
|
xAxis
|
||||||
.call(d3.svg.axis()
|
.call(d3.svg.axis()
|
||||||
.scale(x)
|
.scale(x)
|
||||||
.orient("bottom")
|
.orient('bottom')
|
||||||
.tickFormat(function(d) { return d + unit; })
|
.tickFormat(function(d) { return d + unit; })
|
||||||
.tickValues([0, scope.max / 4, scope.max / 2, (3 * scope.max) / 4, scope.max])
|
.tickValues([0, scope.max / 4, scope.max / 2, (3 * scope.max) / 4, scope.max])
|
||||||
.tickSize(0)
|
.tickSize(0)
|
||||||
.tickPadding(12))
|
.tickPadding(12))
|
||||||
.select(".domain");
|
.select('.domain');
|
||||||
lbl.attr('x', w + 20);
|
lbl.attr('x', w + 20);
|
||||||
slider.call(brush.extent([val, val])).call(brush.event);
|
slider.call(brush.extent([val, val])).call(brush.event);
|
||||||
slider.selectAll(".extent,.resize").remove();
|
slider.selectAll('.extent,.resize').remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
function brushed() {
|
function brushed() {
|
||||||
@@ -65,10 +65,10 @@ angular.module('app').directive('slider', ['$window', function ($window) {
|
|||||||
val = x.invert(d3.mouse(this)[0]);
|
val = x.invert(d3.mouse(this)[0]);
|
||||||
brush.extent([val, val]);
|
brush.extent([val, val]);
|
||||||
}
|
}
|
||||||
lbl.text(fmt(val) + ' ' + unit + ' ' + pct(val / scope.max));
|
lbl.text(fmt(val) + ' ' + unit + ' ' + pct(val / scope.max));
|
||||||
scope.change({val: val});
|
scope.change({ val: val });
|
||||||
handle.attr("cx", x(val));
|
handle.attr('cx', x(val));
|
||||||
filled.attr("d", "M0,0V0H" + x(val) + "V0");
|
filled.attr('d', 'M0,0V0H' + x(val) + 'V0');
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.$on('$destroy', function() {
|
scope.$on('$destroy', function() {
|
||||||
@@ -77,4 +77,4 @@ angular.module('app').directive('slider', ['$window', function ($window) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
angular.module('app').directive('slotHardpoint', ['$rootScope', function ($r) {
|
angular.module('app').directive('slotHardpoint', ['$rootScope', function($r) {
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
scope:{
|
scope: {
|
||||||
hp: '=',
|
hp: '=',
|
||||||
size: '=',
|
size: '=',
|
||||||
lbl: '=',
|
lbl: '='
|
||||||
},
|
},
|
||||||
templateUrl: 'views/_slot-hardpoint.html',
|
templateUrl: 'views/_slot-hardpoint.html',
|
||||||
link: function (scope) {
|
link: function(scope) {
|
||||||
scope.$r = $r;
|
scope.$r = $r;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
angular.module('app').directive('slotInternal', ['$rootScope', function ($r) {
|
angular.module('app').directive('slotInternal', ['$rootScope', function($r) {
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
scope:{
|
scope: {
|
||||||
c: '=slot',
|
c: '=slot',
|
||||||
lbl: '=',
|
lbl: '=',
|
||||||
fuel: '='
|
fuel: '='
|
||||||
@@ -11,4 +11,4 @@ angular.module('app').directive('slotInternal', ['$rootScope', function ($r) {
|
|||||||
scope.$r = $r;
|
scope.$r = $r;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* BBCode Generator functions for embedding in the Elite Dangerous Forums
|
* BBCode Generator functions for embedding in the Elite Dangerous Forums
|
||||||
*/
|
*/
|
||||||
angular.module('app').factory('Utils', ['$window','$state','$http', '$q', function ($window, $state, $http, $q) {
|
angular.module('app').factory('Utils', ['$window', '$state', '$http', '$q', function($window, $state, $http, $q) {
|
||||||
|
|
||||||
var shortenAPI = 'https://www.googleapis.com/urlshortener/v1/url?key=';
|
var shortenAPI = 'https://www.googleapis.com/urlshortener/v1/url?key=';
|
||||||
|
|
||||||
function shortenUrl(url) {
|
function shortenUrl(url) {
|
||||||
if ($window.navigator.onLine) {
|
if ($window.navigator.onLine) {
|
||||||
return $http.post(shortenAPI + GAPI_KEY, {longUrl:url}).then(function(response) {
|
return $http.post(shortenAPI + GAPI_KEY, { longUrl: url }).then(function(response) {
|
||||||
return response.data.id;
|
return response.data.id;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return $q.reject({statusText: 'Not Online'});
|
return $q.reject({ statusText: 'Not Online' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ angular.module('app').factory('Utils', ['$window','$state','$http', '$q', functi
|
|||||||
for (i = 0; i < builds.length; i++) {
|
for (i = 0; i < builds.length; i++) {
|
||||||
b = builds[i];
|
b = builds[i];
|
||||||
//var href = $state.href('outfit',{shipId: b.id, code: b.code, bn: b.buildName}, {absolute: true});
|
//var href = $state.href('outfit',{shipId: b.id, code: b.code, bn: b.buildName}, {absolute: true});
|
||||||
l.push('[tr][td]', b.name,'[/td][td]', b.buildName ,'[/td]');
|
l.push('[tr][td]', b.name, '[/td][td]', b.buildName, '[/td]');
|
||||||
|
|
||||||
for (j = 0, fl = facets.length; j < fl; j++) {
|
for (j = 0, fl = facets.length; j < fl; j++) {
|
||||||
if (facets[j].active) {
|
if (facets[j].active) {
|
||||||
@@ -52,8 +52,8 @@ angular.module('app').factory('Utils', ['$window','$state','$http', '$q', functi
|
|||||||
}
|
}
|
||||||
l.push('[/tr]\n');
|
l.push('[/tr]\n');
|
||||||
}
|
}
|
||||||
l.push('[tr][td="align: center, colspan:',colCount,'"][size=-3]\n[url=', link,']Interactive Comparison at Coriolis.io[/url][/td][/tr]\n[/size][/table]');
|
l.push('[tr][td="align: center, colspan:', colCount, '"][size=-3]\n[url=', link, ']Interactive Comparison at Coriolis.io[/url][/td][/tr]\n[/size][/table]');
|
||||||
l.unshift('[table="width:', colCount * 90,',align: center"]\n[tr][th][B][COLOR=#FF8C0D]Ship[/COLOR][/B][/th][th][B][COLOR="#FF8C0D"]Build[/COLOR][/B][/th]');
|
l.unshift('[table="width:', colCount * 90, ',align: center"]\n[tr][th][B][COLOR=#FF8C0D]Ship[/COLOR][/B][/th][th][B][COLOR="#FF8C0D"]Build[/COLOR][/B][/th]');
|
||||||
return l.join('');
|
return l.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* [description]
|
* [description]
|
||||||
*/
|
*/
|
||||||
angular.module('app').service('Persist', ['$window','lodash', function ($window, _) {
|
angular.module('app').service('Persist', ['$window', 'lodash', function($window, _) {
|
||||||
var LS_KEY_BUILDS = 'builds';
|
var LS_KEY_BUILDS = 'builds';
|
||||||
var LS_KEY_COMPARISONS = 'comparisons';
|
var LS_KEY_COMPARISONS = 'comparisons';
|
||||||
var localStorage = $window.localStorage;
|
var localStorage = $window.localStorage;
|
||||||
@@ -19,8 +19,8 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
this.lsEnabled = false;
|
this.lsEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.builds = buildJson? angular.fromJson(buildJson) : {};
|
this.builds = buildJson ? angular.fromJson(buildJson) : {};
|
||||||
this.comparisons = comparisonJson? angular.fromJson(comparisonJson) : {};
|
this.comparisons = comparisonJson ? angular.fromJson(comparisonJson) : {};
|
||||||
var buildCount = Object.keys(this.builds).length;
|
var buildCount = Object.keys(this.builds).length;
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
@@ -35,7 +35,7 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
* @param {string} name The name of the build
|
* @param {string} name The name of the build
|
||||||
* @param {string} code The serialized code
|
* @param {string} code The serialized code
|
||||||
*/
|
*/
|
||||||
this.saveBuild = function (shipId, name, code) {
|
this.saveBuild = function(shipId, name, code) {
|
||||||
if (!this.lsEnabled) {
|
if (!this.lsEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
this.builds[shipId] = {};
|
this.builds[shipId] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.builds[shipId][name]) {
|
if (!this.builds[shipId][name]) {
|
||||||
this.state.buildCount++;
|
this.state.buildCount++;
|
||||||
this.state.hasBuilds = true;
|
this.state.hasBuilds = true;
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
* @param {string} name The name of the build
|
* @param {string} name The name of the build
|
||||||
* @return {string} The serialized build string.
|
* @return {string} The serialized build string.
|
||||||
*/
|
*/
|
||||||
this.getBuild = function (shipId, name) {
|
this.getBuild = function(shipId, name) {
|
||||||
if (this.builds[shipId] && this.builds[shipId][name]) {
|
if (this.builds[shipId] && this.builds[shipId][name]) {
|
||||||
return this.builds[shipId][name];
|
return this.builds[shipId][name];
|
||||||
}
|
}
|
||||||
@@ -76,8 +76,8 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
* @param {string} shipId The unique id for a model of ship
|
* @param {string} shipId The unique id for a model of ship
|
||||||
* @param {string} name The name of the build
|
* @param {string} name The name of the build
|
||||||
*/
|
*/
|
||||||
this.deleteBuild = function (shipId, name) {
|
this.deleteBuild = function(shipId, name) {
|
||||||
if(this.lsEnabled && this.builds[shipId][name]) {
|
if (this.lsEnabled && this.builds[shipId][name]) {
|
||||||
delete this.builds[shipId][name];
|
delete this.builds[shipId][name];
|
||||||
if (Object.keys(this.builds[shipId]).length === 0) {
|
if (Object.keys(this.builds[shipId]).length === 0) {
|
||||||
delete this.builds[shipId];
|
delete this.builds[shipId];
|
||||||
@@ -90,8 +90,8 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
var comps = this.comparisons;
|
var comps = this.comparisons;
|
||||||
for (var c in comps) {
|
for (var c in comps) {
|
||||||
for (var i = 0; i < comps[c].builds.length; i++) { // For all builds in the current comparison
|
for (var i = 0; i < comps[c].builds.length; i++) { // For all builds in the current comparison
|
||||||
if(comps[c].builds[i].shipId == shipId && comps[c].builds[i].buildName == name) {
|
if (comps[c].builds[i].shipId == shipId && comps[c].builds[i].buildName == name) {
|
||||||
comps[c].builds.splice(i,1);
|
comps[c].builds.splice(i, 1);
|
||||||
break; // A build is unique ber comparison
|
break; // A build is unique ber comparison
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
* @param {array} builds Array of builds
|
* @param {array} builds Array of builds
|
||||||
* @param {array} facets Array of facet indices
|
* @param {array} facets Array of facet indices
|
||||||
*/
|
*/
|
||||||
this.saveComparison = function (name, builds, facets){
|
this.saveComparison = function(name, builds, facets) {
|
||||||
if (!this.lsEnabled) {
|
if (!this.lsEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
}
|
}
|
||||||
this.comparisons[name] = {
|
this.comparisons[name] = {
|
||||||
facets: facets,
|
facets: facets,
|
||||||
builds: _.map(builds, function (b) { return {shipId: b.id, buildName: b.buildName }; })
|
builds: _.map(builds, function(b) { return { shipId: b.id, buildName: b.buildName }; })
|
||||||
};
|
};
|
||||||
localStorage.setItem(LS_KEY_COMPARISONS, angular.toJson(this.comparisons));
|
localStorage.setItem(LS_KEY_COMPARISONS, angular.toJson(this.comparisons));
|
||||||
this.state.hasComparisons = true;
|
this.state.hasComparisons = true;
|
||||||
@@ -128,7 +128,7 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
* @param {string} name [description]
|
* @param {string} name [description]
|
||||||
* @return {object} Object containing array of facets and ship id + build names
|
* @return {object} Object containing array of facets and ship id + build names
|
||||||
*/
|
*/
|
||||||
this.getComparison = function (name) {
|
this.getComparison = function(name) {
|
||||||
if (this.comparisons[name]) {
|
if (this.comparisons[name]) {
|
||||||
return this.comparisons[name];
|
return this.comparisons[name];
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
* Removes the comparison from localstorage.
|
* Removes the comparison from localstorage.
|
||||||
* @param {string} name Comparison name
|
* @param {string} name Comparison name
|
||||||
*/
|
*/
|
||||||
this.deleteComparison = function (name) {
|
this.deleteComparison = function(name) {
|
||||||
if (this.lsEnabled && this.comparisons[name]) {
|
if (this.lsEnabled && this.comparisons[name]) {
|
||||||
delete this.comparisons[name];
|
delete this.comparisons[name];
|
||||||
localStorage.setItem(LS_KEY_COMPARISONS, angular.toJson(this.comparisons));
|
localStorage.setItem(LS_KEY_COMPARISONS, angular.toJson(this.comparisons));
|
||||||
@@ -166,7 +166,7 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
* Get the saved insurance type
|
* Get the saved insurance type
|
||||||
* @return {string} The name of the saved insurance type of null
|
* @return {string} The name of the saved insurance type of null
|
||||||
*/
|
*/
|
||||||
this.getInsurance = function () {
|
this.getInsurance = function() {
|
||||||
if (this.lsEnabled) {
|
if (this.lsEnabled) {
|
||||||
return localStorage.getItem('insurance');
|
return localStorage.getItem('insurance');
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
* Persist selected insurance type
|
* Persist selected insurance type
|
||||||
* @param {string} name Insurance type name
|
* @param {string} name Insurance type name
|
||||||
*/
|
*/
|
||||||
this.setInsurance = function (name) {
|
this.setInsurance = function(name) {
|
||||||
if (this.lsEnabled) {
|
if (this.lsEnabled) {
|
||||||
return localStorage.setItem('insurance', name);
|
return localStorage.setItem('insurance', name);
|
||||||
}
|
}
|
||||||
@@ -187,9 +187,9 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
* 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
|
||||||
*/
|
*/
|
||||||
this.getState = function () {
|
this.getState = function() {
|
||||||
if (this.lsEnabled) {
|
if (this.lsEnabled) {
|
||||||
var state = localStorage.getItem('state');
|
var state = localStorage.getItem('state');
|
||||||
if (state) {
|
if (state) {
|
||||||
return angular.fromJson(state);
|
return angular.fromJson(state);
|
||||||
}
|
}
|
||||||
@@ -201,9 +201,9 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
|
|||||||
* Save the current router state to localstorage
|
* Save the current router state to localstorage
|
||||||
* @param {object} state State object containing state name and params
|
* @param {object} state State object containing state name and params
|
||||||
*/
|
*/
|
||||||
this.setState = function (state) {
|
this.setState = function(state) {
|
||||||
if (this.lsEnabled) {
|
if (this.lsEnabled) {
|
||||||
localStorage.setItem('state',angular.toJson(state));
|
localStorage.setItem('state', angular.toJson(state));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Service managing seralization and deserialization of models for use in URLs and persistene.
|
* Service managing seralization and deserialization of models for use in URLs and persistene.
|
||||||
*/
|
*/
|
||||||
angular.module('app').service('Serializer', ['lodash', function (_) {
|
angular.module('app').service('Serializer', ['lodash', function(_) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes the ships selected components for all slots to a URL friendly string.
|
* Serializes the ships selected components for all slots to a URL friendly string.
|
||||||
@@ -10,7 +10,7 @@ angular.module('app').service('Serializer', ['lodash', function (_) {
|
|||||||
*/
|
*/
|
||||||
this.fromShip = function(ship) {
|
this.fromShip = function(ship) {
|
||||||
var power = {
|
var power = {
|
||||||
enabled: [ship.cargoScoop.enabled? 1 : 0],
|
enabled: [ship.cargoScoop.enabled ? 1 : 0],
|
||||||
priorities: [ship.cargoScoop.priority]
|
priorities: [ship.cargoScoop.priority]
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -20,9 +20,9 @@ angular.module('app').service('Serializer', ['lodash', function (_) {
|
|||||||
_.map(ship.hardpoints, mapGroup, power),
|
_.map(ship.hardpoints, mapGroup, power),
|
||||||
_.map(ship.internal, mapGroup, power),
|
_.map(ship.internal, mapGroup, power),
|
||||||
'.',
|
'.',
|
||||||
LZString.compressToBase64(power.enabled.join('')).replace(/\//g,'-'),
|
LZString.compressToBase64(power.enabled.join('')).replace(/\//g, '-'),
|
||||||
'.',
|
'.',
|
||||||
LZString.compressToBase64(power.priorities.join('')).replace(/\//g,'-')
|
LZString.compressToBase64(power.priorities.join('')).replace(/\//g, '-')
|
||||||
];
|
];
|
||||||
|
|
||||||
return _.flatten(data).join('');
|
return _.flatten(data).join('');
|
||||||
@@ -35,11 +35,8 @@ angular.module('app').service('Serializer', ['lodash', function (_) {
|
|||||||
* @param {Ship} ship The ship instance to be updated
|
* @param {Ship} ship The ship instance to be updated
|
||||||
* @param {string} code The string to deserialize
|
* @param {string} code The string to deserialize
|
||||||
*/
|
*/
|
||||||
this.toShip = function (ship, dataString) {
|
this.toShip = function(ship, dataString) {
|
||||||
var commonCount = ship.common.length,
|
var common = new Array(ship.common.length),
|
||||||
hpCount = commonCount + ship.hardpoints.length,
|
|
||||||
totalCount = hpCount + ship.internal.length,
|
|
||||||
common = new Array(ship.common.length),
|
|
||||||
hardpoints = new Array(ship.hardpoints.length),
|
hardpoints = new Array(ship.hardpoints.length),
|
||||||
internal = new Array(ship.internal.length),
|
internal = new Array(ship.internal.length),
|
||||||
parts = dataString.split('.'),
|
parts = dataString.split('.'),
|
||||||
@@ -47,12 +44,12 @@ angular.module('app').service('Serializer', ['lodash', function (_) {
|
|||||||
enabled = null,
|
enabled = null,
|
||||||
code = parts[0];
|
code = parts[0];
|
||||||
|
|
||||||
if(parts[1]) {
|
if (parts[1]) {
|
||||||
enabled = LZString.decompressFromBase64(parts[1].replace(/-/g,'/')).split('');
|
enabled = LZString.decompressFromBase64(parts[1].replace(/-/g, '/')).split('');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parts[2]) {
|
if (parts[2]) {
|
||||||
priorities = LZString.decompressFromBase64(parts[2].replace(/-/g,'/')).split('');
|
priorities = LZString.decompressFromBase64(parts[2].replace(/-/g, '/')).split('');
|
||||||
}
|
}
|
||||||
|
|
||||||
decodeToArray(code, internal, decodeToArray(code, hardpoints, decodeToArray(code, common, 1)));
|
decodeToArray(code, internal, decodeToArray(code, hardpoints, decodeToArray(code, common, 1)));
|
||||||
@@ -61,19 +58,23 @@ angular.module('app').service('Serializer', ['lodash', function (_) {
|
|||||||
// - priorities
|
// - priorities
|
||||||
// - enabled/disabled
|
// - enabled/disabled
|
||||||
|
|
||||||
ship.buildWith({
|
ship.buildWith(
|
||||||
bulkheads: code.charAt(0) * 1,
|
{
|
||||||
common: common,
|
bulkheads: code.charAt(0) * 1,
|
||||||
hardpoints: hardpoints,
|
common: common,
|
||||||
internal: internal,
|
hardpoints: hardpoints,
|
||||||
}, priorities, enabled);
|
internal: internal
|
||||||
|
},
|
||||||
|
priorities,
|
||||||
|
enabled
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.fromComparison = function (name, builds, facets, predicate, desc) {
|
this.fromComparison = function(name, builds, facets, predicate, desc) {
|
||||||
var shipBuilds = [];
|
var shipBuilds = [];
|
||||||
|
|
||||||
builds.forEach(function (b) {
|
builds.forEach(function(b) {
|
||||||
shipBuilds.push({s: b.id, n: b.buildName, c: this.fromShip(b)});
|
shipBuilds.push({ s: b.id, n: b.buildName, c: this.fromShip(b) });
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
return LZString.compressToBase64(angular.toJson({
|
return LZString.compressToBase64(angular.toJson({
|
||||||
@@ -81,12 +82,12 @@ angular.module('app').service('Serializer', ['lodash', function (_) {
|
|||||||
b: shipBuilds,
|
b: shipBuilds,
|
||||||
f: facets,
|
f: facets,
|
||||||
p: predicate,
|
p: predicate,
|
||||||
d: desc? 1 : 0
|
d: desc ? 1 : 0
|
||||||
})).replace(/\//g,'-');
|
})).replace(/\//g, '-');
|
||||||
};
|
};
|
||||||
|
|
||||||
this.toComparison = function (code) {
|
this.toComparison = function(code) {
|
||||||
return angular.fromJson(LZString.decompressFromBase64(code.replace(/-/g,'/')));
|
return angular.fromJson(LZString.decompressFromBase64(code.replace(/-/g, '/')));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,14 +99,14 @@ angular.module('app').service('Serializer', ['lodash', function (_) {
|
|||||||
* @return {string} The id of the selected component or '-' if none selected
|
* @return {string} The id of the selected component or '-' if none selected
|
||||||
*/
|
*/
|
||||||
function mapGroup(slot) {
|
function mapGroup(slot) {
|
||||||
this.enabled.push(slot.enabled? 1 : 0);
|
this.enabled.push(slot.enabled ? 1 : 0);
|
||||||
this.priorities.push(slot.priority);
|
this.priorities.push(slot.priority);
|
||||||
|
|
||||||
return (slot.id === null)? '-' : slot.id;
|
return slot.id === null ? '-' : slot.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function decodeToArray(code, arr, codePos) {
|
function decodeToArray(code, arr, codePos) {
|
||||||
for (i = 0; i < arr.length; i++) {
|
for (var i = 0; i < arr.length; i++) {
|
||||||
if (code.charAt(codePos) == '-') {
|
if (code.charAt(codePos) == '-') {
|
||||||
arr[i] = 0;
|
arr[i] = 0;
|
||||||
codePos++;
|
codePos++;
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
angular.module('shipyard').factory('ComponentSet', ['lodash', function (_) {
|
angular.module('shipyard').factory('ComponentSet', ['lodash', function(_) {
|
||||||
|
|
||||||
|
function filter(data, maxClass, minClass, mass) {
|
||||||
|
return _.filter(data, function(c) {
|
||||||
|
return c.class <= maxClass && c.class >= minClass && (c.maxmass === undefined || mass <= c.maxmass);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function ComponentSet(components, mass, maxCommonArr, maxInternal, maxHardPoint) {
|
function ComponentSet(components, mass, maxCommonArr, maxInternal, maxHardPoint) {
|
||||||
this.mass = mass;
|
this.mass = mass;
|
||||||
@@ -8,7 +14,7 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function (_) {
|
|||||||
this.hpClass = {};
|
this.hpClass = {};
|
||||||
this.intClass = {};
|
this.intClass = {};
|
||||||
|
|
||||||
for (var i = 0; i < components.common.length; i ++) {
|
for (var i = 0; i < components.common.length; i++) {
|
||||||
var max = maxCommonArr[i];
|
var max = maxCommonArr[i];
|
||||||
switch (i) {
|
switch (i) {
|
||||||
// Slots where component class must be equal to slot class
|
// Slots where component class must be equal to slot class
|
||||||
@@ -22,21 +28,21 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function (_) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var h in components.hardpoints) {
|
for (var h in components.hardpoints) {
|
||||||
this.hardpoints[h] = filter(components.hardpoints[h], maxHardPoint, 0, this.mass);
|
this.hardpoints[h] = filter(components.hardpoints[h], maxHardPoint, 0, this.mass);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var g in components.internal) {
|
for (var g in components.internal) {
|
||||||
this.internal[g] = filter(components.internal[g], maxInternal, 0, this.mass);
|
this.internal[g] = filter(components.internal[g], maxInternal, 0, this.mass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ComponentSet.prototype.getHps = function(c) {
|
ComponentSet.prototype.getHps = function(c) {
|
||||||
if(!this.hpClass[c]) {
|
if (!this.hpClass[c]) {
|
||||||
var o = this.hpClass[c] = {};
|
var o = this.hpClass[c] = {};
|
||||||
for(var key in this.hardpoints) {
|
for (var key in this.hardpoints) {
|
||||||
var data = filter(this.hardpoints[key], c, c? 1 : 0, this.mass);
|
var data = filter(this.hardpoints[key], c, c ? 1 : 0, this.mass);
|
||||||
if(data.length) { // If group is not empty
|
if (data.length) { // If group is not empty
|
||||||
o[key] = data;
|
o[key] = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,11 +51,11 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function (_) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ComponentSet.prototype.getInts = function(c) {
|
ComponentSet.prototype.getInts = function(c) {
|
||||||
if(!this.intClass[c]) {
|
if (!this.intClass[c]) {
|
||||||
var o = this.intClass[c] = {};
|
var o = this.intClass[c] = {};
|
||||||
for(var key in this.internal) {
|
for (var key in this.internal) {
|
||||||
var data = filter(this.internal[key], c, 0, this.mass);
|
var data = filter(this.internal[key], c, 0, this.mass);
|
||||||
if(data.length) { // If group is not empty
|
if (data.length) { // If group is not empty
|
||||||
o[key] = data;
|
o[key] = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,12 +63,6 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function (_) {
|
|||||||
return this.intClass[c];
|
return this.intClass[c];
|
||||||
};
|
};
|
||||||
|
|
||||||
function filter (data, maxClass, minClass, mass) {
|
|
||||||
return _.filter(data, function (c) {
|
|
||||||
return c.class <= maxClass && c.class >= minClass && (c.maxmass === undefined || mass <= c.maxmass);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return ComponentSet;
|
return ComponentSet;
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength', 'calcJumpRange', 'lodash', function (Components, calcShieldStrength, calcJumpRange, _) {
|
angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength', 'calcJumpRange', 'lodash', function(Components, calcShieldStrength, calcJumpRange, _) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ship model used to track all ship components and properties.
|
* Ship model used to track all ship components and properties.
|
||||||
@@ -17,8 +17,8 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
for (var slotType in slots) { // Initialize all slots
|
for (var slotType in slots) { // Initialize all slots
|
||||||
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] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.c = { incCost: true, c: { name: this.name, cost: this.cost } }; // Make a 'Ship' component similar to other components
|
this.c = { incCost: true, c: { name: this.name, cost: this.cost } }; // Make a 'Ship' component similar to other components
|
||||||
@@ -37,11 +37,11 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
this.powerList.unshift(this.common[0]); // Add Power Plant
|
this.powerList.unshift(this.common[0]); // Add Power Plant
|
||||||
|
|
||||||
this.priorityBands = [
|
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 },
|
||||||
{deployed: 0, retracted: 0},
|
{ deployed: 0, retracted: 0 },
|
||||||
{deployed: 0, retracted: 0}
|
{ deployed: 0, retracted: 0 }
|
||||||
];
|
];
|
||||||
|
|
||||||
// Cumulative and aggragate stats
|
// Cumulative and aggragate stats
|
||||||
@@ -64,32 +64,32 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
common = this.common,
|
common = this.common,
|
||||||
hps = this.hardpoints,
|
hps = this.hardpoints,
|
||||||
bands = this.priorityBands,
|
bands = this.priorityBands,
|
||||||
cl = common.length, hl = hps.length, il = internal.length,
|
cl = common.length,
|
||||||
i,l;
|
i, l;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
if (this.cargoScoop.enabled) {
|
if (this.cargoScoop.enabled) {
|
||||||
bands[this.cargoScoop.priority].retracted += this.cargoScoop.c.power;
|
bands[this.cargoScoop.priority].retracted += this.cargoScoop.c.power;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < cl; i++) {
|
for (i = 0; i < cl; i++) {
|
||||||
common[i].enabled = enabled? enabled[i + 1] * 1 : true;
|
common[i].enabled = enabled ? enabled[i + 1] * 1 : true;
|
||||||
common[i].priority = priorities? priorities[i + 1] * 1 : 0;
|
common[i].priority = priorities ? priorities[i + 1] * 1 : 0;
|
||||||
common[i].type = 'SYS';
|
common[i].type = 'SYS';
|
||||||
this.use(common[i], comps.common[i], Components.common(i, comps.common[i]), true);
|
this.use(common[i], comps.common[i], Components.common(i, comps.common[i]), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
common[1].type = 'ENG'; // Thrusters
|
common[1].type = 'ENG'; // Thrusters
|
||||||
common[2].type = 'ENG'; // FSD
|
common[2].type = 'ENG'; // FSD
|
||||||
cl++; // Increase accounting for Cargo Scoop
|
cl++; // Increase accounts for Cargo Scoop
|
||||||
|
|
||||||
for(i = 0, l = comps.hardpoints.length; i < l; i++) {
|
for (i = 0, l = hps.length; i < l; i++) {
|
||||||
hps[i].enabled = enabled? enabled[cl + i] * 1 : true;
|
hps[i].enabled = enabled ? enabled[cl + i] * 1 : true;
|
||||||
hps[i].priority = priorities? priorities[cl + i] * 1 : 0;
|
hps[i].priority = priorities ? priorities[cl + i] * 1 : 0;
|
||||||
hps[i].type = hps[i].maxClass? 'WEP' : 'SYS';
|
hps[i].type = hps[i].maxClass ? 'WEP' : 'SYS';
|
||||||
|
|
||||||
if (comps.hardpoints[i] !== 0) {
|
if (comps.hardpoints[i] !== 0) {
|
||||||
this.use(hps[i], comps.hardpoints[i], Components.hardpoints(comps.hardpoints[i]), true);
|
this.use(hps[i], comps.hardpoints[i], Components.hardpoints(comps.hardpoints[i]), true);
|
||||||
@@ -98,9 +98,11 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0, l = comps.internal.length; i < l; i++) {
|
cl += hps.length; // Increase accounts for hardpoints
|
||||||
internal[i].enabled = enabled? enabled[hl + cl + i] * 1 : true;
|
|
||||||
internal[i].priority = priorities? priorities[hl + cl + i] * 1 : 0;
|
for (i = 0, l = internal.length; i < l; i++) {
|
||||||
|
internal[i].enabled = enabled ? enabled[cl + i] * 1 : true;
|
||||||
|
internal[i].priority = priorities ? priorities[cl + i] * 1 : 0;
|
||||||
internal[i].type = 'SYS';
|
internal[i].type = 'SYS';
|
||||||
|
|
||||||
if (comps.internal[i] !== 0) {
|
if (comps.internal[i] !== 0) {
|
||||||
@@ -117,7 +119,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ship.prototype.useBulkhead = function(index, preventUpdate) {
|
Ship.prototype.useBulkhead = function(index, preventUpdate) {
|
||||||
var oldBulkhead = this.bulkheads.c;
|
var oldBulkhead = this.bulkheads.c;
|
||||||
this.bulkheads.id = index;
|
this.bulkheads.id = index;
|
||||||
this.bulkheads.c = Components.bulkheads(this.id, index);
|
this.bulkheads.c = Components.bulkheads(this.id, index);
|
||||||
this.updateStats(this.bulkheads, this.bulkheads.c, oldBulkhead, preventUpdate);
|
this.updateStats(this.bulkheads, this.bulkheads.c, oldBulkhead, preventUpdate);
|
||||||
@@ -136,7 +138,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
if (slot.id != id) { // Selecting a different component
|
if (slot.id != id) { // Selecting a different component
|
||||||
var slotIndex = this.internal.indexOf(slot);
|
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
|
// 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
|
||||||
var similarSlotIndex = this.findInternalByGroup(component.grp);
|
var similarSlotIndex = this.findInternalByGroup(component.grp);
|
||||||
// If another slot has an installed component with of the same type
|
// If another slot has an installed component with of the same type
|
||||||
@@ -163,7 +165,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
* @param {number} fuel Fuel available in tons
|
* @param {number} fuel Fuel available in tons
|
||||||
* @return {number} Jump range in Light Years
|
* @return {number} Jump range in Light Years
|
||||||
*/
|
*/
|
||||||
Ship.prototype.jumpRangeWithMass = function (mass, fuel) {
|
Ship.prototype.jumpRangeWithMass = function(mass, fuel) {
|
||||||
return calcJumpRange(mass, this.common[2].c, fuel);
|
return calcJumpRange(mass, this.common[2].c, fuel);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -173,19 +175,19 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
* @param {string} group Component group/type
|
* @param {string} group Component group/type
|
||||||
* @return {number} The index of the slot in ship.internal
|
* @return {number} The index of the slot in ship.internal
|
||||||
*/
|
*/
|
||||||
Ship.prototype.findInternalByGroup = function (group) {
|
Ship.prototype.findInternalByGroup = function(group) {
|
||||||
return _.findIndex(this.internal, function (slot) {
|
return _.findIndex(this.internal, function(slot) {
|
||||||
return slot.c && slot.c.grp == group;
|
return slot.c && slot.c.grp == group;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Ship.prototype.changePriority = function (slot, newPriority) {
|
Ship.prototype.changePriority = function(slot, newPriority) {
|
||||||
if(newPriority >= 0 && newPriority < this.priorityBands.length) {
|
if (newPriority >= 0 && newPriority < this.priorityBands.length) {
|
||||||
var oldPriority = slot.priority;
|
var oldPriority = slot.priority;
|
||||||
slot.priority = newPriority;
|
slot.priority = newPriority;
|
||||||
|
|
||||||
if (slot.enabled) {
|
if (slot.enabled) {
|
||||||
var usage = (slot.c.passive || this.hardpoints.indexOf(slot) == -1)? 'retracted' : 'deployed';
|
var usage = (slot.c.passive || this.hardpoints.indexOf(slot) == -1) ? 'retracted' : 'deployed';
|
||||||
this.priorityBands[oldPriority][usage] -= slot.c.power;
|
this.priorityBands[oldPriority][usage] -= slot.c.power;
|
||||||
this.priorityBands[newPriority][usage] += slot.c.power;
|
this.priorityBands[newPriority][usage] += slot.c.power;
|
||||||
this.updatePower();
|
this.updatePower();
|
||||||
@@ -195,36 +197,33 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ship.prototype.setCostIncluded = function (item, included) {
|
Ship.prototype.setCostIncluded = function(item, included) {
|
||||||
if (item.incCost != included && item.c) {
|
if (item.incCost != included && item.c) {
|
||||||
this.totalCost += included? item.c.cost : -item.c.cost;
|
this.totalCost += included ? item.c.cost : -item.c.cost;
|
||||||
}
|
}
|
||||||
item.incCost = included;
|
item.incCost = included;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ship.prototype.setSlotEnabled = function (slot, enabled) {
|
Ship.prototype.setSlotEnabled = function(slot, enabled) {
|
||||||
if (slot.enabled != enabled && slot.c) { // Enabled state is changing
|
if (slot.enabled != enabled && slot.c) { // Enabled state is changing
|
||||||
var usage = (slot.c.passive || this.hardpoints.indexOf(slot) == -1)? 'retracted' : 'deployed';
|
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][usage] += enabled ? slot.c.power : -slot.c.power;
|
||||||
this.updatePower();
|
this.updatePower();
|
||||||
}
|
}
|
||||||
slot.enabled = enabled;
|
slot.enabled = enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ship.prototype.getSlotStatus = function (slot, deployed) {
|
Ship.prototype.getSlotStatus = function(slot, deployed) {
|
||||||
if(!slot.c) { // Empty Slot
|
if (!slot.c) { // Empty Slot
|
||||||
return 0; // No Status (Not possible)
|
return 0; // No Status (Not possible)
|
||||||
}
|
} else if (!slot.enabled) {
|
||||||
else if (!slot.enabled) {
|
|
||||||
return 1; // Disabled
|
return 1; // Disabled
|
||||||
}
|
} else if (deployed) {
|
||||||
else if (deployed) {
|
return this.priorityBands[slot.priority].deployedSum > this.powerAvailable ? 2 : 3; // Offline : Online
|
||||||
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
|
||||||
}
|
|
||||||
else if (this.hardpoints.indexOf(slot) != -1 && !slot.c.passive) { // Active hardpoints have no retracted status
|
|
||||||
return 0; // No Status (Not possible)
|
return 0; // No Status (Not possible)
|
||||||
}
|
}
|
||||||
return this.priorityBands[slot.priority].retractedSum > this.powerAvailable? 2 : 3; // Offline : Online
|
return this.priorityBands[slot.priority].retractedSum > this.powerAvailable ? 2 : 3; // Offline : Online
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -254,8 +253,8 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
this.totalCost -= old.cost;
|
this.totalCost -= old.cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(old.power) {
|
if (old.power) {
|
||||||
this.priorityBands[slot.priority][(isHardPoint && !old.passive)? 'deployed' : 'retracted'] -= old.power;
|
this.priorityBands[slot.priority][(isHardPoint && !old.passive) ? 'deployed' : 'retracted'] -= old.power;
|
||||||
powerChange = true;
|
powerChange = true;
|
||||||
}
|
}
|
||||||
this.unladenMass -= old.mass || 0;
|
this.unladenMass -= old.mass || 0;
|
||||||
@@ -285,7 +284,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (n.power) {
|
if (n.power) {
|
||||||
this.priorityBands[slot.priority][(isHardPoint && !n.passive)? 'deployed' : 'retracted'] += n.power;
|
this.priorityBands[slot.priority][(isHardPoint && !n.passive) ? 'deployed' : 'retracted'] += n.power;
|
||||||
powerChange = true;
|
powerChange = true;
|
||||||
}
|
}
|
||||||
this.unladenMass += n.mass || 0;
|
this.unladenMass += n.mass || 0;
|
||||||
@@ -294,7 +293,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
this.ladenMass = this.unladenMass + this.cargoCapacity + this.fuelCapacity;
|
this.ladenMass = this.unladenMass + this.cargoCapacity + this.fuelCapacity;
|
||||||
this.armourTotal = this.armourAdded + this.armour;
|
this.armourTotal = this.armourAdded + this.armour;
|
||||||
|
|
||||||
if(!preventUpdate) {
|
if (!preventUpdate) {
|
||||||
if (powerChange) {
|
if (powerChange) {
|
||||||
this.updatePower();
|
this.updatePower();
|
||||||
}
|
}
|
||||||
@@ -307,10 +306,10 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
var bands = this.priorityBands;
|
var bands = this.priorityBands;
|
||||||
var prevRetracted = 0, prevDeployed = 0;
|
var prevRetracted = 0, prevDeployed = 0;
|
||||||
|
|
||||||
for(var i = 0, l = bands.length; i < l; i++) {
|
for (var i = 0, l = bands.length; i < l; i++) {
|
||||||
var band = bands[i];
|
var band = bands[i];
|
||||||
prevRetracted = band.retractedSum = prevRetracted + band.retracted;
|
prevRetracted = band.retractedSum = prevRetracted + band.retracted;
|
||||||
prevDeployed = band.deployedSum = prevDeployed + band.deployed + band.retracted;
|
prevDeployed = band.deployedSum = prevDeployed + band.deployed + band.retracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.powerAvailable = this.common[0].c.pGen;
|
this.powerAvailable = this.common[0].c.pGen;
|
||||||
@@ -320,7 +319,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
|
|
||||||
Ship.prototype.updateShieldStrength = function() {
|
Ship.prototype.updateShieldStrength = function() {
|
||||||
var sgSI = this.findInternalByGroup('sg'); // Find Shield Generator slot Index if any
|
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;
|
this.shieldStrength = sgSI != -1 ? calcShieldStrength(this.mass, this.shields, this.internal[sgSI].c, this.shieldMultiplier) : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -336,8 +335,8 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
this.maxJumpCount = Math.ceil(jumps); // Number of full fuel jumps + final jump to empty tank
|
this.maxJumpCount = Math.ceil(jumps); // Number of full fuel jumps + final jump to empty tank
|
||||||
|
|
||||||
// Going backwards, start with the last jump using the remaining fuel
|
// Going backwards, start with the last jump using the remaining fuel
|
||||||
this.unladenTotalRange = fuelRemaining > 0? calcJumpRange(this.unladenMass + fuelRemaining, fsd, fuelRemaining): 0;
|
this.unladenTotalRange = fuelRemaining > 0 ? calcJumpRange(this.unladenMass + fuelRemaining, fsd, fuelRemaining) : 0;
|
||||||
this.ladenTotalRange = fuelRemaining > 0? calcJumpRange(this.unladenMass + this.cargoCapacity + fuelRemaining, fsd, fuelRemaining): 0;
|
this.ladenTotalRange = fuelRemaining > 0 ? calcJumpRange(this.unladenMass + this.cargoCapacity + fuelRemaining, fsd, fuelRemaining) : 0;
|
||||||
|
|
||||||
// For each max fuel jump, calculate the max jump range based on fuel left in the tank
|
// For each max fuel jump, calculate the max jump range based on fuel left in the tank
|
||||||
for (var j = 0, l = Math.floor(jumps); j < l; j++) {
|
for (var j = 0, l = Math.floor(jumps); j < l; j++) {
|
||||||
|
|||||||
@@ -22,48 +22,48 @@ angular.module('shipyard', ['ngLodash'])
|
|||||||
// Map to lookup group labels/names for component grp
|
// Map to lookup group labels/names for component grp
|
||||||
.value('GroupMap', {
|
.value('GroupMap', {
|
||||||
// Common
|
// Common
|
||||||
pp:'Power Plant',
|
pp: 'Power Plant',
|
||||||
t:'Thrusters',
|
t: 'Thrusters',
|
||||||
fsd:'Frame Shift Drive',
|
fsd: 'Frame Shift Drive',
|
||||||
ls:'Life Support',
|
ls: 'Life Support',
|
||||||
pd:'Power Distributor',
|
pd: 'Power Distributor',
|
||||||
s:'Sensors',
|
s: 'Sensors',
|
||||||
ft:'Fuel Tank',
|
ft: 'Fuel Tank',
|
||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
fs:'Fuel Scoop',
|
fs: 'Fuel Scoop',
|
||||||
sc:'Scanners',
|
sc: 'Scanners',
|
||||||
am:'Auto Field-Maint. Unit',
|
am: 'Auto Field-Maint. Unit',
|
||||||
cr:'Cargo Racks',
|
cr: 'Cargo Racks',
|
||||||
fi:'FSD Interdictor',
|
fi: 'FSD Interdictor',
|
||||||
hb:'Hatch Breaker Limpet Ctrl',
|
hb: 'Hatch Breaker Limpet Ctrl',
|
||||||
hr:'Hull Reinforcement Package',
|
hr: 'Hull Reinforcement Package',
|
||||||
rf:'Refinery',
|
rf: 'Refinery',
|
||||||
scb:'Shield Cell Bank',
|
scb: 'Shield Cell Bank',
|
||||||
sg:'Shield Generator',
|
sg: 'Shield Generator',
|
||||||
dc:'Docking Computer',
|
dc: 'Docking Computer',
|
||||||
fx:'Fuel Transfer Limpet Ctrl',
|
fx: 'Fuel Transfer Limpet Ctrl',
|
||||||
pc:'Prospector Limpet Ctrl',
|
pc: 'Prospector Limpet Ctrl',
|
||||||
cc:'Collector Limpet Ctrl',
|
cc: 'Collector Limpet Ctrl',
|
||||||
|
|
||||||
// Hard Points
|
// Hard Points
|
||||||
bl: "Beam Laser",
|
bl: 'Beam Laser',
|
||||||
ul: "Burst Laser",
|
ul: 'Burst Laser',
|
||||||
c: "Cannon",
|
c: 'Cannon',
|
||||||
cs: "Cargo Scanner",
|
cs: 'Cargo Scanner',
|
||||||
cm: "Countermeasure",
|
cm: 'Countermeasure',
|
||||||
fc: "Fragment Cannon",
|
fc: 'Fragment Cannon',
|
||||||
ws: "Frame Shift Wake Scanner",
|
ws: 'Frame Shift Wake Scanner',
|
||||||
kw: "Kill Warrant Scanner",
|
kw: 'Kill Warrant Scanner',
|
||||||
nl: "Mine Launcher",
|
nl: 'Mine Launcher',
|
||||||
ml: "Mining Laser",
|
ml: 'Mining Laser',
|
||||||
mr: "Missile Rack",
|
mr: 'Missile Rack',
|
||||||
pa: "Plasma Accelerator",
|
pa: 'Plasma Accelerator',
|
||||||
mc: "Multi-cannon",
|
mc: 'Multi-cannon',
|
||||||
pl: "Pulse Laser",
|
pl: 'Pulse Laser',
|
||||||
rg: "Rail Gun",
|
rg: 'Rail Gun',
|
||||||
sb: "Shield Booster",
|
sb: 'Shield Booster',
|
||||||
tp: "Torpedo Pylon"
|
tp: 'Torpedo Pylon'
|
||||||
})
|
})
|
||||||
.value('shipPurpose', {
|
.value('shipPurpose', {
|
||||||
mp: 'Multi Purpose',
|
mp: 'Multi Purpose',
|
||||||
@@ -77,7 +77,7 @@ angular.module('shipyard', ['ngLodash'])
|
|||||||
'Small',
|
'Small',
|
||||||
'Medium',
|
'Medium',
|
||||||
'Large',
|
'Large',
|
||||||
'Capital',
|
'Capital'
|
||||||
])
|
])
|
||||||
.value('hardPointClass', [
|
.value('hardPointClass', [
|
||||||
'Utility',
|
'Utility',
|
||||||
@@ -146,7 +146,7 @@ angular.module('shipyard', ['ngLodash'])
|
|||||||
},
|
},
|
||||||
{ // 8
|
{ // 8
|
||||||
title: 'Power',
|
title: 'Power',
|
||||||
props: ['powerRetracted','powerDeployed','powerAvailable'],
|
props: ['powerRetracted', 'powerDeployed', 'powerAvailable'],
|
||||||
lbls: ['Retracted', 'Deployed', 'Available'],
|
lbls: ['Retracted', 'Deployed', 'Available'],
|
||||||
unit: 'MW',
|
unit: 'MW',
|
||||||
fmt: 'fPwr'
|
fmt: 'fPwr'
|
||||||
@@ -163,7 +163,7 @@ angular.module('shipyard', ['ngLodash'])
|
|||||||
lbls: ['Unladen', 'Laden'],
|
lbls: ['Unladen', 'Laden'],
|
||||||
unit: 'LY',
|
unit: 'LY',
|
||||||
fmt: 'fRound'
|
fmt: 'fRound'
|
||||||
},
|
}
|
||||||
])
|
])
|
||||||
/**
|
/**
|
||||||
* Calculate the maximum single jump range based on mass and a specific FSD
|
* Calculate the maximum single jump range based on mass and a specific FSD
|
||||||
@@ -174,7 +174,7 @@ angular.module('shipyard', ['ngLodash'])
|
|||||||
* @return {number} Distance in Light Years
|
* @return {number} Distance in Light Years
|
||||||
*/
|
*/
|
||||||
.value('calcJumpRange', function(mass, fsd, fuel) {
|
.value('calcJumpRange', function(mass, fsd, fuel) {
|
||||||
return Math.pow(Math.min(fuel === undefined? fsd.maxfuel : fuel, fsd.maxfuel) / fsd.fuelmul, 1 / fsd.fuelpower ) * fsd.optmass / mass;
|
return Math.pow(Math.min(fuel === undefined ? fsd.maxfuel : fuel, fsd.maxfuel) / fsd.fuelmul, 1 / fsd.fuelpower ) * fsd.optmass / mass;
|
||||||
})
|
})
|
||||||
/**
|
/**
|
||||||
* Calculate the a ships shield strength based on mass, shield generator and shield boosters used.
|
* Calculate the a ships shield strength based on mass, shield generator and shield boosters used.
|
||||||
@@ -186,7 +186,7 @@ angular.module('shipyard', ['ngLodash'])
|
|||||||
* @param {number} multiplier Shield multiplier for ship (1 + shield boosters if any)
|
* @param {number} multiplier Shield multiplier for ship (1 + shield boosters if any)
|
||||||
* @return {number} Approximate shield strengh in MJ
|
* @return {number} Approximate shield strengh in MJ
|
||||||
*/
|
*/
|
||||||
.value('calcShieldStrength', function (mass, shields, sg, multiplier) {
|
.value('calcShieldStrength', function(mass, shields, sg, multiplier) {
|
||||||
if (!sg) {
|
if (!sg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
angular.module('shipyard').service('Components', ['lodash', 'ComponentsDB', 'ShipsDB', 'ComponentSet', function (_, C, Ships, ComponentSet) {
|
angular.module('shipyard').service('Components', ['lodash', 'ComponentsDB', 'ShipsDB', 'ComponentSet', function(_, C, Ships, ComponentSet) {
|
||||||
|
|
||||||
this.cargoScoop = function() {
|
this.cargoScoop = function() {
|
||||||
return { name: 'Cargo Hatch', class: 1, rating: 'H', power: 0.6};
|
return { name: 'Cargo Hatch', class: 1, rating: 'H', power: 0.6 };
|
||||||
};
|
};
|
||||||
|
|
||||||
this.common = function (typeIndex, componentId) {
|
this.common = function(typeIndex, componentId) {
|
||||||
return C.common[typeIndex][componentId];
|
return C.common[typeIndex][componentId];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ angular.module('shipyard').service('Components', ['lodash', 'ComponentsDB', 'Shi
|
|||||||
for (var n in C.hardpoints) {
|
for (var n in C.hardpoints) {
|
||||||
var group = C.hardpoints[n];
|
var group = C.hardpoints[n];
|
||||||
for (var i = 0; i < group.length; i++) {
|
for (var i = 0; i < group.length; i++) {
|
||||||
if (group[i].id == id) {
|
if (group[i].id === id) {
|
||||||
return group[i];
|
return group[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ angular.module('shipyard').service('Components', ['lodash', 'ComponentsDB', 'Shi
|
|||||||
for (var n in C.internal) {
|
for (var n in C.internal) {
|
||||||
var group = C.internal[n];
|
var group = C.internal[n];
|
||||||
for (var i = 0; i < group.length; i++) {
|
for (var i = 0; i < group.length; i++) {
|
||||||
if (group[i].id == id) {
|
if (group[i].id === id) {
|
||||||
return group[i];
|
return group[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,9 +49,9 @@ angular.module('shipyard').service('Components', ['lodash', 'ComponentsDB', 'Shi
|
|||||||
* @param {string} shipId Unique ship Id/Key
|
* @param {string} shipId Unique ship Id/Key
|
||||||
* @return {ComponentSet} The set of components the ship can install
|
* @return {ComponentSet} The set of components the ship can install
|
||||||
*/
|
*/
|
||||||
this.forShip = function (shipId) {
|
this.forShip = function(shipId) {
|
||||||
var ship = Ships[shipId];
|
var ship = Ships[shipId];
|
||||||
return new ComponentSet(C, ship.properties.mass + 5, ship.slots.common, ship.slots.internal[0], ship.slots.hardpoints[0]);
|
return new ComponentSet(C, ship.properties.mass + 5, ship.slots.common, ship.slots.internal[0], ship.slots.hardpoints[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
Reference in New Issue
Block a user