plugin-backend #1

Merged
ada merged 34 commits from plugin-backend into main 2024-05-01 00:21:12 -05:00
6 changed files with 112 additions and 76 deletions
Showing only changes of commit 9fea6e1d95 - Show all commits

View File

@ -38,3 +38,8 @@ function hide_empty_summaries() {
} }
}); });
} }
function notices_ur_debug() {
document.getElementById("debug-block").classList.toggle("hidden");
}

View File

@ -5,19 +5,11 @@ var current_scene = "";
var current_seed = Number.MAX_VALUE; var current_seed = Number.MAX_VALUE;
var current_checks = 0; var current_checks = 0;
var current_entrances = 0; var current_entrances = 0;
var current_hints = 0;
var current_codes = Number.MAX_VALUE; var current_codes = Number.MAX_VALUE;
var current_hints = 0;
var total_checks = 0; var total_checks = 0;
var total_entrances = 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 // Global state internal
var server_address = ""; var server_address = "";
var cross_codes = {}; var cross_codes = {};
@ -31,7 +23,7 @@ window.onload = () => {
cross_codes = JSON.parse(JSON.stringify(data)); cross_codes = JSON.parse(JSON.stringify(data));
refresh_overview().then((overview) => { refresh_overview().then((overview) => {
perform_updates(true, true, true, true); perform_updates(true, true, true, true);
update_overview(overview, true, true); update_overview(overview, true);
}); });
refresh_elements(); refresh_elements();
}, },
@ -53,14 +45,12 @@ async function refresh_elements() {
const changed_scene = overview.scene != current_scene; const changed_scene = overview.scene != current_scene;
const changed_checks = overview.items != current_checks; const changed_checks = overview.items != current_checks;
const changed_entrances = overview.entrances != current_entrances; 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 changed_hints = overview.hints != current_hints;
const any_change = const any_change =
changed_seed || changed_seed ||
changed_scene || changed_scene ||
changed_checks || changed_checks ||
changed_entrances || changed_entrances ||
changed_codes ||
changed_hints; changed_hints;
if (any_change) { if (any_change) {
@ -70,8 +60,9 @@ async function refresh_elements() {
changed_entrances, changed_entrances,
changed_hints changed_hints
); );
update_overview(overview, changed_scene, changed_codes); update_overview(overview, changed_scene);
} }
await update_codes(overview.codes);
} }
setTimeout(refresh_elements, 500); 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() { async function get_updated_server_address() {
fetch(`${document.URL}get/address`) fetch(`${document.URL}get/address`)
.then( .then(
@ -151,7 +138,7 @@ async function refresh_entrances() {
return data; return data;
} }
async function update_overview(overview, changed_scene, changed_codes) { async function update_overview(overview, changed_scene) {
let overview_checks_title = document let overview_checks_title = document
.getElementById("overview-totals") .getElementById("overview-totals")
.querySelector(".overview-checks"); .querySelector(".overview-checks");
@ -172,14 +159,10 @@ async function update_overview(overview, changed_scene, changed_codes) {
current_checks = overview.items; current_checks = overview.items;
current_entrances = overview.entrances; current_entrances = overview.entrances;
current_hints = overview.hints; current_hints = overview.hints;
current_codes = Object.keys(overview.codes).length;
if (changed_scene) { if (changed_scene) {
await update_scene(overview.scene); await update_scene(overview.scene);
} }
if (changed_codes) {
await update_codes(overview.codes);
}
} }
async function update_codes(codes) { async function update_codes(codes) {
@ -200,7 +183,40 @@ async function update_codes(codes) {
cross_codes_block_list_item.cloneNode(true) cross_codes_block_list_item.cloneNode(true)
); );
cross_codes_block_list_item.classList.remove("hidden"); cross_codes_block_list_item.classList.remove("hidden");
const codes_length = Array.from(Object.keys(codes)).length;
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) => { Object.keys(default_cross_codes).forEach((code) => {
cross_codes_block_list_item.querySelector( cross_codes_block_list_item.querySelector(
".codes-list-item-title" ".codes-list-item-title"
@ -216,37 +232,45 @@ async function update_codes(codes) {
cross_codes_block_list_item.cloneNode(true) cross_codes_block_list_item.cloneNode(true)
); );
}); });
Object.keys(global_cross_codes).forEach((code) => { document
cross_codes_block_list_item.querySelector( .getElementById("codes-list")
".codes-list-item-title" .replaceWith(new_cross_codes_block_list);
).textContent = code;
cross_codes_block_list_item.querySelector( // Change the number of current codes if it's different
".codes-list-item-code" current_codes = codes_length;
).textContent = global_cross_codes[code] } else {
.replace(/U/g, "⬆️") Object.keys(codes)
.replace(/R/g, "➡️") .sort((i, j) => {
.replace(/D/g, "⬇️") return codes[i].Distance - codes[j].Distance;
.replace(/L/g, "⬅️"); })
new_cross_codes_block_list.appendChild( .forEach((code, index) => {
cross_codes_block_list_item.cloneNode(true) 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;
}); });
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);
} }
async function apply_summary_colors(summary) { async function apply_summary_colors(summary) {

View File

@ -12,8 +12,8 @@
{% load static tailwind_tags %} {% load static tailwind_tags %}
{% tailwind_css %} {% tailwind_css %}
<link rel="stylesheet" href="https://csshake.surge.sh/csshake-default.css"> <link rel="stylesheet" href="https://csshake.surge.sh/csshake-default.css">
<script src="{% static "tracker/assets/button_functions.js" %}"></script> <script src="{% static "tracker/assets/button-functions.js" %}"></script>
<script type="module" src="{% static "tracker/assets/refresh_elements.js" %}"></script> <script type="module" src="{% static "tracker/assets/main.js" %}"></script>
<script type="module" src="{% static "tracker/assets/translate-hints.js" %}"></script> <script type="module" src="{% static "tracker/assets/translate-hints.js" %}"></script>
</head> </head>
<body class="min-h-screen font-nerd bg-gradient-to-br from-bluelight-background-dark to-bluelight-background"> <body class="min-h-screen font-nerd bg-gradient-to-br from-bluelight-background-dark to-bluelight-background">

View File

@ -1,5 +1,5 @@
{% if not is_entered %} {% if not is_entered %}
<ul class="p-2 flex flex-col rounded-xl {{ extra_classes }}"> <ul class="p-2 flex flex-col rounded-xl order-last {{ extra_classes }}">
<div class="pl-2 text-base codes-list-item-title">{{ name }}</div> <div class="pl-2 text-base codes-list-item-title">{{ name }}</div>
<hr class="mb-2 border-2 border-holy-cross opacity-30 rounded-xl" /> <hr class="mb-2 border-2 border-holy-cross opacity-30 rounded-xl" />
<div class="min-x-full"> <div class="min-x-full">

View File

@ -132,6 +132,7 @@
{% endfor %} {% endfor %}
</div> </div>
</div> {% endcomment %} </div> {% endcomment %}
{% comment %} <div class="order-1 order-2 order-3 order-4 order-5 order-6 order-7 order-8 order-9 order-10 order-11 order-12"></div> {% endcomment %}
{% include "tracker/src/index.html" with tracker_fe_link="https://gitea.werefox.cafe/ada/tunic-tracker-redux" tracker_be_link="https://github.com/spaceglace/TunicTransitionTracker" %} {% include "tracker/src/index.html" with tracker_fe_link="https://gitea.werefox.cafe/ada/tunic-tracker-redux" tracker_be_link="https://github.com/spaceglace/TunicTransitionTracker" %}
</div> </div>
{% endblock content %} {% endblock content %}

View File

@ -94,10 +94,16 @@ def index(request):
tracker_checks_cleared_total = tracker_items_data["collected"] tracker_checks_cleared_total = tracker_items_data["collected"]
active_codes = {} active_codes = {}
for name, distance in tracker_current_scene_codes.items(): for name, value in tracker_current_scene_codes.items():
logging.debug(value)
this_scene = tracker_current_scene
if value["Global"]:
this_scene = "Global"
active_codes[name] = { active_codes[name] = {
"distance": distance, "distance": value["Distance"],
"code": cross_codes[tracker_current_scene][name], "global": value["Global"],
"in_range": value["InRange"],
"code": cross_codes[this_scene][name],
} }
logging.debug(active_codes) logging.debug(active_codes)
@ -164,8 +170,8 @@ def format_overview_output(overview):
overview_string += f"\t{key}: " overview_string += f"\t{key}: "
if key == "codes": if key == "codes":
overview_string += "\n" overview_string += "\n"
for code, distance in value.items(): for code, something in value.items():
overview_string += f"\t\t{code}: {distance:.2f}\n" overview_string += f"\t\t{code}: {something['Distance']:.2f}\n"
else: else:
overview_string += f"{value}\n" overview_string += f"{value}\n"
return overview_string return overview_string