Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Commit

Permalink
JShint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin McLeod committed Apr 17, 2015
1 parent acffdd1 commit 0d2fd28
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 48 deletions.
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app/js/db.js
6 changes: 3 additions & 3 deletions app/js/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
angular.module('app', ['ngRoute','shipyard','ngLodash','app.templates'])
.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
.config(['$routeProvider', function($routeProvider) {
//$locationProvider.html5Mode(true);
$routeProvider
.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) {
Expand All @@ -23,7 +23,7 @@ angular.module('app', ['ngRoute','shipyard','ngLodash','app.templates'])
$rootScope.fPct = d3.format(',.2%');

$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
Expand Down
4 changes: 2 additions & 2 deletions app/js/controllers/controller-ship.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ angular.module('app')
$scope.availCS = Components.forShip($scope.shipId);

// for debugging
window.ship = $scope.ship;
window.availcs = $scope.availCS;
//window.ship = $scope.ship;
//window.availcs = $scope.availCS;
}]);
4 changes: 2 additions & 2 deletions app/js/controllers/controller-shipyard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('app')
.controller('ShipyardController', ['$rootScope', '$scope', function ($rootScope, $scope) {
.controller('ShipyardController', function () {

}]);
});
9 changes: 3 additions & 6 deletions app/js/directives/directive-list-cost.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
angular.module('app').directive('costList', ['$rootScope', 'lodash', function ($r, _) {
angular.module('app').directive('costList', ['$rootScope', function ($r) {
return {
restrict: 'A',
scope: {
ship: '='
},
templateUrl: 'views/costs.html',
link: function (scope, element, attributes) {
scope.hps = ship.hardpoints;
scope.ints = ship.internal;
scope.com = ship.common;
link: function (scope) {
scope.$r = $r;
scope.insuranceOptions = {
Alpha: 0.975,
Expand All @@ -20,7 +17,7 @@ angular.module('app').directive('costList', ['$rootScope', 'lodash', function ($
scope.toggle = function(item) {
item.incCost = !item.incCost;
scope.ship.updateTotals();
}
};
}
};
}]);
6 changes: 3 additions & 3 deletions app/js/directives/directive-list-power.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
angular.module('app')
.directive('powerList', ['$rootScope', 'lodash', function ($r, _) {
.directive('powerList', ['$rootScope', function ($r) {
return {
restrict: 'A',
scope: {
ship: '=ship'
},
templateUrl: 'views/power.html',
link: function (scope, element, attributes) {
link: function (scope) {
scope.$r = $r;

scope.toggle = function(slot) {
slot.enabled = !slot.enabled;
scope.ship.updateTotals();
}
};
}
};
}]);
6 changes: 3 additions & 3 deletions app/js/directives/directive-menu.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
angular.module('app').directive('shipyardMenu', ['$rootScope', 'lodash', function ($rootScope, _) {
angular.module('app').directive('shipyardMenu', function () {

return {
restrict: 'E',
templateUrl: 'views/menu.html',
link: function (scope, element, attributes) {
link: function () {

// TODO: Saved Ships: load, save, save as, delete, export
// TODO: Links: github, forum, etc

}
};
}]);
});
55 changes: 31 additions & 24 deletions app/js/shipyard/factory-ship.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
this.id = id;
this.defaults = shipData.defaultComponents;
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){
if(typeof o != 'object') {
Expand All @@ -25,7 +26,7 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
maxClass: arr[i]
});
}
}.bind(this))
}.bind(this));
}
}.bind(this));
}
Expand Down Expand Up @@ -55,29 +56,30 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
var availCommon = DB.components.common;
var availHardPoints = DB.components.hardpoints;
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] };

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].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) {
hps[i].id = 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) {
internal[i].id = comps.internal[i];
internal[i].c = availInternal[comps.internal[i]];
}
}
this.updateTotals();
}
};

/**
* Serializes the selected components for all slots to a URL friendly string.
Expand All @@ -103,7 +105,7 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
* @return {string} The id of the selected component or '-' if none selected
*/
function idToStr(slot) {
return o.id === undefined? '-' : o.id;
return slot.id === undefined? '-' : slot.id;
}

/**
Expand All @@ -128,17 +130,17 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
if (c < commonCount) {
comps.common[c] = code.substring(i, i + 2);
} else if (c < hpCount) {
comps.hardpoints[c - commonCount] = code.substring(i, i + 2)
comps.hardpoints[c - commonCount] = code.substring(i, i + 2);
} else {
comps.internal[c - hpCount] = code.substring(i, i + 2)
comps.internal[c - hpCount] = code.substring(i, i + 2);
}
i++;
}
c++;
}

this.defaults = comps;
this.buildWidth(data);
this.buildWidth(comps);
};

/**
Expand All @@ -159,32 +161,37 @@ angular.module('shipyard').factory('ShipFactory', ['components', 'lodash', funct
this.powerDeployed = this.powerRetracted + h.power;

// 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.armorTotal = this.armourAdded + this.armour;

}
};

/**
* 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.
*
* @param {object} slot The component slot
* @param {string} id Unique ID for the selected component
* @param {object} componentData Properties for the selected component
* @param {object} slot The component slot
* @param {string} id Unique ID for the selected component
* @param {object} component Properties for the selected component
*/
Ship.prototype.use = function(slot, id, componentData) {
if (slot.id != id) { // Selecting a different option
Ship.prototype.use = function(slot, id, component) {
if (slot.id != id) { // Selecting a different component
slot.id = id;
slot.c = componentData;
slot.c = component;

// New componnent is a Shield Generator
if(componentData.group == 'sg') {
// Selected componnent is a Shield Generator
if(component.group == 'sg') {
var slotIndex = this.internal.indexOf(slot);
// You can only have one shield Generator
// TODO: find shield generator that is not this one
// set c.id = null, c.c = null;
if (this.sgSI !== null && this.sgSI != slotIndex) {
// 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 {
// Deselect current component
slot.id = null;
slot.c = null;
}
Expand Down Expand Up @@ -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.maxmul;
};
}

/**
* Utilify function for summing the components properties
Expand Down
4 changes: 0 additions & 4 deletions app/js/shipyard/module-shipyard.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ angular.module('shipyard', [])
case 'u':
l.push('Utility');
break;
default:
console.error('Invalid group size', grp);
}
switch(a[1]) {
case 'o':
Expand All @@ -91,8 +89,6 @@ angular.module('shipyard', [])
case 'm':
l.push('Mount');
break;
default:
console.error('Invalid group category', grp);
}
return l.join(' ');
}
Expand Down
8 changes: 7 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ gulp.task('less', function() {

gulp.task('lint', function() {
return gulp.src('app/js/**/*.js')
.pipe(jshint())
.pipe(jshint({
undef: true,
unused: true,
curly: true,
predef: [ "angular",'DB','d3' ]
}))
.pipe(jshint.reporter('default'));
});

Expand Down Expand Up @@ -121,6 +126,7 @@ gulp.task('watch', function() {
gulp.watch('app/less/*.less', ['less']);
gulp.watch('app/views/**/*', ['html2js']);
gulp.watch('app/js/**/*.js', ['js']);
gulp.watch('data/**/*.json', ['jsonToDB']);
});

gulp.task('clean', function (done) { del(['build'], done); });
Expand Down

0 comments on commit 0d2fd28

Please sign in to comment.