|
@ -33,23 +33,34 @@ var trackedCooldowns = { |
|
|
|
|
|
|
|
|
// Do stuff when HTML parsing is ready
|
|
|
// Do stuff when HTML parsing is ready
|
|
|
$(() => { |
|
|
$(() => { |
|
|
ko.bindingHandlers.foreachprop = { |
|
|
ko.components.register('fight-timeline', { |
|
|
transformObject: function (obj) { |
|
|
viewModel: function(params) { |
|
|
var properties = []; |
|
|
var self = this; |
|
|
ko.utils.objectForEach(obj, function (key, value) { |
|
|
// Data: value is either null, 'like', or 'dislike'
|
|
|
properties.push({ key: key, value: value }); |
|
|
this.fight = params.value.fight(); |
|
|
}); |
|
|
this.actors = params.value.actors; |
|
|
return properties; |
|
|
console.log("fight-timeline: Got ",params.value); |
|
|
|
|
|
|
|
|
|
|
|
// Behaviors
|
|
|
|
|
|
self.calculateDivStyle = function(timestamp, ability) { |
|
|
|
|
|
var fight_length = self.fight.end_time - self.fight.start_time; |
|
|
|
|
|
console.log("Fight was "+fight_length); |
|
|
|
|
|
var cooldown = window.trackedCooldowns[ability.guid].cooldown; |
|
|
|
|
|
console.log("Use was at "+timestamp+" and cd is "+cooldown); |
|
|
|
|
|
var startpct = timestamp / fight_length * 100; |
|
|
|
|
|
var widthpct = cooldown / fight_length * 100; |
|
|
|
|
|
console.log("Cooldown started at "+startpct+"% and endured "+widthpct+"%"); |
|
|
|
|
|
var res = {color: "teal", "margin-left": startpct+"%", width:widthpct+"%"}; |
|
|
|
|
|
return res; |
|
|
|
|
|
}; |
|
|
}, |
|
|
}, |
|
|
init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { |
|
|
template: |
|
|
var properties = ko.pureComputed(function () { |
|
|
'<div class="timeline-container" data-bind="foreach: actors">\ |
|
|
var obj = ko.utils.unwrapObservable(valueAccessor()); |
|
|
<!-- ko foreach: trackedEvents -->\ |
|
|
return ko.bindingHandlers.foreachprop.transformObject(obj); |
|
|
<span class="timeline-used" data-bind="style: $component.calculateDivStyle(timestamp, ability)"><span data-bind="text: ability.name"></span></span>\ |
|
|
|
|
|
<!-- /ko -->\ |
|
|
|
|
|
</div>' |
|
|
}); |
|
|
}); |
|
|
ko.applyBindingsToNode(element, { foreach: properties }, bindingContext); |
|
|
|
|
|
return { controlsDescendantBindings: true }; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
// Document is ready
|
|
|
// Document is ready
|
|
|
function IndexViewModel() { |
|
|
function IndexViewModel() { |
|
|
var self = this; |
|
|
var self = this; |
|
@ -71,8 +82,12 @@ $(() => { |
|
|
self.displayFightPicker(true); |
|
|
self.displayFightPicker(true); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
self.formatTime = function(fight) { |
|
|
self.formatFightTime = function(fight) { |
|
|
let secs = (fight.end_time - fight.start_time)/1000; |
|
|
return self.formatTime(fight.end_time - fight.start_time); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
self.formatTime = function(time) { |
|
|
|
|
|
let secs = time/1000; |
|
|
let mins = Math.floor(secs / 60); |
|
|
let mins = Math.floor(secs / 60); |
|
|
let rest = Math.floor(secs % 60); |
|
|
let rest = Math.floor(secs % 60); |
|
|
return mins+"m"+rest+"s"; |
|
|
return mins+"m"+rest+"s"; |
|
@ -106,9 +121,7 @@ $(() => { |
|
|
//FIXME: This is a hack, we should instead somehow update the trackedEvents observable so only this part is rerendered
|
|
|
//FIXME: This is a hack, we should instead somehow update the trackedEvents observable so only this part is rerendered
|
|
|
self.trackedActors([]); |
|
|
self.trackedActors([]); |
|
|
self.trackedActors(actors); |
|
|
self.trackedActors(actors); |
|
|
for(var actor of self.trackedActors()) { |
|
|
console.log("trackedActors: ",self.trackedActors()); |
|
|
console.log("tracked: ",actor.trackedEvents()); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
self.textColor = function(job) { |
|
|
self.textColor = function(job) { |
|
@ -167,6 +180,7 @@ async function filterEvents(fight, events) { |
|
|
actor.trackedEvents = ko.observableArray(); |
|
|
actor.trackedEvents = ko.observableArray(); |
|
|
result.push(actor); |
|
|
result.push(actor); |
|
|
} |
|
|
} |
|
|
|
|
|
event.timestamp = event.timestamp - fight.start_time; |
|
|
actor.trackedEvents.push(event); |
|
|
actor.trackedEvents.push(event); |
|
|
console.log(event); |
|
|
console.log(event); |
|
|
} |
|
|
} |
|
|