Cross codes now update in place, as soon as a new save file is created.

This commit is contained in:
Ada Werefox 2024-03-07 03:46:23 -06:00
parent 8e7c65303d
commit 25102a6bbc
6 changed files with 154 additions and 54 deletions

View File

@ -1,10 +1,25 @@
var current_hash = ""; var current_hash = "";
window.onload = () => { window.onload = () => {
const refresh_interval = setInterval(refresh_elements, 500); fetch("http://localhost:8080/static/tracker/data/holy_cross_codes.json")
.then((response) => response.json())
.then(
(data) => {
const cross_codes = JSON.parse(JSON.stringify(data));
// console.log(cross_codes);
const refresh_interval = setInterval(
refresh_elements,
500,
cross_codes
);
},
(error) => {
console.log(error);
}
);
}; };
async function refresh_elements() { async function refresh_elements(cross_codes) {
fetch("http://localhost:8000/spoiler") fetch("http://localhost:8000/spoiler")
.then((response) => response.json()) .then((response) => response.json())
.then( .then(
@ -28,7 +43,9 @@ async function refresh_elements() {
const current_scene_name = response_object.Current.Scene; const current_scene_name = response_object.Current.Scene;
const all_scenes = response_object.Scenes; const all_scenes = response_object.Scenes;
const debug_info = response_object.Debug; const debug_info = response_object.Debug;
const cross_codes = response_object.Codes; const cross_codes_entered = response_object.Codes;
const default_cross_codes = cross_codes.Default;
const global_cross_codes = cross_codes.Global;
// Refresh elements with new data from the back end. // Refresh elements with new data from the back end.
@ -47,6 +64,11 @@ async function refresh_elements() {
.getElementById("overview") .getElementById("overview")
.querySelector(".breakdown-list") .querySelector(".breakdown-list")
.firstElementChild.cloneNode(true); .firstElementChild.cloneNode(true);
let cross_codes_block = document
.getElementById("overview")
.querySelector(".breakdown-list")
.firstElementChild.querySelector(".codes-block")
.cloneNode(true);
breakdown_block.classList.remove("hidden"); breakdown_block.classList.remove("hidden");
let debug_item = document let debug_item = document
.getElementById("debug-block") .getElementById("debug-block")
@ -122,18 +144,31 @@ async function refresh_elements() {
.firstElementChild.cloneNode(true); .firstElementChild.cloneNode(true);
breakdown_block_mapped_list_item.classList.remove("hidden"); breakdown_block_mapped_list_item.classList.remove("hidden");
cross_codes_block = document
.getElementById("overview")
.querySelector(".breakdown-list")
.firstElementChild.querySelector(".codes-block")
.cloneNode(true);
let new_cross_codes_block_list = cross_codes_block
.querySelector(".codes-list")
.cloneNode(true);
let cross_codes_block_list_item = cross_codes_block
.querySelector(".codes-list")
.firstElementChild.cloneNode(true);
// Clear out current list content. // Clear out current list content.
new_breakdown_block_checks_list.innerHTML = ""; new_breakdown_block_checks_list.innerHTML = "";
new_breakdown_block_entrances_list.innerHTML = ""; new_breakdown_block_entrances_list.innerHTML = "";
new_breakdown_block_mapped_list.innerHTML = ""; new_breakdown_block_mapped_list.innerHTML = "";
new_cross_codes_block_list.innerHTML = "";
new_breakdown_block_checks_list.appendChild( new_breakdown_block_checks_list.appendChild(
breakdown_block_checks_list_item.cloneNode() breakdown_block_checks_list_item.cloneNode(true)
); );
new_breakdown_block_entrances_list.appendChild( new_breakdown_block_entrances_list.appendChild(
breakdown_block_entrances_list_item.cloneNode() breakdown_block_entrances_list_item.cloneNode(true)
); );
new_breakdown_block_mapped_list.appendChild( new_breakdown_block_mapped_list.appendChild(
breakdown_block_mapped_list_item.cloneNode() breakdown_block_mapped_list_item.cloneNode(true)
); );
// Create variables for commonly used values. // Create variables for commonly used values.
@ -143,6 +178,7 @@ async function refresh_elements() {
let scene_entrances_undiscovered = let scene_entrances_undiscovered =
all_scenes[scene].Totals.Entrances.Undiscovered; all_scenes[scene].Totals.Entrances.Undiscovered;
let scene_entrances_total = all_scenes[scene].Totals.Entrances.Total; let scene_entrances_total = all_scenes[scene].Totals.Entrances.Total;
let scene_has_codes = Object.keys(cross_codes).includes(scene);
// Set textContent. // Set textContent.
summary_title.textContent = scene; summary_title.textContent = scene;
@ -152,7 +188,7 @@ async function refresh_elements() {
breakdown_block_checks_title.textContent = `Checks: ${all_scenes[scene].Totals.Checks.Undiscovered}/${all_scenes[scene].Totals.Checks.Total}`; breakdown_block_checks_title.textContent = `Checks: ${all_scenes[scene].Totals.Checks.Undiscovered}/${all_scenes[scene].Totals.Checks.Total}`;
breakdown_block_entrances_title.textContent = `Entrances: ${all_scenes[scene].Totals.Entrances.Undiscovered}/${all_scenes[scene].Totals.Entrances.Total}`; breakdown_block_entrances_title.textContent = `Entrances: ${all_scenes[scene].Totals.Entrances.Undiscovered}/${all_scenes[scene].Totals.Entrances.Total}`;
// Create checks, entrances, and mapped entrances lists. // Create checks, entrances, mapped entrances, and cross code lists.
Object.keys(all_scenes[scene].Checks).forEach((check) => { Object.keys(all_scenes[scene].Checks).forEach((check) => {
if (!all_scenes[scene].Checks[check]) { if (!all_scenes[scene].Checks[check]) {
breakdown_block_checks_list_item.textContent = `${check}`; breakdown_block_checks_list_item.textContent = `${check}`;
@ -174,6 +210,63 @@ async function refresh_elements() {
); );
} }
}); });
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, "⬅️ ");
if (cross_codes_entered.Global[code]) {
cross_codes_block_list_item.classList.add("hidden");
} else {
cross_codes_block_list_item.classList.remove("hidden");
}
new_cross_codes_block_list.appendChild(
cross_codes_block_list_item.cloneNode(true)
);
});
if (scene_has_codes) {
Object.keys(cross_codes[scene]).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[scene][code]
.replace(/U/g, "⬆️ ")
.replace(/R/g, "➡️ ")
.replace(/D/g, "⬇️ ")
.replace(/L/g, "⬅️ ");
if (cross_codes_entered[scene][code]) {
cross_codes_block_list_item.classList.add("hidden");
} else {
cross_codes_block_list_item.classList.remove("hidden");
}
new_cross_codes_block_list.appendChild(
cross_codes_block_list_item.cloneNode(true)
);
});
}
// Apply color coding to summary block // Apply color coding to summary block
summary_block.classList.remove( summary_block.classList.remove(
@ -207,10 +300,16 @@ async function refresh_elements() {
breakdown_block breakdown_block
.querySelector(".breakdown-block-mapped-list") .querySelector(".breakdown-block-mapped-list")
.replaceWith(new_breakdown_block_mapped_list); .replaceWith(new_breakdown_block_mapped_list);
breakdown_block
.querySelector(".codes-list")
.replaceWith(new_cross_codes_block_list);
// Append relevant elements to lists. // Append relevant elements to lists.
if (scene == current_scene_name) { if (scene == current_scene_name) {
summary_block.classList.add("hidden"); summary_block.classList.add("hidden");
breakdown_block
.querySelector(".codes-block")
.classList.remove("hidden");
document document
.getElementById("breakdown-current") .getElementById("breakdown-current")
.firstElementChild.replaceWith(breakdown_block.cloneNode(true)); .firstElementChild.replaceWith(breakdown_block.cloneNode(true));

View File

@ -1,7 +1,8 @@
{ {
"Default": { "Default": {
"Speedrunner Code": "RULDDRULU", "Speedrunner Code": "RULDDRULU",
"Seeking Spell": "ULURDL" "Seeking Spell": "ULURDL",
"Healing Spell": "DRDLURU"
}, },
"Cathedral": { "Cathedral": {
"Secret Legend Door": "LULURULURDRRURDLDRDLDL" "Secret Legend Door": "LULURULURDRRURDLDRDLDL"
@ -19,6 +20,11 @@
"Eastern Vault Fortress": { "Eastern Vault Fortress": {
"Candles Fairy": "RLDRUL" "Candles Fairy": "RLDRUL"
}, },
"Global": {
"Firebomb": "LURDRURDRURDL",
"Firecracker": "DRURULULDLDR",
"Icebomb": "LDRURDRURDRUL"
},
"Hourglass Cave": { "Hourglass Cave": {
"Hourglass Door": "RULURULUURDLDRDLDR", "Hourglass Door": "RULURULUURDLDRDLDR",
"Hourglass Fairy": "LURURDRURULLLURU" "Hourglass Fairy": "LURURDRURULLLURU"
@ -65,12 +71,6 @@
"Secret Gathering Place": { "Secret Gathering Place": {
"Waterfall Fairy": "DRURURULULURURULDLDLDRDLDRDRUR" "Waterfall Fairy": "DRURURULULURURULDLDLDRDLDRDRUR"
}, },
"Spells": {
"Healing Spell": "DRDLURU",
"Dynamite": "DRURULULDLDR",
"Fire Bomb": "LURDRURDRURDL",
"Ice Bomb": "LDRURDLURDLUL"
},
"West Garden": { "West Garden": {
"Sword Door": "DRULUR", "Sword Door": "DRULUR",
"Tiles Fairy": "URULURULURDRULRLURULURULU", "Tiles Fairy": "URULURULURDRULRLURULURULU",

View File

@ -57,9 +57,5 @@
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% if current_scene.title != scene_title %}
<div class="pt-4 hidden">{% include "tracker/codes/index.html" %}</div>
{% else %}
<div class="pt-4">{% include "tracker/codes/index.html" %}</div> <div class="pt-4">{% include "tracker/codes/index.html" %}</div>
{% endif %}
</div> </div>

View File

@ -1,7 +1,8 @@
<ul class="flex flex-col p-2 rounded-md bg-bluelight-translucent-dark max-w-full {% if is_entered %}hidden{% endif %}"> {% if not is_entered %}
<div class="p-2">{{ name }}:</div> <ul class="flex flex-col p-2 rounded-md bg-bluelight-translucent-dark max-w-full">
<div class="p-2 codes-list-item-title">{{ name }}</div>
<div class="p-2 m-auto justify-center align-top"> <div class="p-2 m-auto justify-center align-top">
<div class="max-w-64"> <div class="max-w-64 codes-list-item-code">
{% for arrow in code %} {% for arrow in code %}
{% if arrow == "U" %} {% if arrow == "U" %}
⬆️ ⬆️
@ -16,3 +17,4 @@
</div> </div>
</div> </div>
</ul> </ul>
{% endif %}

View File

@ -1,18 +1,21 @@
<div class="flex flex-col max-w-full text-lg rounded-md ring-4 bg-bluelight-translucent ring-bluelight-dark justify-start p-4 {{ is_hidden }}"> <div class="flex flex-col max-w-full text-lg rounded-md ring-4 bg-bluelight-translucent ring-bluelight-dark justify-start p-4 {% if current_scene.title != scene_title %}hidden{% endif %} codes-block">
Holy Cross Codes Holy Cross Codes
<div class="flex flex-col space-y-2"> <div class="flex flex-col space-y-2">
<ul class="flex flex-col space-y-4 rounded-md" id="codes-block"> <ul class="flex flex-col space-y-4 rounded-md codes-list">
<ul class="flex flex-col p-2 rounded-md bg-bluelight-translucent-dark w-full hidden">
</ul>
{% for name, code in default_codes.items %} {% for name, code in default_codes.items %}
{% include "tracker/codes/block.html" with is_entered=false %} {% include "tracker/codes/block.html" with is_entered=False %}
{% endfor %} {% endfor %}
{% for name, code in spell_codes.items %} {% for scene, codes in tracked_codes.items %}
{% include "tracker/codes/block.html" with is_entered=false %} {% if scene == "Global" %}
{% endfor %} {% for name, code_tuple in codes.items %}
{% for name, code_tuple in current_codes.items %}
{% include "tracker/codes/block.html" with code=code_tuple.0 is_entered=code_tuple.1 %} {% include "tracker/codes/block.html" with code=code_tuple.0 is_entered=code_tuple.1 %}
{% endfor %} {% endfor %}
{% elif scene == scene_title %}
{% for name, code_tuple in codes.items %}
{% include "tracker/codes/block.html" with code=code_tuple.0 is_entered=code_tuple.1 %}
{% endfor %}
{% endif %}
{% endfor %}
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -31,7 +31,7 @@ def index(request):
is_hidden = False is_hidden = False
except: except:
return return
with open('tracker/data/holy_cross_codes.json', 'r') as t: with open('tracker/static/tracker/data/holy_cross_codes.json', 'r') as t:
try: try:
cross_codes = loads(t.read()) cross_codes = loads(t.read())
except: except:
@ -41,12 +41,13 @@ def index(request):
tracker_current_scene = tracker_output["Current"]["Scene"] tracker_current_scene = tracker_output["Current"]["Scene"]
tracker_current_scene_data = tracker_output["Scenes"][tracker_current_scene] tracker_current_scene_data = tracker_output["Scenes"][tracker_current_scene]
tracker_scenes = tracker_output["Scenes"] tracker_scenes = tracker_output["Scenes"]
tracker_codes = tracker_output["Codes"] entered_codes = tracker_output["Codes"]
try: try:
current_cross_codes = cross_codes[tracker_current_scene] tracker_codes = cross_codes
for k, v in cross_codes[tracker_current_scene].items(): for scene in entered_codes:
current_cross_codes[k] = ( for k, v in cross_codes[scene].items():
v, tracker_codes[tracker_current_scene][k]) tracker_codes[scene][k] = (
v, entered_codes[scene][k])
except Exception as e: except Exception as e:
current_cross_codes = {} current_cross_codes = {}
print(e) print(e)
@ -56,8 +57,7 @@ def index(request):
"is_hidden": is_hidden, "is_hidden": is_hidden,
"debug": tracker_debug, "debug": tracker_debug,
"default_codes": cross_codes["Default"], "default_codes": cross_codes["Default"],
"spell_codes": cross_codes["Spells"], "tracked_codes": tracker_codes,
"current_codes": current_cross_codes,
"totals": tracker_totals, "totals": tracker_totals,
"scenes": tracker_scenes, "scenes": tracker_scenes,
"current_scene": { "current_scene": {