Skip to content

Commit 1c12808

Browse files
committed
Merge pull request dsjoerg#22 from nickelsen/fix-lotv-army-chart
Fix time on lotv army chart.
2 parents 38debcb + a3ae4ff commit 1c12808

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

app/assets/javascripts/angular/controllers/match.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function($scope, $window, $route, $location, $element, Match) {
4444
// console.log("matchscope", $scope);
4545
$scope.$watch('current_frame', function(v) {
4646
if(v) {
47-
$scope.current_time = Sc2.frameToTime(v);
47+
$scope.current_time = Sc2.frameToTime(v, $scope.match.expansion);
4848
$scope.time_has_been_set = true
4949
}
5050
});

app/assets/javascripts/angular/directives/armychart.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ gg.directive('armychart', ['$location', '$timeout', function($location, $timeout
115115
scope.freeze = function(frame, updateURL) {
116116
switch(typeof frame) {
117117
case "number": frame = frame; break;
118-
case "string": frame = Sc2.timeToFrame(frame); break;
118+
case "string": frame = Sc2.timeToFrame(frame, scope.match.expansion); break;
119119
default: return false;
120120
}
121121

@@ -162,7 +162,7 @@ gg.directive('armychart', ['$location', '$timeout', function($location, $timeout
162162
if(typeof e == "number") {
163163
frame = e;
164164
} else if(typeof e == "string") {
165-
frame = Sc2.timeToFrame(e);
165+
frame = Sc2.timeToFrame(e, scope.match.expansion);
166166
} else {
167167
// If clicked on the background, we have xAxis on the event, if clicked
168168
// on a series, we'll have the point.

app/assets/javascripts/angular/helpers/sc2.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,13 @@ for (var expansion_tag in Sc2.armyUnits) {
258258

259259
// I'd rather stuff these here, than in Match
260260

261-
Sc2.frameToTime = function(frame) {
262-
minute = Math.floor(frame / (60 * 16));
263-
second = Math.floor((frame / 16) % 60).toString();
261+
Sc2.frameToTime = function(frame, expansion) {
262+
fps = 16;
263+
if (expansion >= 2) {
264+
fps *= 1.4;
265+
}
266+
minute = Math.floor(frame / (60 * fps));
267+
second = Math.floor((frame / fps) % 60).toString();
264268
if (second.length < 2) {
265269
second = "0" + second;
266270
}
@@ -271,7 +275,11 @@ Sc2.timeToFrame = function(time) {
271275
parts = time.split(':');
272276
seconds = parseInt(parts[parts.length-1]);
273277
minutes = parseInt(parts[parts.length-2]);
274-
frame = ((minutes*60) + seconds) * 16;
278+
fps = 16;
279+
if (expansion >= 2) {
280+
fps *= 1.4;
281+
}
282+
frame = ((minutes*60) + seconds) * fps;
275283
return frame;
276284
}
277285

0 commit comments

Comments
 (0)