JShint fixes

This commit is contained in:
Colin McLeod
2015-04-16 20:44:27 -07:00
parent acffdd1f4b
commit 0d2fd2804f
10 changed files with 55 additions and 48 deletions

1
.jshintignore Normal file
View File

@@ -0,0 +1 @@
app/js/db.js

View File

@@ -1,9 +1,9 @@
angular.module('app', ['ngRoute','shipyard','ngLodash','app.templates']) angular.module('app', ['ngRoute','shipyard','ngLodash','app.templates'])
.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) { .config(['$routeProvider', function($routeProvider) {
//$locationProvider.html5Mode(true); //$locationProvider.html5Mode(true);
$routeProvider $routeProvider
.when('/:ship', { templateUrl: 'views/ship.html', controller: 'ShipController' }) .when('/:ship', { templateUrl: 'views/ship.html', controller: 'ShipController' })
.when('/', { templateUrl: 'views/ships.html', controller: 'ShipyardController' }) .when('/', { templateUrl: 'views/ships.html', controller: 'ShipyardController' });
}]) }])
.run(['$rootScope','commonArray','shipPurpose', 'shipSize', 'hardPointClass', 'internalGroupMap', function ($rootScope, CArr, shipPurpose, sz, hpc, igMap) { .run(['$rootScope','commonArray','shipPurpose', 'shipSize', 'hardPointClass', 'internalGroupMap', function ($rootScope, CArr, shipPurpose, sz, hpc, igMap) {
@@ -23,7 +23,7 @@ angular.module('app', ['ngRoute','shipyard','ngLodash','app.templates'])
$rootScope.fPct = d3.format(',.2%'); $rootScope.fPct = d3.format(',.2%');
$rootScope.calcJumpRange = function(mass, fsd, fuel) { $rootScope.calcJumpRange = function(mass, fsd, fuel) {
return Math.pow( (fuel || fsd.maxfuel) / fds.fuelmul, 1 / fsd.fuelpower ) * fsd.optmass / mass; return Math.pow( (fuel || fsd.maxfuel) / fsd.fuelmul, 1 / fsd.fuelpower ) * fsd.optmass / mass;
}; };
// TODO: Load Saved Ships List from Local Storage // TODO: Load Saved Ships List from Local Storage

View File

@@ -5,6 +5,6 @@ angular.module('app')
$scope.availCS = Components.forShip($scope.shipId); $scope.availCS = Components.forShip($scope.shipId);
// for debugging // for debugging
window.ship = $scope.ship; //window.ship = $scope.ship;
window.availcs = $scope.availCS; //window.availcs = $scope.availCS;
}]); }]);

View File

@@ -1,4 +1,4 @@
angular.module('app') angular.module('app')
.controller('ShipyardController', ['$rootScope', '$scope', function ($rootScope, $scope) { .controller('ShipyardController', function () {
}]); });

View File

@@ -1,14 +1,11 @@
angular.module('app').directive('costList', ['$rootScope', 'lodash', function ($r, _) { angular.module('app').directive('costList', ['$rootScope', function ($r) {
return { return {
restrict: 'A', restrict: 'A',
scope: { scope: {
ship: '=' ship: '='
}, },
templateUrl: 'views/costs.html', templateUrl: 'views/costs.html',
link: function (scope, element, attributes) { link: function (scope) {
scope.hps = ship.hardpoints;
scope.ints = ship.internal;
scope.com = ship.common;
scope.$r = $r; scope.$r = $r;
scope.insuranceOptions = { scope.insuranceOptions = {
Alpha: 0.975, Alpha: 0.975,
@@ -20,7 +17,7 @@ angular.module('app').directive('costList', ['$rootScope', 'lodash', function ($
scope.toggle = function(item) { scope.toggle = function(item) {
item.incCost = !item.incCost; item.incCost = !item.incCost;
scope.ship.updateTotals(); scope.ship.updateTotals();
} };
} }
}; };
}]); }]);

View File

@@ -1,18 +1,18 @@
angular.module('app') angular.module('app')
.directive('powerList', ['$rootScope', 'lodash', function ($r, _) { .directive('powerList', ['$rootScope', function ($r) {
return { return {
restrict: 'A', restrict: 'A',
scope: { scope: {
ship: '=ship' ship: '=ship'
}, },
templateUrl: 'views/power.html', templateUrl: 'views/power.html',
link: function (scope, element, attributes) { link: function (scope) {
scope.$r = $r; scope.$r = $r;
scope.toggle = function(slot) { scope.toggle = function(slot) {
slot.enabled = !slot.enabled; slot.enabled = !slot.enabled;
scope.ship.updateTotals(); scope.ship.updateTotals();
} };
} }
}; };
}]); }]);

View File

@@ -1,13 +1,13 @@
angular.module('app').directive('shipyardMenu', ['$rootScope', 'lodash', function ($rootScope, _) { angular.module('app').directive('shipyardMenu', function () {
return { return {
restrict: 'E', restrict: 'E',
templateUrl: 'views/menu.html', templateUrl: 'views/menu.html',
link: function (scope, element, attributes) { link: function () {
// TODO: Saved Ships: load, save, save as, delete, export // TODO: Saved Ships: load, save, save as, delete, export
// TODO: Links: github, forum, etc // TODO: Links: github, forum, etc
} }
}; };
}]); });

View File

@@ -10,7 +10,8 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
this.id = id; this.id = id;
this.defaults = shipData.defaultComponents; this.defaults = shipData.defaultComponents;
this.incCost = true; this.incCost = true;
this.cargoScoop = { enabled: true, c: { name: 'Cargo Scoop', class: 1, rating: 'H', power: .6} }; this.cargoScoop = { enabled: true, c: { name: 'Cargo Scoop', class: 1, rating: 'H', power: 0.6} };
this.sgSI = null; // Shield Generator Slot Index
angular.forEach(shipData,function(o,k){ angular.forEach(shipData,function(o,k){
if(typeof o != 'object') { if(typeof o != 'object') {
@@ -25,7 +26,7 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
maxClass: arr[i] maxClass: arr[i]
}); });
} }
}.bind(this)) }.bind(this));
} }
}.bind(this)); }.bind(this));
} }
@@ -55,29 +56,30 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
var availCommon = DB.components.common; var availCommon = DB.components.common;
var availHardPoints = DB.components.hardpoints; var availHardPoints = DB.components.hardpoints;
var availInternal = DB.components.internal; var availInternal = DB.components.internal;
var i,l;
this.bulkheads = { incCost: true, id: comps.bulkheads || 0, c: DB.components.bulkheads[this.id][comps.bulkheads || 0] }; this.bulkheads = { incCost: true, id: comps.bulkheads || 0, c: DB.components.bulkheads[this.id][comps.bulkheads || 0] };
for(var i = 0, l = comps.common.length; i < l; i++) { for(i = 0, l = comps.common.length; i < l; i++) {
common[i].id = comps.common[i]; common[i].id = comps.common[i];
common[i].c = availCommon[i][comps.common[i]]; common[i].c = availCommon[i][comps.common[i]];
} }
for(var i = 0, l = comps.hardpoints.length; i < l; i++) { for(i = 0, l = comps.hardpoints.length; i < l; i++) {
if(comps.hardpoints[i] !== 0) { if(comps.hardpoints[i] !== 0) {
hps[i].id = comps.hardpoints[i]; hps[i].id = comps.hardpoints[i];
hps[i].c = availHardPoints[comps.hardpoints[i]]; hps[i].c = availHardPoints[comps.hardpoints[i]];
} }
} }
for(var i = 0, l = comps.internal.length; i < l; i++) { for(i = 0, l = comps.internal.length; i < l; i++) {
if(comps.internal[i] !== 0) { if(comps.internal[i] !== 0) {
internal[i].id = comps.internal[i]; internal[i].id = comps.internal[i];
internal[i].c = availInternal[comps.internal[i]]; internal[i].c = availInternal[comps.internal[i]];
} }
} }
this.updateTotals(); this.updateTotals();
} };
/** /**
* Serializes the selected components for all slots to a URL friendly string. * Serializes the selected components for all slots to a URL friendly string.
@@ -103,7 +105,7 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
* @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 idToStr(slot) { function idToStr(slot) {
return o.id === undefined? '-' : o.id; return slot.id === undefined? '-' : slot.id;
} }
/** /**
@@ -128,9 +130,9 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
if (c < commonCount) { if (c < commonCount) {
comps.common[c] = code.substring(i, i + 2); comps.common[c] = code.substring(i, i + 2);
} else if (c < hpCount) { } else if (c < hpCount) {
comps.hardpoints[c - commonCount] = code.substring(i, i + 2) comps.hardpoints[c - commonCount] = code.substring(i, i + 2);
} else { } else {
comps.internal[c - hpCount] = code.substring(i, i + 2) comps.internal[c - hpCount] = code.substring(i, i + 2);
} }
i++; i++;
} }
@@ -138,7 +140,7 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
} }
this.defaults = comps; this.defaults = comps;
this.buildWidth(data); this.buildWidth(comps);
}; };
/** /**
@@ -159,32 +161,37 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
this.powerDeployed = this.powerRetracted + h.power; this.powerDeployed = this.powerRetracted + h.power;
// TODO: range // TODO: range
this.calcShieldStrength = this.sgSI !== null? calcShieldStrength(this.mass, this.shields, this.internal[this.sgSI], 1) : 0;
this.armourAdded = 0; // internal.armoradd TODO: Armour (reinforcement, bulkheads) this.armourAdded = 0; // internal.armoradd TODO: Armour (reinforcement, bulkheads)
this.armorTotal = this.armourAdded + this.armour; this.armorTotal = this.armourAdded + this.armour;
};
}
/** /**
* Update a slot with a the component if the id is different from the current id for this slot. * Update a slot with a the component if the id is different from the current id for this slot.
* Frees the slot of the current component if the id matches the current id for the slot. * Frees the slot of the current component if the id matches the current id for the slot.
* *
* @param {object} slot The component slot * @param {object} slot The component slot
* @param {string} id Unique ID for the selected component * @param {string} id Unique ID for the selected component
* @param {object} componentData Properties for the selected component * @param {object} component Properties for the selected component
*/ */
Ship.prototype.use = function(slot, id, componentData) { Ship.prototype.use = function(slot, id, component) {
if (slot.id != id) { // Selecting a different option if (slot.id != id) { // Selecting a different component
slot.id = id; slot.id = id;
slot.c = componentData; slot.c = component;
// New componnent is a Shield Generator // Selected componnent is a Shield Generator
if(componentData.group == 'sg') { if(component.group == 'sg') {
var slotIndex = this.internal.indexOf(slot);
// You can only have one shield Generator // You can only have one shield Generator
// TODO: find shield generator that is not this one if (this.sgSI !== null && this.sgSI != slotIndex) {
// set c.id = null, c.c = null; // A shield generator is already selected in a different slot
this.internal[this.sgSI].id = null;
this.internal[this.sgSI].c = null;
}
this.sgSI = slotIndex;
} }
// Deselecting current option
} else { } else {
// Deselect current component
slot.id = null; slot.id = null;
slot.c = null; slot.c = null;
} }
@@ -212,7 +219,7 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
return shields * multiplier * (sg.optmul + (mass - sg.optmass) / (sg.maxmass - sg.optmass) * (sg.maxmul - sg.optmul)); return shields * multiplier * (sg.optmul + (mass - sg.optmass) / (sg.maxmass - sg.optmass) * (sg.maxmul - sg.optmul));
} }
return shields * multiplier * sg.maxmul; return shields * multiplier * sg.maxmul;
}; }
/** /**
* Utilify function for summing the components properties * Utilify function for summing the components properties

View File

@@ -69,8 +69,6 @@ angular.module('shipyard', [])
case 'u': case 'u':
l.push('Utility'); l.push('Utility');
break; break;
default:
console.error('Invalid group size', grp);
} }
switch(a[1]) { switch(a[1]) {
case 'o': case 'o':
@@ -91,8 +89,6 @@ angular.module('shipyard', [])
case 'm': case 'm':
l.push('Mount'); l.push('Mount');
break; break;
default:
console.error('Invalid group category', grp);
} }
return l.join(' '); return l.join(' ');
} }

View File

@@ -23,7 +23,12 @@ gulp.task('less', function() {
gulp.task('lint', function() { gulp.task('lint', function() {
return gulp.src('app/js/**/*.js') return gulp.src('app/js/**/*.js')
.pipe(jshint()) .pipe(jshint({
undef: true,
unused: true,
curly: true,
predef: [ "angular",'DB','d3' ]
}))
.pipe(jshint.reporter('default')); .pipe(jshint.reporter('default'));
}); });
@@ -121,6 +126,7 @@ gulp.task('watch', function() {
gulp.watch('app/less/*.less', ['less']); gulp.watch('app/less/*.less', ['less']);
gulp.watch('app/views/**/*', ['html2js']); gulp.watch('app/views/**/*', ['html2js']);
gulp.watch('app/js/**/*.js', ['js']); gulp.watch('app/js/**/*.js', ['js']);
gulp.watch('data/**/*.json', ['jsonToDB']);
}); });
gulp.task('clean', function (done) { del(['build'], done); }); gulp.task('clean', function (done) { del(['build'], done); });