diff --git a/src/renderer/src/bridge/BridgeClient.ts b/src/renderer/src/bridge/BridgeClient.ts index f98f907e6..0b643d28c 100644 --- a/src/renderer/src/bridge/BridgeClient.ts +++ b/src/renderer/src/bridge/BridgeClient.ts @@ -42,8 +42,8 @@ export class BridgeClient { return this.json('world') } - hover(worldX: number, worldZ: number, signal?: AbortSignal): Promise { - return this.json(`hover?x=${worldX}&z=${worldZ}`, { signal }) + hover(view: string, worldX: number, worldZ: number, signal?: AbortSignal): Promise { + return this.json(`hover?view=${encodeURIComponent(view)}&x=${worldX}&z=${worldZ}`, { signal }) } entities(): Promise { diff --git a/src/renderer/src/bridge/types.ts b/src/renderer/src/bridge/types.ts index 6fd5ee3e3..a122c6fda 100644 --- a/src/renderer/src/bridge/types.ts +++ b/src/renderer/src/bridge/types.ts @@ -43,6 +43,30 @@ export interface MapHover { slopeDegrees: number biomeFile: string | null regionFile: string | null + /** How the spot got its region and the biome the view shows, region first. */ + pickPath: PickStep[] +} + +/** REGION, BIOME and CHILD were picked by noise; IMAGE_MAP and FOCUS were set without a pick. */ +export type PickKind = 'REGION' | 'BIOME' | 'CHILD' | 'IMAGE_MAP' | 'FOCUS' + +export interface PickStep { + kind: PickKind + picked: MapLabel + /** The biome list a BIOME step picked from, such as "land". */ + list: string | null + /** The parent name a CHILD step replaced; null when the parent kept the spot. */ + replaced: string | null + /** 0 to 1; null when nothing was picked. */ + noise: number | null + bands: PickBand[] +} + +/** One option's share of a pick noise: picked from `from` up to `to`. */ +export interface PickBand { + option: MapLabel + from: number + to: number } export interface Marker { diff --git a/src/renderer/src/studio/HoverCard.tsx b/src/renderer/src/studio/HoverCard.tsx index b861b6558..7b6872095 100644 --- a/src/renderer/src/studio/HoverCard.tsx +++ b/src/renderer/src/studio/HoverCard.tsx @@ -3,6 +3,7 @@ import { Kbd } from '@/components/ui/kbd' import type { MapHover, MapLabel } from '../bridge/types' import { hexColor } from './colors' import type { CanvasPoint } from './MapCanvas' +import { PickRows, replacedParent } from './PickRows' import { shortcutFor } from './shortcuts' interface HoverCardProps { @@ -43,14 +44,17 @@ export function HoverCard({ hover, point, viewId, detailed, minY }: HoverCardPro const subject = viewId === 'caveBiomes' ? hover.caveBiome : viewId === 'regions' ? hover.region : hover.biome const groups = detailed ? detailGroups(hover, viewId) : [] + const parent = replacedParent(hover.pickPath) return (
-

{ground(hover, minY)}

+ {parent !== null &&

child of {parent}

} +

{ground(hover, minY)}

+ {groups.map((group) => (

{group.title}

diff --git a/src/renderer/src/studio/MapStudio.tsx b/src/renderer/src/studio/MapStudio.tsx index 0cbd10562..b03ca911e 100644 --- a/src/renderer/src/studio/MapStudio.tsx +++ b/src/renderer/src/studio/MapStudio.tsx @@ -71,7 +71,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps useServerEvents(client, controller, setPlayers, tell, setConnected) useEntities(client, toggles.entities, setEntities) - useHover(client, controller, pointer, setHover) + useHover(client, controller, viewId, pointer, setHover) const selectView = useCallback((nextViewId: string) => { setViewId(nextViewId) @@ -297,6 +297,7 @@ function useEntities(client: BridgeClient, visible: boolean, setEntities: (entit function useHover( client: BridgeClient, controller: React.RefObject, + viewId: string, pointer: CanvasPoint | null, setHover: (hover: MapHover | null) => void ): void { @@ -308,11 +309,11 @@ function useHover( const spot = controller.current.worldAt(pointer.x, pointer.y) const stop = new AbortController() client - .hover(Math.floor(spot.x), Math.floor(spot.z), stop.signal) + .hover(viewId, Math.floor(spot.x), Math.floor(spot.z), stop.signal) .then(setHover) .catch(() => undefined) return () => stop.abort() - }, [client, controller, pointer, setHover]) + }, [client, controller, viewId, pointer, setHover]) } function useKeyboard( diff --git a/src/renderer/src/studio/PickRows.tsx b/src/renderer/src/studio/PickRows.tsx new file mode 100644 index 000000000..cc2d9ded5 --- /dev/null +++ b/src/renderer/src/studio/PickRows.tsx @@ -0,0 +1,83 @@ +import type { PickBand, PickStep } from '../bridge/types' +import { hexColor } from './colors' + +// Gaps between bands shrink as there are more of them, so many thin bands still read as a bar. +const WIDE_GAP_MOST_BANDS = 18 +const NARROW_GAP_MOST_BANDS = 50 + +/** How the spot got its region and biome: one row per pick, the noise value marked on every option's share of it. */ +export function PickRows({ path }: { path: PickStep[] }): React.JSX.Element | null { + if (path.length === 0) { + return null + } + return ( +
+ {path.map((step, index) => ( + + ))} +
+ ) +} + +function PickRow({ step }: { step: PickStep }): React.JSX.Element { + return ( + <> + {rowLabel(step)} + {step.noise === null ? ( + {step.kind === 'FOCUS' ? 'Focus' : 'Image map'} + ) : ( + + )} + {step.noise === null ? '' : step.noise.toFixed(3)} + + ) +} + +function NoiseBar({ bands, noise }: { bands: PickBand[]; noise: number }): React.JSX.Element { + const picked = pickedBandIndex(bands, noise) + const gap = bands.length <= WIDE_GAP_MOST_BANDS ? 2 : bands.length <= NARROW_GAP_MOST_BANDS ? 1 : 0 + return ( +
+ {bands.map((band, index) => ( + + ))} + +
+ ) +} + +/** The first band the noise does not pass; values beyond 1 pick the last, as the generator does. */ +export function pickedBandIndex(bands: PickBand[], noise: number): number { + const index = bands.findIndex((band) => noise <= band.to) + return index === -1 ? bands.length - 1 : index +} + +function rowLabel(step: PickStep): string { + switch (step.kind) { + case 'REGION': + return 'Region' + case 'BIOME': + return step.list === null ? 'Biome' : step.list.charAt(0).toUpperCase() + step.list.slice(1) + case 'CHILD': + return 'Child' + case 'IMAGE_MAP': + case 'FOCUS': + return step.picked.kind === 'REGION' ? 'Region' : 'Biome' + } +} + +/** The parent the spot's biome replaced, when a child step replaced one. */ +export function replacedParent(path: PickStep[]): string | null { + return path.findLast((step) => step.kind === 'CHILD' && step.replaced !== null)?.replaced ?? null +}