upgrade ResetCompletion() for cleaning

This commit is contained in:
ReznoRMichael 2021-07-08 23:50:41 +02:00
parent bffb16f814
commit 0e2a054116
4 changed files with 104 additions and 22 deletions

View file

@ -86,10 +86,10 @@ function HKCheckCompletion(jsonObject) {
} else return false; } else return false;
} else return false; // Pre-Cleaning and filling initial data (h2, id) needed for PrepareHTMLString() } else return false; // Pre-Cleaning and filling initial data (h2, id) needed for PrepareHTMLString()
// PrefillHTML(HK.sections); // PrefillHTML(HK.sections);
// Prevents adding current percent data after each function call (each click of Analyze button) // Prevents adding current percent data after each function call and resets what the analyzing has done to the original object. Prevents wrong data display after subsequent save analyzing.
ResetCompletion(_hk_database_js__WEBPACK_IMPORTED_MODULE_0__.default.sections); // ================================================================================== // ResetCompletion(_hk_database_js__WEBPACK_IMPORTED_MODULE_0__.default); // ================================================================================== //
// ---------------- Time Played ----------------- // // ---------------- Time Played ----------------- //
CheckPlayTime(_hk_database_js__WEBPACK_IMPORTED_MODULE_0__.default.sections.intro, HKPlayerData.playTime); // ---------------- Game Completion Status ----------------- // CheckPlayTime(_hk_database_js__WEBPACK_IMPORTED_MODULE_0__.default.sections.intro, HKPlayerData.playTime); // ---------------- Game Completion Status ----------------- //
@ -1451,14 +1451,53 @@ function InitialHTMLPopulate(db) {
(0,_page_functions_js__WEBPACK_IMPORTED_MODULE_1__.CheckboxSpoilersToggle)(); (0,_page_functions_js__WEBPACK_IMPORTED_MODULE_1__.CheckboxSpoilersToggle)();
} }
/** /**
* Zero-fill all "percent" properties in the JSON Object (reset to default) * Reset the object state in memory to default values, like before first save analyzing. Undo all changes.
* @param {object} jsObj object containing the "percent" properties to be reset to 0 * @param {object} db database object reference
*/ */
function ResetCompletion(jsObj) { function ResetCompletion(db) {
for (var i in jsObj) { var sections = db.sections;
if (jsObj[i].hasOwnProperty("percent")) jsObj[i].percent = 0; var entries = {};
db.saveAnalyzed = false;
for (var section in sections) {
entries = sections[section].entries;
if (sections[section].hasOwnProperty("percent")) sections[section].percent = 0;
switch (section) {
case "intro":
case "hints":
break;
default:
for (var entry in entries) {
if (entries[entry].hasOwnProperty("icon")) {
entries[entry].icon = "red";
}
if (entries[entry].hasOwnProperty("disabled")) {
entries[entry].disabled = false;
}
if (entries[entry].hasOwnProperty("amount")) {
entries[entry].amount = 0;
}
if (entries[entry].hasOwnProperty("amountTotal")) {
entries[entry].amountTotal = 0;
}
if (entry.hasOwnProperty("currentName")) {
delete entries[entry].currentName;
}
if (entry.hasOwnProperty("currentSpoiler")) {
delete entries[entry].currentSpoiler;
}
}
}
} }
} }
/** /**
@ -4975,7 +5014,8 @@ function CompletionHTML(jsObj, hkGameCompletion) {
function GenerateInnerHTML(db) { function GenerateInnerHTML(db) {
var sections = db.sections; var sections = db.sections;
console.log(sections); /* console.log(sections); */
var finalHTMLFill = ""; var finalHTMLFill = "";
var textFill = ""; var textFill = "";
var entries = {}; var entries = {};
@ -5026,10 +5066,11 @@ function GenerateInnerHTML(db) {
} }
/* Final HTML Fill here */ /* Final HTML Fill here */
/* console.groupCollapsed("finalHTMLFill");
console.groupCollapsed("finalHTMLFill");
console.log(finalHTMLFill); console.log(finalHTMLFill);
console.groupEnd(); console.groupEnd(); */
document.getElementById("generated").innerHTML = finalHTMLFill; document.getElementById("generated").innerHTML = finalHTMLFill;
} }

File diff suppressed because one or more lines are too long

View file

@ -92,8 +92,8 @@ function HKCheckCompletion(jsonObject) {
// Pre-Cleaning and filling initial data (h2, id) needed for PrepareHTMLString() // Pre-Cleaning and filling initial data (h2, id) needed for PrepareHTMLString()
// PrefillHTML(HK.sections); // PrefillHTML(HK.sections);
// Prevents adding current percent data after each function call (each click of Analyze button) // Prevents adding current percent data after each function call and resets what the analyzing has done to the original object. Prevents wrong data display after subsequent save analyzing.
ResetCompletion(HK.sections); ResetCompletion(HK);
// ================================================================================== // // ================================================================================== //
@ -1540,13 +1540,54 @@ function InitialHTMLPopulate(db) {
} }
/** /**
* Zero-fill all "percent" properties in the JSON Object (reset to default) * Reset the object state in memory to default values, like before first save analyzing. Undo all changes.
* @param {object} jsObj object containing the "percent" properties to be reset to 0 * @param {object} db database object reference
*/ */
function ResetCompletion(jsObj) { function ResetCompletion(db) {
for (let i in jsObj) { let sections = db.sections;
if (jsObj[i].hasOwnProperty("percent")) jsObj[i].percent = 0; let entries = {};
db.saveAnalyzed = false;
for (let section in sections) {
entries = sections[section].entries;
if (sections[section].hasOwnProperty("percent")) sections[section].percent = 0;
switch (section) {
case "intro":
case "hints":
break;
default:
for (let entry in entries) {
if (entries[entry].hasOwnProperty("icon")) {
entries[entry].icon = "red";
}
if (entries[entry].hasOwnProperty("disabled")) {
entries[entry].disabled = false;
}
if (entries[entry].hasOwnProperty("amount")) {
entries[entry].amount = 0;
}
if (entries[entry].hasOwnProperty("amountTotal")) {
entries[entry].amountTotal = 0;
}
if (entry.hasOwnProperty("currentName")) {
delete entries[entry].currentName;
}
if (entry.hasOwnProperty("currentSpoiler")) {
delete entries[entry].currentSpoiler;
}
}
}
} }
} }

View file

@ -131,7 +131,7 @@ function GenerateInnerHTML(db) {
let sections = db.sections; let sections = db.sections;
console.log(sections); /* console.log(sections); */
let finalHTMLFill = ""; let finalHTMLFill = "";
let textFill = ""; let textFill = "";
@ -184,9 +184,9 @@ function GenerateInnerHTML(db) {
} }
/* Final HTML Fill here */ /* Final HTML Fill here */
console.groupCollapsed("finalHTMLFill"); /* console.groupCollapsed("finalHTMLFill");
console.log(finalHTMLFill); console.log(finalHTMLFill);
console.groupEnd(); console.groupEnd(); */
document.getElementById("generated").innerHTML = finalHTMLFill; document.getElementById("generated").innerHTML = finalHTMLFill;