Skip to content

Commit

Permalink
feat(ui): add ability to click on country to change map mode point-of…
Browse files Browse the repository at this point in the history
…-view
  • Loading branch information
MichaelMakesGames committed May 31, 2024
1 parent cd0798a commit 7bce924
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/renderer/src/lib/map/MapContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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,
};
}
}
Expand All @@ -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(),
}));
}
}
</script>

<div class="relative h-full w-full" style:background={bg} bind:this={container}>
Expand All @@ -389,9 +408,9 @@
{$t('export.button')}
</button>
{/if}
{#if tooltip != null && !zooming && !resizing}
{#if tooltip != null && !tooltip.hidden && !zooming && !resizing}
<div class="pointer-events-none absolute left-0 top-0 h-full w-full overflow-hidden">
<MapTooltip {...tooltip} gameState={gameStateOrNull} />
<MapTooltip x={tooltip.x} y={tooltip.y} system={tooltip.system} gameState={gameStateOrNull} />
</div>
{/if}
{#if !$gameStatePromise}
Expand Down Expand Up @@ -437,6 +456,8 @@
on:mouseout={() => {
tooltip = null;
}}
on:click={onMapClick}
class:cursor-pointer={tooltip?.countryId != null}
class="h-full w-full"
>
<g transform={transform?.toString()}>
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/lib/map/data/processMapData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -192,6 +193,7 @@ export default async function processMapData(
terraIncognitaPath,
galaxyBorderCircles,
findClosestSystem,
systemIdToCountry,
};
}

Expand Down

0 comments on commit 7bce924

Please sign in to comment.