/* files.js */ function loadDocument(filePath) { filePath = filePath.replace(` `,`%20`); while(right(filePath,1) === `:`){ filePath = left( filePath, len( filePath ) - 1 ); } var xhr = new XMLHttpRequest(); xhr.open("GET", filePath, false); // 'false' makes the request synchronous xhr.setRequestHeader("Accept", "text/plain"); xhr.send(null); if (xhr.status === 200) { return xhr.responseText; } else { throw new Error('Error loading document: ' + xhr.status); } } function loadJSON(filePath) { filePath = filePath.replace(` `,`%20`); while(right(filePath,1) === `:`){ filePath = left( filePath, len( filePath ) - 1 ); } var xhr = new XMLHttpRequest(); xhr.open("GET", filePath, false); // 'false' makes the request synchronous xhr.setRequestHeader("Accept", "application/json"); xhr.send(null); if (xhr.status === 200) { return JSON.parse(xhr.responseText); } else { throw new Error('Error loading JSON file: ' + xhr.status); } } async function loadFullMap() { // Load the full map const full_map = await fetch(`${host}/test dictionary/scripts/json/maps/${map}.json`).then(response => response.json()); // Initialize full_stats array const full_stats = []; for (let x = 0; x < full_map.length; x++) { full_stats[x] = []; // Initialize the second dimension for (let y = 0; y < full_map[x].length; y++) { full_stats[x][y] = []; // Initialize the third dimension for (let z = 0; z < layers.gui; z++) { const sectionValue = sections(full_map[x][y][z], 4)[0]; const url = `${host}/entity dictionary/scripts/json/${sectionValue}.json`; if(preloaded.indexOf(sectionValue) !== -1){ full_stats[x][y][z] = preloaded[sections(full_map[x][y][z],4)[0]]; continue; } full_stats[x][y][z] = preloaded[sections(full_map[x][y][z],4)[0]]; // Check if the file exists before fetching it if (await fileExists(url)) { full_stats[x][y][z] = await fetch(url).then(response => response.json()); } else { // console.warn(`File not found: ${url}`); full_stats[x][y][z] = null; // or handle the missing file case as needed continue; } // Capture the first key const keys = layers.Object.keys(full_stats[x][y][z]); if (keys.length === 0) { full_stats[x][y][z] = null; continue; } const key = keys[0]; if ( key === sections( full_map[x][y][z], 4 )[0] ){ preloaded[sections(full_map[x][y][z],4)[0]] = full_stats[x][y][z][sections(full_map[x][y][z],4)[0]]; } else { preloaded[sections(full_map[x][y][z],4)[0]] = null; } } } } return full_stats; } // Function to check if a file exists using a HEAD request async function fileExists(url) { url = url.replace(` `,`%20`); while(right(url,1) === `:`){ url = left( url, len( url ) - 1 ); } try { const response = await fetch(url, { method: 'HEAD' }); return response.ok; } catch (error) { // console.error(`Error checking file existence: ${error}`); return false; } } // Load cardinal directions from JSON with enhanced debugging function loadJSON(url) { url = url.replace(` `,`%20`); while(right(url,1) === `:`){ url = left( url, len( url ) - 1 ); } try { const data = loadJSON(url); if (!data) { console.error(`Failed to load JSON from ${url}`); } return data; } catch (error) { console.error(`Error loading JSON from ${url}:`, error); return null; } }