mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-04 17:41:23 +01:00
Fix null safety and performance in overview dialogs search (#1272)
* Initial plan * fix: add optional chaining and optimize performance in overview dialogs Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
This commit is contained in:
parent
330d098b0c
commit
03b84354ad
2 changed files with 7 additions and 4 deletions
|
|
@ -75,10 +75,10 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
|
||||||
// filter by search text
|
// filter by search text
|
||||||
filtered = filtered.filter(b => {
|
filtered = filtered.filter(b => {
|
||||||
const name = b.name.toLowerCase();
|
const name = b.name.toLowerCase();
|
||||||
const state = (pack.states[b.state].name || "").toLowerCase();
|
const state = (pack.states[b.state]?.name || "").toLowerCase();
|
||||||
const prov = pack.cells.province[b.cell];
|
const prov = pack.cells.province[b.cell];
|
||||||
const province = prov ? pack.provinces[prov]?.name.toLowerCase() : "";
|
const province = prov ? pack.provinces[prov]?.name.toLowerCase() : "";
|
||||||
const culture = (pack.cultures[b.culture].name || "").toLowerCase();
|
const culture = (pack.cultures[b.culture]?.name || "").toLowerCase();
|
||||||
return (
|
return (
|
||||||
name.includes(searchText) ||
|
name.includes(searchText) ||
|
||||||
state.includes(searchText) ||
|
state.includes(searchText) ||
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,16 @@ function overviewRivers() {
|
||||||
let lines = "";
|
let lines = "";
|
||||||
const unit = distanceUnitInput.value;
|
const unit = distanceUnitInput.value;
|
||||||
|
|
||||||
|
// Precompute a lookup map from river id to river for efficient basin lookup
|
||||||
|
const riversById = new Map(pack.rivers.map(river => [river.i, river]));
|
||||||
|
|
||||||
let filteredRivers = pack.rivers;
|
let filteredRivers = pack.rivers;
|
||||||
const searchText = byId("riversSearch").value.toLowerCase().trim();
|
const searchText = byId("riversSearch").value.toLowerCase().trim();
|
||||||
if (searchText) {
|
if (searchText) {
|
||||||
filteredRivers = filteredRivers.filter(r => {
|
filteredRivers = filteredRivers.filter(r => {
|
||||||
const name = (r.name || "").toLowerCase();
|
const name = (r.name || "").toLowerCase();
|
||||||
const type = (r.type || "").toLowerCase();
|
const type = (r.type || "").toLowerCase();
|
||||||
const basin = pack.rivers.find(river => river.i === r.basin);
|
const basin = riversById.get(r.basin);
|
||||||
const basinName = basin ? (basin.name || "").toLowerCase() : "";
|
const basinName = basin ? (basin.name || "").toLowerCase() : "";
|
||||||
return name.includes(searchText) || type.includes(searchText) || basinName.includes(searchText);
|
return name.includes(searchText) || type.includes(searchText) || basinName.includes(searchText);
|
||||||
});
|
});
|
||||||
|
|
@ -50,7 +53,7 @@ function overviewRivers() {
|
||||||
const discharge = r.discharge + " m³/s";
|
const discharge = r.discharge + " m³/s";
|
||||||
const length = rn(r.length * distanceScale) + " " + unit;
|
const length = rn(r.length * distanceScale) + " " + unit;
|
||||||
const width = rn(r.width * distanceScale, 3) + " " + unit;
|
const width = rn(r.width * distanceScale, 3) + " " + unit;
|
||||||
const basin = pack.rivers.find(river => river.i === r.basin)?.name;
|
const basin = riversById.get(r.basin)?.name;
|
||||||
|
|
||||||
lines += /* html */ `<div
|
lines += /* html */ `<div
|
||||||
class="states"
|
class="states"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue