reorganize code

This commit is contained in:
ReznoRMichael 2021-08-04 22:56:15 +02:00
commit 03df9ae9f9
7 changed files with 188 additions and 139 deletions

View file

@ -11,7 +11,9 @@ import {
AppendHTML,
CheckboxHintsToggle,
CheckboxSpoilersToggle,
StorageAvailable
StorageAvailable,
Benchmark,
benchmarkTimes
} from "./page-functions.js";
import {
@ -62,52 +64,8 @@ let pSpan = "<span class='p-left-small'></span>";
/* let benchHKCCBegin, benchHKCCEnd; */
let benchmarkTimes = {
LoadSaveFile: {
name: "LoadSaveFile()",
timeStart: 0,
timeEnd: 0
},
CheckCompletion: {
name: "HKCheckCompletion()",
timeStart: 0,
timeEnd: 0
},
GenerateInnerHTML: {
name: "GenerateInnerHTML()",
timeStart: 0,
timeEnd: 0
},
HKReadTextArea: {
name: "HKReadTextArea()",
timeStart: 0,
timeEnd: 0
},
Total: {
name: "Total",
timeStart: 0,
timeEnd: 0
}
};
/* -------------------------- Functions ----------------------------- */
function Benchmark(bench) {
let result = 0;
for (let time in bench) {
if (bench[time].timeStart !== 0 && bench[time].timeEnd !== 0) {
result = bench[time].timeEnd - bench[time].timeStart;
console.info(`${bench[time].name} time (ms) = %c${result.toFixed(2)}`, `color: #008cdc; font-weight: 700;`);
}
bench[time].timeStart = 0;
bench[time].timeEnd = 0;
}
}
/**
* Main Function. Checks Hollow Knight game completion by analyzing the save file
* @param {object} jsonObject Decoded save data in JavaScript Object Notation form (JSON)
@ -2297,7 +2255,5 @@ document.getElementById("save-area-read").addEventListener("click", () => {
export {
// to use in LoadSaveFile.js for auto-analyzing file after decoding
HKCheckCompletion,
benchmarkTimes,
Benchmark
HKCheckCompletion
};

View file

@ -10,11 +10,14 @@
const aesjs = require("./aes-js.js");
// For reading the text area after save decoding
import {
HKCheckCompletion,
benchmarkTimes,
Benchmark
HKCheckCompletion
} from "./HKCheckCompletion.js";
import {
Benchmark,
benchmarkTimes
} from "./page-functions.js";
const CSHARP_HEADER = [0, 1, 0, 0, 0, 255, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 6, 1, 0, 0, 0]; // 22 bytes
const BASE64_ARRAY = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".split("").map(c => c.charCodeAt(0));
@ -45,6 +48,8 @@ function LoadSaveFile(input, time) {
// start benchmark
benchmarkTimes.LoadSaveFile.timeStart = time;
benchmarkTimes.Total.timeStart = time;
benchmarkTimes.HKReadTextArea.timeStart = 0;
benchmarkTimes.HKReadTextArea.timeEnd = 0;
// Prepares a File object from the first file of the input files for reading as an Array Buffer
let inputFileObject = inputFileList[0];

View file

@ -1,12 +1,8 @@
import {
benchmarkTimes
} from "./HKCheckCompletion.js";
import {
LoadSaveFile
} from "./LoadSaveFile.js";
// ---------------- Load image files (necessary for Webpack) ----------------- //
/* ------------------------ Load image files (necessary for Webpack) ---------------------------------------------------------- */
import HEALTH_MASK_IMAGE from "../img/health-mask.png";
import HEALTH_MASK_STEEL_IMAGE from "../img/health-mask-steel.png";
@ -17,7 +13,7 @@ import NOTCH_OVERCHARMED_IMAGE from "../img/notch-overcharmed.png";
import GEO_IMAGE from "../img/geo.png";
import GEO_SHADE_IMAGE from "../img/geo-shade.png";
// ---------------- Constants ----------------- //
/* ------------------------- Constants ---------------------------------------------------------------------------------------- */
// const DATA_UNKNOWN = "Data unknown";
const SYMBOL_FALSE = "<i class='icon-cancel'></i>"; // "❌ "
@ -33,9 +29,54 @@ const WIKI_LINK = "https://hollowknight.fandom.com/wiki/";
const ROOT = document.documentElement;
const SCROLL_BUTTON = document.querySelector(".scroll-up-button");
/* -------------------------- Variables --------------------------------------------------------------------------------------- */
let benchmarkTimes = {
LoadSaveFile: {
name: "LoadSaveFile()",
timeStart: 0,
timeEnd: 0
},
CheckCompletion: {
name: "HKCheckCompletion()",
timeStart: 0,
timeEnd: 0
},
GenerateInnerHTML: {
name: "GenerateInnerHTML()",
timeStart: 0,
timeEnd: 0
},
HKReadTextArea: {
name: "HKReadTextArea()",
timeStart: 0,
timeEnd: 0
},
Total: {
name: "Total",
timeStart: 0,
timeEnd: 0
}
};
/* ######################################################################################### */
function Benchmark(bench) {
let result = 0;
for (let time in bench) {
if (bench[time].timeStart !== 0 && bench[time].timeEnd !== 0) {
result = bench[time].timeEnd - bench[time].timeStart;
console.info(`${bench[time].name} time (ms) = %c${result.toFixed(2)}`, `color: #008cdc; font-weight: 700;`);
}
bench[time].timeStart = 0;
bench[time].timeEnd = 0;
}
}
function ScrollToElement(element) {
@ -1149,5 +1190,7 @@ export {
AppendHTML,
CheckboxHintsToggle,
CheckboxSpoilersToggle,
StorageAvailable
StorageAvailable,
Benchmark,
benchmarkTimes
};