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_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,7 +183,40 @@ 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;
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"
@ -216,37 +232,45 @@ async function update_codes(codes) {
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)
);
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;
});
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) {

View File

@ -12,8 +12,8 @@
{% load static tailwind_tags %}
{% tailwind_css %}
<link rel="stylesheet" href="https://csshake.surge.sh/csshake-default.css">
<script src="{% static "tracker/assets/button_functions.js" %}"></script>
<script type="module" src="{% static "tracker/assets/refresh_elements.js" %}"></script>
<script src="{% static "tracker/assets/button-functions.js" %}"></script>
<script type="module" src="{% static "tracker/assets/main.js" %}"></script>
<script type="module" src="{% static "tracker/assets/translate-hints.js" %}"></script>
</head>
<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 %}
<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>
<hr class="mb-2 border-2 border-holy-cross opacity-30 rounded-xl" />
<div class="min-x-full">

View File

@ -132,6 +132,7 @@
{% endfor %}
</div>
</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" %}
</div>
{% endblock content %}

View File

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