mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-05 01:51:23 +01:00
feat: enhance search functionality
This commit is contained in:
parent
3e339b78d4
commit
51f9db39b6
6 changed files with 91 additions and 86 deletions
|
|
@ -64,24 +64,32 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
|
|||
|
||||
// add line for each burg
|
||||
function burgsOverviewAddLines() {
|
||||
const searchText = byId("burgsSearch").value.toLowerCase().trim();
|
||||
const selectedStateId = +byId("burgsFilterState").value;
|
||||
const selectedCultureId = +byId("burgsFilterCulture").value;
|
||||
const searchText = (byId("burgsSearch").value || "").toLowerCase().trim();
|
||||
let filtered = pack.burgs.filter(b => b.i && !b.removed); // all valid burgs
|
||||
if (selectedStateId !== -1) filtered = filtered.filter(b => b.state === selectedStateId); // filtered by state
|
||||
if (selectedCultureId !== -1) filtered = filtered.filter(b => b.culture === selectedCultureId); // filtered by culture
|
||||
|
||||
// filter by search text
|
||||
|
||||
const validBurgs = pack.burgs.filter(b => b.i && !b.removed);
|
||||
let filtered = validBurgs;
|
||||
|
||||
if (searchText) {
|
||||
// filter by search text
|
||||
filtered = filtered.filter(b => {
|
||||
const name = (b.name || "").toLowerCase();
|
||||
const state = (pack.states[b.state]?.name || "").toLowerCase();
|
||||
const name = b.name.toLowerCase();
|
||||
const state = (pack.states[b.state].name || "").toLowerCase();
|
||||
const prov = pack.cells.province[b.cell];
|
||||
const province = prov ? (pack.provinces[prov]?.name || "").toLowerCase() : "";
|
||||
const culture = (pack.cultures[b.culture]?.name || "").toLowerCase();
|
||||
return name.includes(searchText) || state.includes(searchText) || province.includes(searchText) || culture.includes(searchText);
|
||||
const province = prov ? pack.provinces[prov]?.name.toLowerCase() : "";
|
||||
const culture = (pack.cultures[b.culture].name || "").toLowerCase();
|
||||
return (
|
||||
name.includes(searchText) ||
|
||||
state.includes(searchText) ||
|
||||
province.includes(searchText) ||
|
||||
culture.includes(searchText) ||
|
||||
b.group.toLowerCase().includes(searchText)
|
||||
);
|
||||
});
|
||||
}
|
||||
if (selectedStateId !== -1) filtered = filtered.filter(b => b.state === selectedStateId); // filtered by state
|
||||
if (selectedCultureId !== -1) filtered = filtered.filter(b => b.culture === selectedCultureId); // filtered by culture
|
||||
|
||||
body.innerHTML = "";
|
||||
let lines = "";
|
||||
|
|
@ -133,7 +141,7 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
|
|||
body.insertAdjacentHTML("beforeend", lines);
|
||||
|
||||
// update footer
|
||||
burgsFooterBurgs.innerHTML = filtered.length;
|
||||
burgsFooterBurgs.innerHTML = `${filtered.length} of ${validBurgs.length}`;
|
||||
burgsFooterPopulation.innerHTML = filtered.length ? si(totalPopulation / filtered.length) : 0;
|
||||
|
||||
// add listeners
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue