Removed thiserror, added some tracing for file loading, moved the json files to an input folder and updated the search filtering a bit

Wynd 2024-06-30 11:11:51 +03:00
parent 92890f198b
commit 99334a74fd
10 changed files with 554 additions and 3205 deletions

View File

@ -0,0 +1,2 @@
[env]
RUST_LOG = "khguide=debug"

View File

@ -9,5 +9,4 @@ serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.118"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
thiserror = "1.0.61"
itertools = "0.13.0"

View File

@ -1,12 +0,0 @@
[tasks.create]
dependencies = ["run", "format"]
[tasks.format]
private = true
command = "prettier"
args = ["-w", "index.html"]
[tasks.run]
private = true
command = "cargo"
args = ["run"]

3381
index.html

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,7 @@ use std::collections::HashMap;
use askama::Template;
use itertools::Itertools;
use serde::Deserialize;
use tracing_subscriber::EnvFilter;
#[derive(Debug, Deserialize, PartialEq, Eq)]
enum Character {
@ -127,14 +128,27 @@ struct CommandsTemplate {
pub crystals: Vec<String>,
}
const ABILITIES_PATH: &str = "./input/abilities.json";
const FINISHERS_PATH: &str = "./input/finish-commands.json";
const COMMANDS_PATH: &str = "./input/commands.json";
fn main() {
let abilities_str = std::fs::read_to_string("./abilities.json").unwrap();
// Initialize tracing
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.event_format(tracing_subscriber::fmt::format().with_source_location(true))
.init();
tracing::info!("Loading abilities json data from {}", ABILITIES_PATH);
let abilities_str = std::fs::read_to_string(ABILITIES_PATH).unwrap();
let abilities = serde_json::from_str::<Vec<Ability>>(&abilities_str).unwrap();
let finishers_str = std::fs::read_to_string("./finish-commands.json").unwrap();
tracing::info!("Loading finishers json data from {}", ABILITIES_PATH);
let finishers_str = std::fs::read_to_string(FINISHERS_PATH).unwrap();
let finishers = serde_json::from_str::<HashMap<String, Finisher>>(&finishers_str).unwrap();
let commands_str = std::fs::read_to_string("./commands.json").unwrap();
tracing::info!("Loading commands json data from {}", ABILITIES_PATH);
let commands_str = std::fs::read_to_string(COMMANDS_PATH).unwrap();
let mut commands = serde_json::from_str::<Vec<Command>>(&commands_str).unwrap();
// Create a vec with all the crystal variants found in abilities
@ -152,6 +166,7 @@ fn main() {
}
}
tracing::info!("Generating the commands table template");
let template = CommandsTemplate { commands, crystals };
std::fs::write("./index.html", template.render().unwrap()).unwrap();

View File

@ -1,4 +1,4 @@
<input type="text" id="filter" autocomplete="off" onkeyup="filter()" />
<input type="text" id="filter" autocomplete="off" />
<br />
<input
type="radio"

View File

@ -9,6 +9,10 @@
let searchType = "result";
document.addEventListener("DOMContentLoaded", (event) => {
const searchFilter = document.getElementById("filter");
let filterHandler = debounce(() => filter());
searchFilter.addEventListener("keyup", filterHandler);
const searchInputs = document.querySelectorAll(
'input[type="radio"][name="search"]',
);
@ -43,6 +47,16 @@
});
});
function debounce(callback, wait = 300) {
let timeoutId = null;
return (...args) => {
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(() => {
callback(...args);
}, wait);
};
}
function filter() {
const table = document.querySelector("table tbody");
const search = document