From 75bd3413bd6d152f92d5f2961fa36290f9e7591f Mon Sep 17 00:00:00 2001 From: NoLifeKing Date: Tue, 24 May 2022 14:08:59 +0200 Subject: [PATCH] feat: Added debug mode, to increase log verbosity --- gulpfile.js | 14 ++++----- src/scripts/destiny2/apiClient.tsx | 36 +++++++++++++---------- src/scripts/destiny2/goalItems.js | 13 ++++++-- src/scripts/eventEmitter.js | 5 ++-- src/scripts/react/MainWindow/Settings.tsx | 18 ++++++++++++ 5 files changed, 57 insertions(+), 29 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 8282baa..a5088ac 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -84,7 +84,7 @@ gulp.task("default", function () { "purge-unused-css", "fix-windows", "build-ts", - "minify-scripts", + //"minify-scripts", "fix-version", "build-archive" ) @@ -98,7 +98,7 @@ gulp.task("default", function () { "purge-unused-css", "fix-windows", "build-ts", - "minify-scripts", + //"minify-scripts", "fix-version", "build-archive" ) @@ -112,7 +112,7 @@ gulp.task("default", function () { "purge-unused-css", "fix-windows", "build-ts", - "minify-scripts", + //"minify-scripts", "fix-version", "build-archive" ) @@ -126,7 +126,7 @@ gulp.task("default", function () { "purge-unused-css", "fix-windows", "build-ts", - "minify-scripts", + //"minify-scripts", "fix-version", "build-archive" ) @@ -142,7 +142,7 @@ gulp.task("default", function () { "purge-unused-css", "fix-windows", "build-ts", - "minify-scripts", + //"minify-scripts", "fix-version", "build-archive" ) @@ -156,7 +156,7 @@ gulp.task("default", function () { "purge-unused-css", "fix-windows", "build-ts", - "minify-scripts", + //"minify-scripts", "fix-version", "build-archive" ) @@ -171,7 +171,7 @@ gulp.task( "purge-unused-css", "fix-windows", "build-ts", - "minify-scripts", + //"minify-scripts", "fix-version", "build-archive" ) diff --git a/src/scripts/destiny2/apiClient.tsx b/src/scripts/destiny2/apiClient.tsx index a2e8912..e4ccfab 100644 --- a/src/scripts/destiny2/apiClient.tsx +++ b/src/scripts/destiny2/apiClient.tsx @@ -904,24 +904,28 @@ export class DestinyApiClient { savedAmount = 0; log("CHARACTER-HISTORY", `Loading page ${page} (${historyActivityUrl})`); var history = await pluginClient.GET(historyActivityUrl, await getUserToken()); - - let data = JSON.parse(history.Result.content); - if (data.Response.activities) { - log("CHARACTER-HISTORY", `Got ${data.Response.activities.length} activities`); - for (let activity of data.Response.activities) { - if ((await db.getStorageItem("playerActivity", activity.activityDetails.instanceId)) === null) { - await db.setStorageItem("playerActivity", activity.activityDetails.instanceId, { - characterId: characterId, - activity: activity, - }); + try { + let data = JSON.parse(history.Result.content); + if (data.Response.activities) { + log("CHARACTER-HISTORY", `Got ${data.Response.activities.length} activities`); + for (let activity of data.Response.activities) { + if ((await db.getStorageItem("playerActivity", activity.activityDetails.instanceId)) === null) { + await db.setStorageItem("playerActivity", activity.activityDetails.instanceId, { + characterId: characterId, + activity: activity, + }); + } + savedAmount++; } - savedAmount++; + eventEmitter.emit("character-history-partial-loaded", { + membershipId, + characterId, + }); + log("CHARACTER-HISTORY", `Saved ${savedAmount} activities`); } - eventEmitter.emit("character-history-partial-loaded", { - membershipId, - characterId, - }); - log("CHARACTER-HISTORY", `Saved ${savedAmount} activities`); + } catch (e) { + log("CHARACTER-HISTORY", "Failed to load character history", e, history); + reject(history.Result.content); } page++; diff --git a/src/scripts/destiny2/goalItems.js b/src/scripts/destiny2/goalItems.js index 20e0512..15cbc61 100644 --- a/src/scripts/destiny2/goalItems.js +++ b/src/scripts/destiny2/goalItems.js @@ -67,6 +67,9 @@ export class Destiny2Goals { if (milestone.availableQuests && milestone.availableQuests.length > 0) { for (let quest of milestone.availableQuests) { + if (quest.tracked) { + milestoneDataItem.tracked = true; + } if (quest.status.started && !quest.status.completed) { if (quest.status.stepObjectives && quest.status.stepObjectives.length > 0) { for (let step of quest.status.stepObjectives) { @@ -158,7 +161,8 @@ export class Destiny2Goals { type: "bounty", inProgressValueStyle: 0, completedValueStyle: 0, - tracked: bounty.state == 2, + tracked: (bounty.state & 2) == 2, + state: bounty.state, }; if (typeof bounty.expirationDate !== "undefined") { @@ -229,7 +233,8 @@ export class Destiny2Goals { type: "quest", inProgressValueStyle: 0, completedValueStyle: 0, - tracked: instanceQuest.state == 2, + tracked: (instanceQuest.state & 2) == 2, + state: instanceQuest.state, }; if (typeof objective.completionValue !== "undefined") { @@ -272,7 +277,8 @@ export class Destiny2Goals { type: "quest", inProgressValueStyle: 0, completedValueStyle: 0, - tracked: uninstancedQuest.state == 2, + tracked: (uninstancedQuest.state & 2) == 2, + state: uninstancedQuest.state, }; if (typeof objective.completionValue !== "undefined") { @@ -328,6 +334,7 @@ export class Destiny2Goals { nextLevelAt: objective.completionValue, inProgressValueStyle: objective.objectiveInProgressValueStyle, completedValueStyle: objective.objectiveCompletedValueStyle, + state: characterRecord.state, }; characterRecords.push(characterRecordData); diff --git a/src/scripts/eventEmitter.js b/src/scripts/eventEmitter.js index 1dd88a7..da9b44e 100644 --- a/src/scripts/eventEmitter.js +++ b/src/scripts/eventEmitter.js @@ -4,8 +4,6 @@ export class EventEmitter { constructor() { this.eventListeners = []; - this.logArguments = false; - /** * Listen to an event sent from this event emitter * @param {String} eventName The event that you want to listen to @@ -22,7 +20,8 @@ export class EventEmitter { * @param {any} arguments */ this.emit = async function (eventName, ...params) { - if (this.logArguments) { + let logArguments = JSON.parse((await db.getItem("d2-debugmode")) ?? "false"); + if (logArguments) { log("EVENT:EMITTING", eventName, ...params); } else { log("EVENT:EMITTING", eventName); diff --git a/src/scripts/react/MainWindow/Settings.tsx b/src/scripts/react/MainWindow/Settings.tsx index 0393252..5bdd296 100644 --- a/src/scripts/react/MainWindow/Settings.tsx +++ b/src/scripts/react/MainWindow/Settings.tsx @@ -43,6 +43,12 @@ export function Settings() { await db.setItem("d2-track-records", checked); eventEmitter.emit("tracked-items-changed"); }); + + document.getElementById("debugMode").addEventListener("change", async function (event) { + let checked = event.target.checked; + await db.setItem("d2-debugmode", checked); + eventEmitter.emit("debug-changed", checked); + }); }); }); @@ -75,6 +81,12 @@ export function Settings() { ) ? "checked" : ""; + + document.getElementById("debugMode").checked = JSON.parse( + ((await db.getItem("d2-debugmode")) ?? "false").toString() + ) + ? "checked" + : ""; } return ( @@ -150,6 +162,12 @@ export function Settings() { %localappdata%\Overwolf\Log and zip up the folder so we can get you back to achieving your goals.

+
+ + +