Removed unused code, front-end now refreshes data without page refresh.

This commit is contained in:
Ada Werefox 2024-03-03 18:47:56 -06:00
parent bfb1c44a9e
commit 50f5660740
6 changed files with 152 additions and 121 deletions

BIN
TunicTransitionTracker-linux Executable file

Binary file not shown.

View File

@ -1,48 +0,0 @@
#!/usr/bin/python
import logging
import re
def import_entrances(spoiler_log='/home/alice/Games/steam/steamapps/compatdata/553420/pfx/drive_c/users/steamuser/AppData/LocalLow/Andrew Shouldice/Secret Legend/Randomizer/Spoiler.log'):
"""A function to import the entrance mappings from the user's spoiler log.
Args:
spoiler_log (str, optional): The filepath of the spoiler log. Defaults to '/home/alice/Games/steam/steamapps/compatdata/553420/pfx/drive_c/users/steamuser/AppData/LocalLow/Andrew Shouldice/Secret Legend/Randomizer/Spoiler.log'.
"""
try:
with open(spoiler_log, 'r') as f:
spoiler_text = f.read()
entrances_map = re.findall('\s+- (.+) -- (.+)\n', spoiler_text)
# logging.debug(entrances_map)
except:
logging.error(f'Could not find spoiler log from path: {spoiler_log}')
return
return dict(entrances_map)
def log_entrances(e):
"""A debug function to ensure entrance parsing has been done successfully.
"""
for l in e:
logging.debug(f'{l[0]} <---> {l[1]}')
def check_mapped_entrances(new_entrances, entrances_map):
"""A function to check off when a new entrance pair has been visited and validate it with the spoiler log.
Args:
new_entrances (tuple): A pairing of two strings containing the entrance names.
entrances_map (dict): An imported dictionary mapping the entrances as listed in the spoiler log.
"""
if new_entrances[0] in entrances_map.keys():
logging.debug(f'Validated that {new_entrances[0]} connects to {new_entrances[1]}')
elif new_entrances[1] in entrances_map.keys():
logging.debug(f'Validated that {new_entrances[1]} connects to {new_entrances[0]}')
else:
logging.warn(f'No connection in spoiler log between {new_entrances[0]} and {new_entrances[1]}')
return False
return True

View File

@ -1,53 +0,0 @@
import logging
import glob
import os
import re
# from collections import deque
def get_current_save_filename(saves_dir='/home/alice/Games/steam/steamapps/compatdata/553420/pfx/drive_c/users/steamuser/AppData/LocalLow/Andrew Shouldice/Secret Legend/SAVES'):
"""Get the last modified save file in the saves directory.
Args:
saves_dir (str, optional): Path to the saves directory. Defaults to '/home/alice/Games/steam/steamapps/compatdata/553420/pfx/drive_c/users/steamuser/AppData/LocalLow/Andrew Shouldice/Secret Legend/SAVES'.
"""
try:
list_files = glob.glob(f'{saves_dir}/*.tunic')
except:
logging.error(
f'Something went wrong in looking for the saves directory at {saves_dir}')
try:
latest_save_path = max(list_files, key=os.path.getmtime)
except:
logging.warn('A save file was deleted.')
return
try:
latest_save_filename = re.search(
'([0-9]*)[a-z-]*~([0-9]*)\.tunic', latest_save_path)
except:
logging.error(f'Cannot perform regex successfully on save path: {latest_save_path}')
return
if latest_save_filename != None:
return (latest_save_filename[0], latest_save_filename[1])
return (None, None)
def get_visited_entrances(save_filename, saves_dir='/home/alice/Games/steam/steamapps/compatdata/553420/pfx/drive_c/users/steamuser/AppData/LocalLow/Andrew Shouldice/Secret Legend/SAVES'):
try:
with open(f'{saves_dir}/{save_filename}', 'r') as save:
save_file_text = save.read()
try:
save_entrances = re.findall('portal (.*)\|1\n', save_file_text)
except:
logging.error(
f'Unable to perform findall successfully on {save_filename}')
return
except:
logging.error(f'Could not find save file from path: {save_filename}')
return
return save_entrances

View File

