not good but not bad

This commit is contained in:
33333-33333 2026-05-26 15:32:27 +09:00
commit 4f0df3f6c5
11 changed files with 1284 additions and 622 deletions

19
app.js
View file

@ -148,7 +148,7 @@ function getStats(map) {
["New Towns", countText(map.newTowns)],
["Municipalities", map.adminCenters.length],
["Admin changed cells", map.adminDebug ? `${map.adminDebug.changedAfterLandscapePartition || 0} partition / ${map.adminDebug.changedAfterSnap || 0} snap` : "-"],
["Regional changed cells", map.regionalDebug?.regionalChangedAfterNaturalPartition ?? "-"],
["Prefecture source", map.regionalDebug?.prefectureSource ?? "-"],
];
}
@ -201,6 +201,12 @@ function adminName(map, adminId) {
return center?.name || (adminId >= 0 ? `Municipality ${adminId + 1}` : "-");
}
function prefectureNameForCell(map, i) {
const id = map.prefectureRegionId?.[i] ?? -1;
const region = (map.prefectureRegions || []).find((p) => p.id === id);
return region?.name || (id >= 0 ? `Prefecture ${id + 1}` : "-");
}
function updateTooltip(event) {
if (!state.map || !tooltipEl) return;
const rect = canvas.getBoundingClientRect();
@ -216,6 +222,7 @@ function updateTooltip(event) {
const density = state.map.populationDensity?.[i] ?? 0;
const lines = [
`<strong>${entity ? `${entity.name} / ${entity.kind}` : `${x}, ${y}`}</strong>`,
`Prefecture: ${prefectureNameForCell(state.map, i)}`,
`Admin: ${adminName(state.map, state.map.adminId?.[i] ?? -1)}`,
`Land: ${state.map.sea?.[i] ? "Sea" : landuseName(state.map.landuse?.[i])}`,
`Elevation: ${elevation.toFixed(3)} / Slope: ${(state.map.slope?.[i] ?? 0).toFixed(3)}`,
@ -223,8 +230,14 @@ function updateTooltip(event) {
];
if (entity?.population) lines.splice(1, 0, `Population: ${entity.population.toLocaleString()}`);
tooltipEl.innerHTML = lines.join("<br>");
tooltipEl.style.left = `${event.clientX - rect.left + 14}px`;
tooltipEl.style.top = `${event.clientY - rect.top + 14}px`;
const margin = 8;
const offset = 14;
const maxLeft = Math.max(margin, rect.width - tooltipEl.offsetWidth - margin);
const maxTop = Math.max(margin, rect.height - tooltipEl.offsetHeight - margin);
const desiredLeft = event.clientX - rect.left + offset;
const desiredTop = event.clientY - rect.top + offset;
tooltipEl.style.left = `${Math.min(Math.max(margin, desiredLeft), maxLeft)}px`;
tooltipEl.style.top = `${Math.min(Math.max(margin, desiredTop), maxTop)}px`;
tooltipEl.classList.add("visible");
}