From 8fe4788ef1119f3dca5a794690319ca63c14b6ff Mon Sep 17 00:00:00 2001 From: ReznoRMichael Date: Mon, 21 Jun 2021 15:07:35 +0200 Subject: [PATCH] CompletionFill() --- src/js/page-functions.js | 61 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/js/page-functions.js b/src/js/page-functions.js index e75958c..0a8f646 100644 --- a/src/js/page-functions.js +++ b/src/js/page-functions.js @@ -134,6 +134,65 @@ function CompletionHTML(jsObj, hkGameCompletion) { } } +/** + * Replaces the h2 titles with a current percent/max percent values as read from the save file + * @param {object} jsObj Object with HTML data to fill + * @param {number} hkGameCompletion Total completion percentage in a save file + */ + function CompletionFill(section, hkGameCompletion) { + + let h2 = ""; + let cl = ""; + let clGreen = "box-green"; + let clRed = "box-red"; + let cp = 0; // current Percent + let mp = 0; // max Percent + let fillText = ""; + + + h2 = section.h2; + + (section.hasOwnProperty("percent")) ? cp = section.percent: cp = 0; + if (section.id === "hk-intro") cp = hkGameCompletion; + + // Don't use percent-box for Essentials, Achievements, Statistics + if (!section.hasOwnProperty("maxPercent")) { + fillText = ""; + } + // otherwise use percent-box with values cp/mp% + else { + + mp = section.maxPercent; + + if (section.id === "hk-maskshards") { + let perc = section.percent; + (perc % 4) ? cp = Math.floor(perc / 4): cp = perc / 4; + } else if (section.id === "hk-vesselfragments") { + let perc = section.percent; + (perc % 3) ? cp = Math.floor(perc / 3): cp = perc / 3; + } + + // switches the box to red when a section (h2) is 0 + if (cp === 0) { + cl = ` ${clRed}`; + } + // switches the box to green when a section (h2) is completed + else if (cp === mp) { + cl = ` ${clGreen}`; + } + // default is blue (partially completed and starting value) + else cl = ""; + + // needed for Game Status to show percentage properly (adds a slash for all boxes except the Game Status one) + if (section.id != "hk-intro") cp += "/"; + + fillText = `
${(section.id === "hk-intro") ? cp: cp + section.maxPercent}%
`; + } + + return h2 + fillText; + +} + function GenerateInnerHTML(hkdb) { console.log(hkdb); @@ -158,7 +217,7 @@ function GenerateInnerHTML(hkdb) { } console.log(finalHTMLFill); - + } /**