@ -0,0 +1,116 @@
window.onload = () => {
let overview = {
checks: document.getElementById("overview_checks"),
entrances: document.getElementById("overview_entrances"),
};
let current_scene = {
name: document.getElementById("current_scene_text"),
checks: {
title: document.getElementById("current_scene_checks_title"),
list: document.getElementById("current_scene_checks_list"),
},
entrances: {
title: document.getElementById("current_scene_entrances_title"),
list: document.getElementById("current_scene_entrances_list"),
mapped: document.getElementById("current_scene_entrances_mapped"),
},
};
let line_elem = document
.getElementById("current_scene_checks_list")
.firstElementChild.cloneNode(true);
let mapped_line_elem = document
.getElementById("current_scene_entrances_mapped")
.firstElementChild.cloneNode(true);
const refresh_interval = setInterval(
refresh_elements,
300,
overview,
current_scene,
line_elem,
mapped_line_elem
);
};
async function refresh_elements(
overview,
current_scene,
line_elem,
mapped_line_elem
) {
fetch("http://localhost:8000/spoiler")
.then((response) => response.json())
.then((data) => {
const response_object = JSON.parse(JSON.stringify(data));
const overview_checks_undiscovered =
response_object.Totals.Checks.Undiscovered;
const overview_checks_total = response_object.Totals.Checks.Total;
const overview_entrances_undiscovered =
response_object.Totals.Entrances.Undiscovered;
const overview_entrances_total = response_object.Totals.Entrances.Total;
const current_scene_name = response_object.Scene;
const current_scene_checks_undiscovered =
response_object.Scenes[current_scene_name].Totals.Checks.Undiscovered;
const current_scene_checks_total =
response_object.Scenes[current_scene_name].Totals.Checks.Total;
const current_scene_entrances_undiscovered =
response_object.Scenes[current_scene_name].Totals.Entrances
.Undiscovered;
const current_scene_entrances_total =
response_object.Scenes[current_scene_name].Totals.Entrances.Total;
const current_scene_checks_list =
response_object.Scenes[current_scene_name].Checks;
const current_scene_entrances_list =
response_object.Scenes[current_scene_name].Entrances;
overview.checks.textContent = `Checks: ${overview_checks_undiscovered}/${overview_checks_total}`;
overview.entrances.textContent = `Entrances: ${overview_entrances_undiscovered}/${overview_entrances_total}`;
current_scene.name.textContent = current_scene_name;
current_scene.checks.title.textContent = `Checks: ${current_scene_checks_undiscovered}/${current_scene_checks_total}`;
current_scene.entrances.title.textContent = `Entrances: ${current_scene_entrances_undiscovered}/${current_scene_entrances_total}`;
current_scene.checks.list.innerHTML = "";
current_scene.entrances.list.innerHTML = "";
current_scene.entrances.mapped.innerHTML = "";
Object.keys(current_scene_checks_list).forEach((check) => {
if (!current_scene_checks_list[check]) {
line_elem.textContent = `${check}`;
current_scene.checks.list.appendChild(line_elem.cloneNode(true));
}
});
Object.keys(current_scene_entrances_list).forEach((entrances) => {
if (current_scene_entrances_list[entrances] == "") {
line_elem.textContent = `${entrances}`;
current_scene.entrances.list.appendChild(line_elem.cloneNode(true));
} else {
mapped_line_elem.textContent = `✔️ ${entrances} -> ${current_scene_entrances_list[entrances]}`;
current_scene.entrances.mapped.appendChild(
mapped_line_elem.cloneNode(true)
);
}
});
})
.catch((err) => {
console.log();
});
}
function log_elements() {
console.log(overview.checks.textContent);
console.log(overview.entrances.textContent);
console.log(current_scene.name.textContent);
console.log(current_scene.checks.title.textContent);
for (i in current_scene.checks.list.children) {
if (current_scene.checks.list.children[i].textContent) {
console.log(current_scene.checks.list.children[i].textContent);
}
}
console.log(current_scene.entrances.title.textContent);
for (i in current_scene.entrances.list.children) {
if (current_scene.entrances.list.children[i].textContent) {
console.log(current_scene.entrances.list.children[i].textContent);
}
}
for (i in current_scene.entrances.mapped.children) {
if (current_scene.entrances.mapped.children[i].textContent) {
console.log(current_scene.entrances.mapped.children[i].textContent);
}
}
}

View File

