From cdb8d29e62320fec777dc0f3ec3a9807dbcffe25 Mon Sep 17 00:00:00 2001 From: kruschen Date: Mon, 26 Aug 2024 21:02:59 +0000 Subject: [PATCH] onhover resolved most types, few are temporary hacks marked with MARKER --- src/modules/ui/cell-info.d.ts | 5 +++++ src/scripts/events/onhover.ts | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 src/modules/ui/cell-info.d.ts diff --git a/src/modules/ui/cell-info.d.ts b/src/modules/ui/cell-info.d.ts new file mode 100644 index 00000000..ec677eea --- /dev/null +++ b/src/modules/ui/cell-info.d.ts @@ -0,0 +1,5 @@ +// src/modules/ui/cell-info.d.ts +declare module 'modules/ui/cell-info.js' { + export function updateCellInfo(coords: [number, number], cellId: number, gridCell: any): void; + // Add other exports as needed + } \ No newline at end of file diff --git a/src/scripts/events/onhover.ts b/src/scripts/events/onhover.ts index 90da1d71..310cc628 100644 --- a/src/scripts/events/onhover.ts +++ b/src/scripts/events/onhover.ts @@ -1,7 +1,7 @@ import * as d3 from "d3"; import {layerIsOn} from "layers"; -import {updateCellInfo} from "modules/ui/cell-info"; +import {updateCellInfo} from "modules/ui/cell-info.js"; import {debounce} from "utils/functionUtils"; import {findCell, findGridCell, isLand} from "utils/graphUtils"; import {byId} from "utils/shorthands"; @@ -16,7 +16,7 @@ import { } from "utils/unitUtils"; import {showMainTip, tip} from "scripts/tooltips"; import {defineEmblemData} from "./utils"; -import {isState} from "utils/typeUtils"; +import {isBurg, isProvince, isReligion, isState} from "utils/typeUtils"; export const onMouseMove = debounce(handleMouseMove, 100); @@ -107,7 +107,7 @@ const onHoverEventsMap: OnHoverEventMap = { const emblemData = defineEmblemData(element); if (emblemData) { const {type, el} = emblemData; - const name = ("fullName" in el && el.fullName) || el.name; + const name = el !== 0 && (("fullname" in el && el.fullname) || el.name); //MARKER: el nutral check tip(`${name} ${type} emblem. Click to edit`); } }, @@ -127,7 +127,10 @@ const onHoverEventsMap: OnHoverEventMap = { burg: ({path}) => { const burgId = +(path.at(-10)?.dataset.id || 0); - const {population, name} = pack.burgs[burgId]; + const burg = pack.burgs[burgId]; + let population = 0; + const name = burg.name; + isBurg(burg) && (population = burg.population); tip(`${name}. Population: ${si(getBurgPopulation(population))}. Click to edit`); highlightDialogLine("burgOverview", burgId, 5000); @@ -153,7 +156,8 @@ const onHoverEventsMap: OnHoverEventMap = { lake: ({element, subgroup}) => { const lakeId = +(element.dataset.f || 0); - const name = pack.features[lakeId]?.name; + const lake = pack.features[lakeId]; + const name = lake ? (lake as IPackFeatureLake).name : ""; //MARKER: as IPackFeatureLake const fullName = subgroup === "freshwater" ? name : name + " " + subgroup; tip(`${fullName} lake. Click to edit`); }, @@ -187,7 +191,8 @@ const onHoverEventsMap: OnHoverEventMap = { religionsLayer: ({packCellId}) => { const religionId = pack.cells.religion[packCellId]; - const {type, name} = pack.religions[religionId] || {}; + const religion = pack.religions[religionId]; + const {type, name} = isReligion(religion) ? religion : {}; //MARKER: religion check const typeTip = type === "Cult" || type == "Heresy" ? type : type + " religion"; tip(`${typeTip}: ${name}`); @@ -200,7 +205,8 @@ const onHoverEventsMap: OnHoverEventMap = { const stateName = isState(state) ? state.fullName : state.name; const provinceId = pack.cells.province[packCellId]; - const provinceName = provinceId ? `${pack.provinces[provinceId].fullName}, ` : ""; + const province = pack.provinces[provinceId]; + const provinceName = isProvince(province) ? `${province.fullName}, ` : ""; tip(provinceName + stateName); highlightDialogLine("statesEditor", stateId);