Last active
December 23, 2015 19:59
-
-
Save dduleone/6686193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var app = angular.module('selfTrickleCalculator'); | |
app.factory('TrickleCalcAPI', function () { | |
return { | |
link: null, | |
moa: null, | |
time: { | |
launch: null, | |
land: null | |
}, | |
unitType: null, | |
setLink: function (l) { | |
this.link = l; | |
}, | |
setMoa: function (tf) { | |
this.moa = tf; | |
}, | |
setTime: function (timeSlot, time) { | |
this.time[timeSlot] = time; | |
}, | |
setLaunchTime: function (lt) { | |
this.time.launch = lt; | |
}, | |
setLandTime: function (lt) { | |
this.time.land = lt; | |
}, | |
setUnitType: function (ut) { | |
this.unitType = ut; | |
}, | |
_troopSpeed: { | |
'sp': 700, | |
'sw': 800, | |
'ar': 500, | |
'xb': 600, | |
'ah': 300, | |
'lh': 400, | |
'hc': 800, | |
'ox': 1000 | |
}, | |
getSpeed: function () { | |
var mod = 1; | |
if(this.moa){ | |
mod = .95; | |
} | |
return this._troopSpeed[this.unitType] * mod; | |
}, | |
getTimeWindow: function () { | |
var timeWindow = this.time.land.unix() - this.time.launch.unix(); | |
//console.log("Time Window: ", timeWindow); | |
return timeWindow; | |
}, | |
findDistance: function () { | |
var win = this.getTimeWindow(); | |
var min = (win - (5*60)) / 2; | |
var max = (win + (5*60)) / 2; | |
var speed = this.getSpeed(); | |
var dist = 1; | |
while ( (speed * dist) < max ) { | |
if ( (speed * dist) > min ) { | |
return dist; | |
} | |
dist++; | |
} | |
return false; | |
} | |
}; | |
}); | |
app.controller('MainCtrl', function ($scope, TrickleCalcAPI) { | |
$scope.findTargets = function () { | |
console.log("Finding Targets..."); | |
console.log("TrickleCalcAPI:", TrickleCalcAPI); | |
console.log("Time Window:", TrickleCalcAPI.getTimeWindow()); | |
console.log("Distance:", TrickleCalcAPI.findDistance()); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment