From 707ce88d0ce48fb6460256d41209aa3aae3609b3 Mon Sep 17 00:00:00 2001 From: amki Date: Wed, 22 Jul 2020 20:14:21 +0200 Subject: [PATCH] Fetch events nao --- cd.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++++------ index.html | 5 ++++ 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/cd.js b/cd.js index 9dd3193..946f828 100644 --- a/cd.js +++ b/cd.js @@ -1,5 +1,8 @@ -const fflog = "https://www.fflogs.com:443/v1/report/fights/"; +const fflogsBase = "https://www.fflogs.com:443/v1/report/"; +const fflogsFightsAPI = fflogsBase + "fights/" +const fflogsEventsAPI = fflogsBase + "events/" const api = "?api_key="; +// ?end=1591130148287&sourceid=5 var indexViewModel; var classColors = { @@ -20,6 +23,9 @@ var classColors = { "Dancer": "#ceb8ab", "Machinist": "#6c6433", "Barde": "#6d8432" +}; + +var offensiveCooldowns = { }; @@ -32,6 +38,8 @@ $(() => { self.logID = ko.observable(localStorage.getItem("fflogid")); self.fights = ko.observableArray(); self.friendlies = ko.observableArray(); + self.enemies = ko.observableArray(); + self.casts = ko.observableArray(); self.displayFightPicker = ko.observable(false); self.selectedFight = ko.observable(); @@ -40,6 +48,7 @@ $(() => { self.fights(log["fights"]); self.friendlies(log["friendlies"]); + self.enemies(log["enemies"]); self.displayFightPicker(true); }; @@ -56,24 +65,74 @@ $(() => { localStorage.setItem("fflogid", self.logID()); }; - self.fightChanged = function() { - console.log("Fight has changed to ",self.selectedFight()); + self.fightChanged = async function() { + console.log("Fight has changed to ",self.selectedFight()); + var casts = await fetchCasts(self.selectedFight()); + + self.casts(casts); + console.log("self",self.casts()); }; self.textColor = function(job) { console.log(job.type) return classColors[job.type]; - } + }; + + self.actorIDToName = function(id) { + for(var actor of self.friendlies()) { + if(id == actor.id) { + return actor.name; + } + } + for(var actor of self.enemies()) { + if(id == actor.id) { + return actor.name; + } + } + return null; + }; }; indexViewModel = new IndexViewModel(); ko.applyBindings(indexViewModel); }); +async function fetchCasts(fight) { + let baseUrl = fflogsEventsAPI + "casts/" + indexViewModel.logID() + api + indexViewModel.apiKey() + "&translate=true" + "&end=" + fight.end_time; + let start_time = fight.start_time; + let result = []; + + let snip = {}; + do { + let url = baseUrl + "&start=" + start_time; + console.log("Requesting "+url); + snip = await fetchCastSnippet(url); + for(var e of snip.events) { + result.push(e); + } + //result = result.concat(snip.events); + start_time = snip.nextPageTimestamp; + } while(snip.nextPageTimestamp) + + return result; +} + +async function fetchCastSnippet(url) { + var res = await fetch(url); + if (!res.ok) { + console.log(res); + throw Error(res.text); + } + var casts = await res.json(); + + console.log(casts); + return casts; +} + // API request um JSON zu erhalten -async function fetchLog(fightId) { - let url = fflog + fightId + api + indexViewModel.apiKey(); +async function fetchLog(logId) { + let url = fflogsFightsAPI + logId + api + indexViewModel.apiKey(); - console.log("Fetching log "+fightId); + console.log("Requesting "+logId); var res = await fetch(url); if (!res.ok) { console.log(res); @@ -84,4 +143,4 @@ async function fetchLog(fightId) { //get specific fight data console.log(log); return log; -} \ No newline at end of file +} diff --git a/index.html b/index.html index 19205a8..2f33f62 100644 --- a/index.html +++ b/index.html @@ -47,6 +47,11 @@ +
+
+
+
+