@ -7,7 +7,7 @@
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" /> <meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="refresh" content="3"> {% comment %} <meta http-equiv="refresh" content="3"> {% endcomment %}
{% load static tailwind_tags %} {% load static tailwind_tags %}
{% tailwind_css %} {% tailwind_css %}
{% load static %} {% load static %}

View File

@ -13,8 +13,8 @@
<div class="p-4 flex flex-col max-w-full space-y-2 md:space-y-4 text-md rounded-md ring-4 bg-bluelight-translucent ring-bluelight-dark"> <div class="p-4 flex flex-col max-w-full space-y-2 md:space-y-4 text-md rounded-md ring-4 bg-bluelight-translucent ring-bluelight-dark">
<div class="text-lg">Overview</div> <div class="text-lg">Overview</div>
<div class="flex flex-col md:flex-row md:space-x-4 space-y-2 md:space-y-0"> <div class="flex flex-col md:flex-row md:space-x-4 space-y-2 md:space-y-0">
<div class="flex basis-1/2">Checks: {{ totals.Checks.Undiscovered }}/{{ totals.Checks.Total }}</div> <div class="flex basis-1/2" id="overview_checks">Checks: {{ totals.Checks.Undiscovered }}/{{ totals.Checks.Total }}</div>
<div class="flex basis-1/2">Entrances: {{ totals.Entrances.Undiscovered }}/{{ totals.Entrances.Total }}</div> <div class="flex basis-1/2" id="overview_entrances">Entrances: {{ totals.Entrances.Undiscovered }}/{{ totals.Entrances.Total }}</div>
</div> </div>
<hr class="border-2 border-bluelight-translucent-dark rounded-md" /> <hr class="border-2 border-bluelight-translucent-dark rounded-md" />
<details class="group p-2 flex flex-col space-y-4 rounded-md ring-4 bg-bluelight-translucent ring-bluelight-dark"> <details class="group p-2 flex flex-col space-y-4 rounded-md ring-4 bg-bluelight-translucent ring-bluelight-dark">
@ -22,7 +22,13 @@
<div class="grid gap-4 md:grid-cols-3 grid-flow-row"> <div class="grid gap-4 md:grid-cols-3 grid-flow-row">
{% for scene, scene_totals in totals.items %} {% for scene, scene_totals in totals.items %}
{% if scene != 'Entrances' and scene != 'Checks' %} {% if scene != 'Entrances' and scene != 'Checks' %}
<div class="p-2 flex flex-col rounded-md ring-4 ring-bluelight-dark bg-opacity-50 {% if scene_totals.Checks.Undiscovered > 0 and scene_totals.Entrances.Undiscovered > 0 %}bg-green-900{% elif scene_totals.Checks.Undiscovered > 0 %}bg-yellow-900{% elif scene_totals.Entrances.Undiscovered > 0 %}bg-blue-900{% else %}{% endif %}"> <div class="p-2 flex flex-col rounded-md ring-4 ring-bluelight-dark bg-opacity-50 {% if scene_totals.Checks.Undiscovered > 0 and scene_totals.Entrances.Undiscovered > 0 %}
{% elif scene_totals.Checks.Undiscovered > 0 %}
{% elif scene_totals.Entrances.Undiscovered > 0 %}
{% endif %}">
<div>{{ scene }}:</div> <div>{{ scene }}:</div>
<div>Checks: {{ scene_totals.Checks.Undiscovered }}/{{ scene_totals.Checks.Total }}</div> <div>Checks: {{ scene_totals.Checks.Undiscovered }}/{{ scene_totals.Checks.Total }}</div>
<div>Entrances: {{ scene_totals.Entrances.Undiscovered }}/{{ scene_totals.Entrances.Total }}</div> <div>Entrances: {{ scene_totals.Entrances.Undiscovered }}/{{ scene_totals.Entrances.Total }}</div>
@ -33,37 +39,47 @@
</details> </details>
</div> </div>
<div class="p-4 flex flex-col max-w-full rounded-md ring-4 bg-bluelight-translucent ring-bluelight-dark"> <div class="p-4 flex flex-col max-w-full rounded-md ring-4 bg-bluelight-translucent ring-bluelight-dark">
<div class="flex text-lg">{{ scene }}</div> <div class="flex text-lg" id="current_scene_text">{{ scene }}</div>
<div class="flex flex-col md:flex-row justify-center md:space-x-4"> <div class="flex flex-col md:flex-row justify-center md:space-x-4">
<div class="flex flex-col basis-1/2 overflow-hidden"> <div class="flex flex-col basis-1/2 overflow-hidden">
<div class="my-2 flex flex-col space-y-2"> <div class="my-2 flex flex-col space-y-2">
<div class="text-md">Checks: {{ scene_data.Totals.Checks.Undiscovered }}/{{ scene_data.Totals.Checks.Total }}</div> <div class="text-md" id="current_scene_checks_title">Checks: {{ scene_data.Totals.Checks.Undiscovered }}/{{ scene_data.Totals.Checks.Total }}</div>
<hr class="border-2 border-bluelight-translucent-dark rounded-md" /> <hr class="border-2 border-bluelight-translucent-dark rounded-md" />
</div> </div>
<div class="pb-4 flex flex-col space-y-2 overflow-x-scroll"> <div class="pb-4 flex flex-col space-y-2 overflow-x-scroll" id="current_scene_checks_list">
{% for check_name, check in scene_data.Checks.items %} {% if scene_data.Totals.Checks.Total > 0 %}
{% if not check.Check %} {% for check_name, check in scene_data.Checks.items %}
<ul class="min-w-max bg-bluelight-translucent rounded-md px-1">❌ {{ check_name }}</ul> {% if not check.Check %}
{% endif %} <ul class="min-w-max bg-bluelight-translucent rounded-md px-1">❌ {{ check_name }}</ul>
{% endfor %} {% endif %}
{% endfor %}
{% else %}
<ul class="min-w-max bg-bluelight-translucent rounded-md px-1" hidden></ul>
{% endif %}
</div> </div>
</div> </div>
<div class="flex flex-col basis-1/2 overflow-hidden"> <div class="flex flex-col basis-1/2 overflow-hidden">
<div class="my-2 flex flex-col space-y-2"> <div class="my-2 flex flex-col space-y-2">
<div class="text-md">Entrances: {{ scene_data.Totals.Entrances.Undiscovered }}/{{ scene_data.Totals.Entrances.Total }}</div> <div class="text-md" id="current_scene_entrances_title">Entrances: {{ scene_data.Totals.Entrances.Undiscovered }}/{{ scene_data.Totals.Entrances.Total }}</div>
<hr class="border-2 border-bluelight-translucent-dark rounded-md" /> <hr class="border-2 border-bluelight-translucent-dark rounded-md" />
</div> </div>
<div class="pb-4 flex flex-col space-y-2 overflow-x-scroll"> <div class="pb-4 flex flex-col space-y-2 overflow-x-scroll" id="current_scene_entrances_list">
{% for entrance_origin, entrance_destination in scene_data.Entrances.items %} {% if scene_data.Totals.Entrances.Total > 0 %}
{% if not entrance_destination.Entrance != '' %} {% for entrance_origin, entrance_destination in scene_data.Entrances.items %}
<ul class="min-w-max bg-bluelight-translucent rounded-md px-1">❌ {{ entrance_origin }} -> {{ entrance_destination.Entrance }}</ul> {% if not entrance_destination.Entrance != '' %}
{% endif %} <ul class="min-w-max bg-bluelight-translucent rounded-md px-1">❌ {{ entrance_origin }}</ul>
{% endfor %} {% else %}
<ul class="min-w-max bg-bluelight-translucent rounded-md px-1" hidden>❌ {{ entrance_origin }}</ul>
{% endif %}
{% endfor %}
{% else %}
<ul class="min-w-max bg-bluelight-translucent rounded-md px-1" hidden></ul>
{% endif %}
</div> </div>
</div> </div>
</div> </div>
<div class="overflow-x-scroll"> <div class="overflow-x-scroll">
<div class="flex flex-col space-y-2 mx-auto min-w-max"> <div class="flex flex-col space-y-2 mx-auto min-w-max" id="current_scene_entrances_mapped">
{% for entrance_origin, entrance_destination in scene_data.Entrances.items %} {% for entrance_origin, entrance_destination in scene_data.Entrances.items %}
{% if entrance_destination.Entrance %} {% if entrance_destination.Entrance %}
<ul class="bg-bluelight rounded-md px-1">✔️ {{ entrance_origin }} -> {{ entrance_destination.Entrance }}</ul> <ul class="bg-bluelight rounded-md px-1">✔️ {{ entrance_origin }} -> {{ entrance_destination.Entrance }}</ul>