diff --git a/tunictracker/tracker/static/tracker/assets/button_functions.js b/tunictracker/tracker/static/tracker/assets/button-functions.js similarity index 92% rename from tunictracker/tracker/static/tracker/assets/button_functions.js rename to tunictracker/tracker/static/tracker/assets/button-functions.js index 142247e..e50f81f 100644 --- a/tunictracker/tracker/static/tracker/assets/button_functions.js +++ b/tunictracker/tracker/static/tracker/assets/button-functions.js @@ -38,3 +38,8 @@ function hide_empty_summaries() { } }); } + + +function notices_ur_debug() { + document.getElementById("debug-block").classList.toggle("hidden"); +} \ No newline at end of file diff --git a/tunictracker/tracker/static/tracker/assets/refresh_elements.js b/tunictracker/tracker/static/tracker/assets/main.js similarity index 86% rename from tunictracker/tracker/static/tracker/assets/refresh_elements.js rename to tunictracker/tracker/static/tracker/assets/main.js index 94aafbb..90583d4 100644 --- a/tunictracker/tracker/static/tracker/assets/refresh_elements.js +++ b/tunictracker/tracker/static/tracker/assets/main.js @@ -5,19 +5,11 @@ var current_scene = ""; var current_seed = Number.MAX_VALUE; var current_checks = 0; var current_entrances = 0; -var current_hints = 0; var current_codes = Number.MAX_VALUE; +var current_hints = 0; var total_checks = 0; var total_entrances = 0; -// Global state for all entrances -// This should hold numbers for how many entrances are mapped/total per scene. -var current_entrances_list = {}; - -// Global state for all checks -// This should hold numbers for how many checks are cleared/total per scene. -var current_checks_list = {}; - // Global state internal var server_address = ""; var cross_codes = {}; @@ -31,7 +23,7 @@ window.onload = () => { cross_codes = JSON.parse(JSON.stringify(data)); refresh_overview().then((overview) => { perform_updates(true, true, true, true); - update_overview(overview, true, true); + update_overview(overview, true); }); refresh_elements(); }, @@ -53,14 +45,12 @@ async function refresh_elements() { const changed_scene = overview.scene != current_scene; const changed_checks = overview.items != current_checks; const changed_entrances = overview.entrances != current_entrances; - const changed_codes = Object.keys(overview.codes).length != current_codes; const changed_hints = overview.hints != current_hints; const any_change = changed_seed || changed_scene || changed_checks || changed_entrances || - changed_codes || changed_hints; if (any_change) { @@ -70,8 +60,9 @@ async function refresh_elements() { changed_entrances, changed_hints ); - update_overview(overview, changed_scene, changed_codes); + update_overview(overview, changed_scene); } + await update_codes(overview.codes); } setTimeout(refresh_elements, 500); } @@ -101,10 +92,6 @@ async function perform_updates( } } -function notices_ur_debug() { - document.getElementById("debug-block").classList.toggle("hidden"); -} - async function get_updated_server_address() { fetch(`${document.URL}get/address`) .then( @@ -151,7 +138,7 @@ async function refresh_entrances() { return data; } -async function update_overview(overview, changed_scene, changed_codes) { +async function update_overview(overview, changed_scene) { let overview_checks_title = document .getElementById("overview-totals") .querySelector(".overview-checks"); @@ -172,14 +159,10 @@ async function update_overview(overview, changed_scene, changed_codes) { current_checks = overview.items; current_entrances = overview.entrances; current_hints = overview.hints; - current_codes = Object.keys(overview.codes).length; if (changed_scene) { await update_scene(overview.scene); } - if (changed_codes) { - await update_codes(overview.codes); - } } async function update_codes(codes) { @@ -200,53 +183,94 @@ async function update_codes(codes) { cross_codes_block_list_item.cloneNode(true) ); cross_codes_block_list_item.classList.remove("hidden"); + const codes_length = Array.from(Object.keys(codes)).length; - Object.keys(default_cross_codes).forEach((code) => { - cross_codes_block_list_item.querySelector( - ".codes-list-item-title" - ).textContent = code; - cross_codes_block_list_item.querySelector( - ".codes-list-item-code" - ).textContent = default_cross_codes[code] - .replace(/U/g, "⬆️") - .replace(/R/g, "➡️") - .replace(/D/g, "⬇️") - .replace(/L/g, "⬅️"); - new_cross_codes_block_list.appendChild( - cross_codes_block_list_item.cloneNode(true) - ); - }); - Object.keys(global_cross_codes).forEach((code) => { - cross_codes_block_list_item.querySelector( - ".codes-list-item-title" - ).textContent = code; - cross_codes_block_list_item.querySelector( - ".codes-list-item-code" - ).textContent = global_cross_codes[code] - .replace(/U/g, "⬆️") - .replace(/R/g, "➡️") - .replace(/D/g, "⬇️") - .replace(/L/g, "⬅️"); - new_cross_codes_block_list.appendChild( - cross_codes_block_list_item.cloneNode(true) - ); - }); - Object.keys(codes).forEach((code) => { - cross_codes_block_list_item.querySelector( - ".codes-list-item-title" - ).textContent = code; - cross_codes_block_list_item.querySelector( - ".codes-list-item-code" - ).textContent = cross_codes[current_scene][code] - .replace(/U/g, "⬆️") - .replace(/R/g, "➡️") - .replace(/D/g, "⬇️") - .replace(/L/g, "⬅️"); - new_cross_codes_block_list.appendChild( - cross_codes_block_list_item.cloneNode(true) - ); - }); - document.getElementById("codes-list").replaceWith(new_cross_codes_block_list); + if (current_codes != Array.from(Object.keys(codes)).length) { + Object.keys(codes) + .sort((i, j) => { + return codes[i].Distance - codes[j].Distance; + }) + .forEach((codename, index) => { + cross_codes_block_list_item.querySelector( + ".codes-list-item-title" + ).textContent = codename; + if (codes[codename].Global) { + cross_codes_block_list_item.querySelector( + ".codes-list-item-code" + ).textContent = cross_codes["Global"][codename] + .replace(/U/g, "⬆️") + .replace(/R/g, "➡️") + .replace(/D/g, "⬇️") + .replace(/L/g, "⬅️"); + } else { + cross_codes_block_list_item.querySelector( + ".codes-list-item-code" + ).textContent = cross_codes[current_scene][codename] + .replace(/U/g, "⬆️") + .replace(/R/g, "➡️") + .replace(/D/g, "⬇️") + .replace(/L/g, "⬅️"); + } + cross_codes_block_list_item.dataset.codename = codename; + cross_codes_block_list_item.dataset.order = index; + new_cross_codes_block_list.appendChild( + cross_codes_block_list_item.cloneNode(true) + ); + }); + Object.keys(default_cross_codes).forEach((code) => { + cross_codes_block_list_item.querySelector( + ".codes-list-item-title" + ).textContent = code; + cross_codes_block_list_item.querySelector( + ".codes-list-item-code" + ).textContent = default_cross_codes[code] + .replace(/U/g, "⬆️") + .replace(/R/g, "➡️") + .replace(/D/g, "⬇️") + .replace(/L/g, "⬅️"); + new_cross_codes_block_list.appendChild( + cross_codes_block_list_item.cloneNode(true) + ); + }); + document + .getElementById("codes-list") + .replaceWith(new_cross_codes_block_list); + + // Change the number of current codes if it's different + current_codes = codes_length; + } else { + Object.keys(codes) + .sort((i, j) => { + return codes[i].Distance - codes[j].Distance; + }) + .forEach((code, index) => { + const classes = Array.from( + document + .getElementById("codes-list") + .querySelector(`[data-codename="${code}"]`).classList + ).filter((classname) => classname.startsWith("order-")); + // console.log(classes); + if (classes.length > 0) { + document + .getElementById("codes-list") + .querySelector(`[data-codename="${code}"]`) + .classList.remove(classes); + } + if (codes[code].Global) { + document + .getElementById("codes-list") + .querySelector(`[data-codename="${code}"]`) + .classList.add(`order-last`); + } + document + .getElementById("codes-list") + .querySelector(`[data-codename="${code}"]`) + .classList.add(`order-[${index + 1}]`); + document + .getElementById("codes-list") + .querySelector(`[data-codename="${code}"]`).dataset.order = index + 1; + }); + } } async function apply_summary_colors(summary) { diff --git a/tunictracker/tracker/templates/index.html b/tunictracker/tracker/templates/index.html index a855253..2300a3d 100644 --- a/tunictracker/tracker/templates/index.html +++ b/tunictracker/tracker/templates/index.html @@ -12,8 +12,8 @@ {% load static tailwind_tags %} {% tailwind_css %} - - + +
diff --git a/tunictracker/tracker/templates/tracker/codes/block.html b/tunictracker/tracker/templates/tracker/codes/block.html index f1a19ee..88283c9 100644 --- a/tunictracker/tracker/templates/tracker/codes/block.html +++ b/tunictracker/tracker/templates/tracker/codes/block.html @@ -1,5 +1,5 @@ {% if not is_entered %} -