mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Hover card: show how the spot was picked
One row per pick under the card's title: region, biome list and each child level, with the options' shares of the noise as a segmented bar, the picked one in its colour and a marker at the noise value. A child names the parent it replaced on its own line. The card is a little wider so long biome names keep their region beside them.
This commit is contained in:
1 parent
f1171307cd
commit
e20bf1dd57
5 files changed
+119
-7
No files matched your search
@@ -42,8 +42,8 @@ export class BridgeClient {
|
||||
return this.json('world')
|
||||
}
|
||||
|
||||
hover(worldX: number, worldZ: number, signal?: AbortSignal): Promise<MapHover> {
|
||||
return this.json(`hover?x=${worldX}&z=${worldZ}`, { signal })
|
||||
hover(view: string, worldX: number, worldZ: number, signal?: AbortSignal): Promise<MapHover> {
|
||||
return this.json(`hover?view=${encodeURIComponent(view)}&x=${worldX}&z=${worldZ}`, { signal })
|
||||
}
|
||||
|
||||
entities(): Promise<Marker[]> {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 (
|
||||
<div
|
||||
ref={card}
|
||||
className="pointer-events-none absolute z-10 w-72 rounded-[10px] border border-overlay-border bg-popover px-3.5 py-3 text-popover-foreground shadow-xl backdrop-blur-sm"
|
||||
className="pointer-events-none absolute z-10 w-80 rounded-[10px] border border-overlay-border bg-popover px-3.5 py-3 text-popover-foreground shadow-xl backdrop-blur-sm"
|
||||
style={position}
|
||||
>
|
||||
<Header subject={subject} region={viewId === 'regions' ? null : hover.region} />
|
||||
<p className="mt-0.5 text-[12px] text-secondary-text tabular-nums">{ground(hover, minY)}</p>
|
||||
{parent !== null && <p className="mt-0.5 truncate text-[12px] text-secondary-text">child of {parent}</p>}
|
||||
<p className="mt-0.5 truncate text-[12px] text-secondary-text tabular-nums">{ground(hover, minY)}</p>
|
||||
<PickRows path={hover.pickPath} />
|
||||
{groups.map((group) => (
|
||||
<section key={group.title} className="mt-2.5">
|
||||
<h3 className="text-[11px] font-semibold text-muted-foreground">{group.title}</h3>
|
||||
|
||||
@@ -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<MapController | null>,
|
||||
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(
|
||||
|
||||
@@ -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 (
|
||||
<div className="mt-2 grid grid-cols-[auto_1fr_auto] items-center gap-x-2.5 gap-y-1.5 text-[11.5px]">
|
||||
{path.map((step, index) => (
|
||||
<PickRow key={index} step={step} />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function PickRow({ step }: { step: PickStep }): React.JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<span className="text-muted-foreground">{rowLabel(step)}</span>
|
||||
{step.noise === null ? (
|
||||
<span className="truncate text-secondary-text">{step.kind === 'FOCUS' ? 'Focus' : 'Image map'}</span>
|
||||
) : (
|
||||
<NoiseBar bands={step.bands} noise={step.noise} />
|
||||
)}
|
||||
<span className="text-right font-mono text-[11px] text-secondary-text tabular-nums">{step.noise === null ? '' : step.noise.toFixed(3)}</span>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
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 (
|
||||
<div className="relative flex h-1.5 min-w-0" style={{ gap }}>
|
||||
{bands.map((band, index) => (
|
||||
<span
|
||||
key={index}
|
||||
className="h-full min-w-px rounded-[2px]"
|
||||
style={{
|
||||
flexGrow: band.to - band.from,
|
||||
flexBasis: 0,
|
||||
backgroundColor: index === picked ? hexColor(band.option.color) : 'var(--overlay-border)'
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
<span
|
||||
className="absolute top-1/2 h-3 w-0.5 -translate-x-1/2 -translate-y-1/2 bg-foreground shadow-[0_0_0_1px_var(--popover)]"
|
||||
style={{ left: `${Math.min(1, Math.max(0, noise)) * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** 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
|
||||
}
|
||||
Reference in new issue
Block a user