CheckExtendedCompletion()

This commit is contained in:
ReznoRMichael 2021-07-19 23:42:58 +02:00
commit fc8f990a97
5 changed files with 140 additions and 4 deletions

View file

@ -270,9 +270,10 @@ function HKCheckCompletion(jsonObject, benchStart = new Date()) {
CheckHintsTrue(HK.sections.hints, HK.sections.hints.entries, HKPlayerData, HKWorldItems);
// ------------------------- Fill completion ----------------------------- //
// ------------------------- Extended game completion check ----------------------------- //
/* Percent completion is filled inside GenerateInnerHTML() using CompletionFill() */
CheckExtendedCompletion(HK);
// ------------------------- Indicate that the save file was loaded and analyzed correctly ----------------------------- //
@ -453,6 +454,62 @@ function CheckCompletionPercent(section, playerData) {
// document.getElementById(section.id).innerHTML += divStart + completionSymbol + textFill + divEnd;
}
/**
* Calculates the amount of all green ticks and total entries. Saves them to database for later display.
* @param {object} db reference to the main HK database
*/
function CheckExtendedCompletion(db) {
let sections = db.sections;
let entries = {};
let gameCompletionExtended = db.sections.intro.entries.gameCompletionExtended;
let intro = db.sections.intro;
/* Bring to default values (0) */
intro.extendedCompletionDone = 0;
intro.extendedCompletionTotal = 0;
gameCompletionExtended.spoiler = 0;
gameCompletionExtended.spoilerAfter = "";
for (let section in sections) {
entries = sections[section].entries;
switch (section) {
case "intro":
case "hints":
continue;
default:
for (let entry in entries) {
if (entries[entry].hasOwnProperty("icon")) {
intro.extendedCompletionTotal++;
if (entries[entry].icon === "green") {
intro.extendedCompletionDone++;
}
if (entries[entry].hasOwnProperty("disabled") && entries[entry].disabled == true) {
intro.extendedCompletionTotal--;
}
}
}
}
}
if (intro.extendedCompletionDone >= intro.extendedCompletionTotal) {
gameCompletionExtended.icon === "green";
}
gameCompletionExtended.spoiler = intro.extendedCompletionDone;
gameCompletionExtended.spoilerAfter = ` / ${intro.extendedCompletionTotal}`;
}
/**
* Reads the "version" string from the save file and appends it to the selected div ID element
* @param {object} section ID of the HTML element for data appending

View file

@ -14,12 +14,17 @@ const HK = {
intro: {
h2: "Game Status",
id: "hk-intro",
percent: 0,
maxPercent: 112,
maxPercentDefault: 112,
maxPercentBaseGame: 100,
maxPercentGrimmTroupe: 106,
maxPercentLifeblood: 107,
extendedCompletionDone: 0,
extendedCompletionTotal: 0,
entries: {
timePlayed: {
id: "timePlayed",
@ -41,6 +46,14 @@ const HK = {
spoilerAfterGrimmTroupe: "(out of 106 %)",
spoilerAfterLifeblood: "(out of 107 %)",
},
gameCompletionExtended: {
id: "gameCompletionExtended",
icon: "red",
name: "Extended Completion:",
spoiler: 0,
spoilerAfter: "",
spoilerAfterDefault: "",
},
saveVersion: {
id: "saveVersion",
icon: "none",

View file

@ -208,6 +208,8 @@ function GenerateInnerHTML(db) {
case "intro":
console.info("Extended Completion:", `${sections[section].extendedCompletionDone} / ${sections[section].extendedCompletionTotal}`);
/* ############## Create each single entry (intro) ############### */
for (let entry in entries) {