KH2 mats filtering

master
Wynd 2025-02-09 13:51:00 +02:00
parent 2464e440a3
commit 438091d3b4
8 changed files with 162 additions and 19 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "khguide" name = "khguide"
version = "1.1.0" version = "1.2.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -5,6 +5,21 @@ use serde::Deserialize;
use crate::create_file; use crate::create_file;
pub const MATERIAL_KINDS: &[&str] = &[
"blazing",
"bright",
"dark",
"dense",
"energy",
"frost",
"lightning",
"lucid",
"power",
"remembrance",
"serenity",
"twilight",
];
#[derive(Debug, Deserialize, PartialEq, Eq)] #[derive(Debug, Deserialize, PartialEq, Eq)]
pub struct MaterialDrops { pub struct MaterialDrops {
kind: String, kind: String,

View File

@ -0,0 +1,13 @@
{% for kind in MATERIAL_KINDS %}
<input
type="checkbox"
id="{{ kind }}Filter"
name="kindFilter"
autocomplete="off"
value="{{ kind }}"
/>
<label for="{{ kind }}Filter">{{ kind|capitalize }}</label>
{% if loop.index0 == 6 %}
<br />
{% endif %}
{% endfor %}

View File

@ -0,0 +1,8 @@
<input
type="checkbox"
id="onlyTracked"
name="onlyTracked"
autocomplete="off"
value=""
/>
<label for="onlyTracked">Show only tracked</label>

View File

@ -58,6 +58,32 @@
} }
} }
} }
button {
margin-left: 16px;
background: #444;
color: #fff;
padding: 8px;
border-color: #555;
border-bottom-color: rgb(85, 85, 85);
border-style: groove;
border-bottom-color: #0a0;
transition-duration: 0.1s;
&:hover {
background: #4f4f4f;
}
&:active {
background: #3f3f3f;
transform: translateY(1px);
}
&.disabled {
opacity: 0.6;
cursor: not-allowed;
}
}
</style> </style>
{% block head %}{% endblock %} {% block head %}{% endblock %}

View File

@ -1,4 +1,9 @@
{% macro drop(label) %} {% macro drop(label) %}
<div
class="category-wrapper"
data-mat-kind="{{ category.kind }}"
data-mat-type="{{ label }}"
>
<div class="category"> <div class="category">
<img <img
src="../assets/materials/{{ category.kind }}/{{ label }}.webp" src="../assets/materials/{{ category.kind }}/{{ label }}.webp"
@ -6,6 +11,7 @@
height="64" height="64"
/> />
<h1>{{ category.kind|capitalize +}} {{+ label|capitalize }}</h1> <h1>{{ category.kind|capitalize +}} {{+ label|capitalize }}</h1>
<button onclick="track(this)">Start tracking</button>
</div> </div>
<div class="enemies"> <div class="enemies">
{% for drop in category.drops(label) %} {% for drop in category.drops(label) %}
@ -18,4 +24,5 @@
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
</div>
{% endmacro %} {% endmacro %}

View File

@ -26,4 +26,11 @@
<li><a href="./kh3/food-sim.html">Food Simulator</a></li> <li><a href="./kh3/food-sim.html">Food Simulator</a></li>
</ul> </ul>
{% endif %} {% endif %}
{% if cfg!(feature = "kh2") %}
<h1>Kingdom Hearts II</h1>
<ul>
<li><a href="./kh2/drops.html">Material Drops</a></li>
</ul>
{% endif %}
{% endblock %} {% endblock %}

View File

@ -46,9 +46,76 @@
} }
} }
</style> </style>
<script>
let showOnlyTracked = false;
let kindFilter = new Set();
document.addEventListener("DOMContentLoaded", (event) => {
const onlyTrackedFilter = document.querySelector(
'input[name="onlyTracked"]',
);
onlyTrackedFilter.addEventListener("input", function () {
showOnlyTracked = this.checked ? true : false;
filter();
});
const kindFilters = document.querySelectorAll(
'input[type="checkbox"][name="kindFilter"]',
);
kindFilters.forEach(function (item, index) {
item.addEventListener("input", function () {
if (this.checked) {
kindFilter.add(this.value);
} else {
kindFilter.delete(this.value);
}
console.log(kindFilter);
filter();
});
});
});
function track(element) {
let parent = element.parentElement.parentElement;
let isTracked = parent.dataset["isTracked"] ?? false;
isTracked = isTracked === "true" ? false : true;
parent.dataset["isTracked"] = isTracked;
element.innerHTML = isTracked ? "Stop tracking" : "Start tracking";
element.style["border-bottom-color"] = isTracked ? "#a00" : "#0a0";
filter();
}
function filter() {
const categories = document.querySelectorAll(".category-wrapper");
for (const category of categories) {
let isTracked = category.dataset["isTracked"] == "true";
let kind = category.dataset["matKind"];
let type = category.dataset["matType"];
category.style.display = "";
if (showOnlyTracked && !isTracked) {
category.style.display = "none";
}
if (kindFilter.size > 0) {
if (!kindFilter.has(kind)) {
category.style.display = "none";
}
}
}
}
</script>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% include "components/kh2/only-tracked-filter.html" %}
<br />
{% include "components/kh2/kind-filters.html" %}
<br />
{% for category in drops %} {% for category in drops %}
{% call macros::drop("shard") %} {% call macros::drop("shard") %}