From 7bce92434f4f70f287169e8560aa65d0413f0f28 Mon Sep 17 00:00:00 2001 From: Michael Moore Date: Fri, 31 May 2024 00:17:04 -0500 Subject: [PATCH] feat(ui): add ability to click on country to change map mode point-of-view --- src/renderer/src/lib/map/MapContainer.svelte | 37 +++++++++++++++---- .../src/lib/map/data/processMapData.ts | 2 + 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/lib/map/MapContainer.svelte b/src/renderer/src/lib/map/MapContainer.svelte index 36d0eff..76ace73 100644 --- a/src/renderer/src/lib/map/MapContainer.svelte +++ b/src/renderer/src/lib/map/MapContainer.svelte @@ -18,7 +18,12 @@ stellarisDataPromiseStore, stellarisPathStore, } from '../loadStellarisData'; - import { appStellarisLanguage, lastProcessedMapSettings, mapSettings } from '../settings'; + import { + appStellarisLanguage, + editedMapSettings, + lastProcessedMapSettings, + mapSettings, + } from '../settings'; import stellarMapsApi from '../stellarMapsApi'; import { debounce, timeItAsync, toastError } from '../utils'; import Map from './Map.svelte'; @@ -305,6 +310,8 @@ x: number; y: number; system: GalacticObject; + countryId: number | null; + hidden: boolean; } | null = null; function onMouseMoveInner(e: MouseEvent) { if (dataOrNull != null && !resizing && !zooming) { @@ -323,6 +330,7 @@ ]; const system = dataOrNull.findClosestSystem(-svgPoint[0], svgPoint[1]); if (system) { + const countryId = dataOrNull.systemIdToCountry[system.id] ?? null; const settings = get(mapSettings); const processedSystem = dataOrNull?.systems.find((s) => s.id === system.id); if (processedSystem == null) { @@ -340,16 +348,15 @@ if (settings.terraIncognita && !processedSystem.systemIsKnown) { tooltip = null; - } else if ( - Math.hypot(tooltipPoint[0] - e.offsetX, tooltipPoint[1] - e.offsetY) > - TOOLTIP_MAX_DISTANCE - ) { - tooltip = null; } else { tooltip = { x: tooltipPoint[0], y: tooltipPoint[1], system: system, + hidden: + Math.hypot(tooltipPoint[0] - e.offsetX, tooltipPoint[1] - e.offsetY) > + TOOLTIP_MAX_DISTANCE, + countryId, }; } } @@ -366,6 +373,18 @@ } onMouseMoveInnerDebounced(e); } + + function onMapClick() { + const countryId = tooltip?.countryId; + if (countryId != null) { + editedMapSettings.update((value) => ({ ...value, mapModePointOfView: countryId.toString() })); + mapSettings.update((value) => ({ ...value, mapModePointOfView: countryId.toString() })); + lastProcessedMapSettings.update((value) => ({ + ...value, + mapModePointOfView: countryId.toString(), + })); + } + }
@@ -389,9 +408,9 @@ {$t('export.button')} {/if} - {#if tooltip != null && !zooming && !resizing} + {#if tooltip != null && !tooltip.hidden && !zooming && !resizing}
- +
{/if} {#if !$gameStatePromise} @@ -437,6 +456,8 @@ on:mouseout={() => { tooltip = null; }} + on:click={onMapClick} + class:cursor-pointer={tooltip?.countryId != null} class="h-full w-full" > diff --git a/src/renderer/src/lib/map/data/processMapData.ts b/src/renderer/src/lib/map/data/processMapData.ts index 89b35c8..1b2d0cc 100644 --- a/src/renderer/src/lib/map/data/processMapData.ts +++ b/src/renderer/src/lib/map/data/processMapData.ts @@ -33,6 +33,7 @@ export default async function processMapData( const settings = { ...rawSettings }; if (settings.hyperlaneMetroStyle) settings.alignStarsToGrid = true; if (settings.alignStarsToGrid) settings.hyperlaneSensitiveBorders = false; + if (settings.mapMode !== 'default') settings.unionMode = false; // get these started right away; await just before needed const emblemsPromise = timeItAsync( @@ -192,6 +193,7 @@ export default async function processMapData( terraIncognitaPath, galaxyBorderCircles, findClosestSystem, + systemIdToCountry, }; }