fix LoadJson script

This commit is contained in:
ReznoRMichael 2021-01-19 23:57:27 +01:00
parent 2505a1958e
commit 5e4dbec3bf
2 changed files with 35 additions and 22 deletions

View file

@ -86,7 +86,7 @@
</html> </html>
<!-- Instantly load test file (Debugging script) --> <!-- Instantly load test file (Debugging script) -->
<!-- <script src="js/LoadJson.js"></script> --> <script src="js/LoadJson.js"></script>
<!-- Main script --> <!-- Main script -->
<script src="js/HKCheckCompletion.js"></script> <script src="js/HKCheckCompletion.js"></script>

View file

@ -2,25 +2,26 @@ var jsonObj = "";
// save file names list in the save/ folder // save file names list in the save/ folder
var fileName = [ var fileName = [
"reznor0.json", // 0 "reznor0", // 0
"reznor1beforegruz.json", // 1 "reznor1beforegruz", // 1
"reznor2aftergruz.json", // 2 "reznor2aftergruz", // 2
"reznor5hornet.json", // 3 "reznor5hornet", // 3
"reznor29ss.json", // 4 "reznor29ss", // 4
"ext48.json", // 5 "ext48", // 5
"reznor88banish.json", // 6 "reznor88banish", // 6
"reznor99whitefragment.json", // 7 "reznor99whitefragment", // 7
"reznor100.json", // 8 "reznor100", // 8
"reznor103ss.json", // 9 "reznor103ss", // 9
"reznor107.json", // 10 "reznor107", // 10
"reznor112grimm.json", // 11 "reznor112grimm", // 11
"PoP/kanna.json", // 12 "PoP/kanna", // 12
"PoP/Reaper4578.json", // 13 "PoP/Reaper4578", // 13
"PoP/tintingaroo.json", // 14 "PoP/tintingaroo", // 14
]; ];
/** /**
* Reads the .json file and parses it to a JS object (jsonObj). * Reads the .json file and parses it to a JS object (jsonObj).
* @param {string} filename Path and .json file name to be loaded
* @param callback Function to be called when the request completes * @param callback Function to be called when the request completes
*/ */
function LoadJSON(filename, callback) { function LoadJSON(filename, callback) {
@ -37,24 +38,36 @@ function LoadJSON(filename, callback) {
psw: optional password */ psw: optional password */
xobj.open('GET', filename, true); // Path to the file xobj.open('GET', filename, true); // Path to the file
// Sends the request to the server - Used for GET requests
xobj.send(null);
// Defines a function to be called when the readyState property changes // Defines a function to be called when the readyState property changes
xobj.onreadystatechange = function GetResponseText() { /* xobj.onreadystatechange = function GetResponseText() {
if (xobj.readyState == 4 && xobj.status == "200") { if (xobj.readyState == 4 && xobj.status == "200") {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode // Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
// Returns the response data as a string // Returns the response data as a string
return callback(xobj.responseText); return callback(xobj.responseText);
} else return false; } else return false;
}; }; */
// Sends the request to the server - Used for GET requests // Sends the request to the server - Used for GET requests
xobj.send(null); // xobj.send(null);
xobj.onload = function JSONparse() {
// Parse JSON string into object
const jsonObject = JSON.parse(xobj.responseText);
document.getElementById("save-area").value = JSON.stringify(jsonObject);
return jsonObject;
// console.log(jsonObj);
}
} }
function JSONparse(response) { /* function JSONparse(response) {
// Parse JSON string into object // Parse JSON string into object
let jsonObject = JSON.parse(response); let jsonObject = JSON.parse(response);
document.getElementById("save-area").value = response; document.getElementById("save-area").value = response;
return jsonObject; return jsonObject;
// console.log(jsonObj); // console.log(jsonObj);
} } */
jsonObj = LoadJSON("../save/" + fileName[13], JSONparse(response)); // jsonObj = LoadJSON("../save/" + fileName[5], JSONparse(response));
jsonObj = LoadJSON("save/" + fileName[5] + ".json");