Switch the studio between packs from the title bar

- List the workspace packs with their names and versions in the pack menu
- Open the chosen pack as the studio world and reconnect to its bridge
- Close the bridge of the world the studio switched away from
- Keep Disconnect in the menu for the world list
This commit is contained in:
piexel committed 2026-11-25 18:54:10 +01:00
1 parent 26c7ed9c40
commit fe99d5bda5
14 files changed
+450 -17

No files matched your search

+6
View File
@@ -32,6 +32,11 @@ export function App(): React.JSX.Element {
}
}, [])
const openPack = useCallback(async (client: BridgeClient, packKey: string) => {
const opened = new BridgeClient(await client.openPack(packKey))
setSession({ client: opened, world: await opened.world() })
}, [])
const connectLink = useCallback(
(link: string) => {
const connection = parseStudioLink(link)
@@ -62,6 +67,7 @@ export function App(): React.JSX.Element {
client={session.client}
world={session.world}
theme={theme}
onOpenPack={(packKey) => openPack(session.client, packKey)}
onDisconnect={() => setSession(null)}
/>
)
@@ -27,6 +27,7 @@ import type {
SceneEntry,
SceneViewInfo,
ServerUsage,
StudioPack,
WorldInfo
} from './types'
@@ -137,6 +138,16 @@ export class BridgeClient {
return this.json('entities')
}
/** The packs the server can switch the studio to; none on a server that cannot. */
packs(): Promise<StudioPack[]> {
return this.json('packs')
}
/** Replaces the studio world with one of the pack; the new world's bridge, once the world is ready. */
openPack(packKey: string): Promise<BridgeConnection> {
return this.json(`open-pack?${new URLSearchParams({ pack: packKey })}`, { method: 'POST' })
}
async teleport(worldX: number, worldZ: number): Promise<void> {
await this.json(`teleport?x=${worldX}&z=${worldZ}`, { method: 'POST' })
}
+8
View File
@@ -301,6 +301,14 @@ export interface SavedTile {
noWater: number
}
/** A pack the server can open the studio on. */
export interface StudioPack {
/** The pack's folder, which names its dimension too. */
key: string
name: string
version: number
}
export interface WorldInfo {
world: string
dimension: string
+28 -4
View File
@@ -1,12 +1,13 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import type { BridgeClient, MapLayerQuery, WorldRect } from '../bridge/BridgeClient'
import type { MapHover, MapLabel, Marker, ModuleViewInfo, ServerUsage, ViewInfo, WorldInfo } from '../bridge/types'
import type { MapHover, MapLabel, Marker, ModuleViewInfo, ServerUsage, StudioPack, ViewInfo, WorldInfo } from '../bridge/types'
import type { Share } from '../map/census'
import type { MapController, MapStatus, MapToggles } from '../map/MapController'
import type { Highlight } from '../map/tileStyle'
import { Waves } from 'lucide-react'
import { HelpDialog } from './HelpDialog'
import { HoverCard } from './HoverCard'
import { Glyph } from './Glyph'
import { Legend } from './Legend'
import { MapCanvas, type CanvasPoint } from './MapCanvas'
import { PickInspector, hasPickSections } from './PickInspector'
@@ -38,6 +39,8 @@ interface MapStudioProps {
client: BridgeClient
world: WorldInfo
theme: Theme
/** Switches the studio to another pack; settles once the studio is on it or the server refused. */
onOpenPack(packKey: string): Promise<void>
onDisconnect(): void
}
@@ -47,7 +50,7 @@ export interface StudioToggles extends MapToggles {
}
/** The map of one world: views on the left, the map in the middle, what is on screen on the right. */
export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps): React.JSX.Element {
export function MapStudio({ client, world, theme, onOpenPack, onDisconnect }: MapStudioProps): React.JSX.Element {
const controller = useRef<MapController | null>(null)
const [viewId, setViewId] = useState(world.views[0]?.id ?? 'biomes')
const [toggles, setToggles] = useState<StudioToggles>({ shading: true, regionBorders: false, grid: false, blocks: false, follow: false, entities: false })
@@ -70,6 +73,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps
const [sceneSummary, setSceneSummary] = useState<string | null>(null)
const [sceneProgress, setSceneProgress] = useState<number | null>(null)
const [sidebarSlot, setSidebarSlot] = useState<HTMLElement | null>(null)
const [openingPack, setOpeningPack] = useState<StudioPack | null>(null)
const loadSceneViews = useCallback(() => client.sceneViews(), [client])
const loadPatternViews = useCallback(() => client.patternViews(), [client])
const sceneViews = useModuleViews(loadSceneViews, packRevision)
@@ -90,6 +94,18 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps
const tell = useCallback((message: string) => setNotice(message), [])
const loadPacks = useCallback(() => client.packs(), [client])
const openPack = useCallback(
(pack: StudioPack) => {
setOpeningPack(pack)
onOpenPack(pack.key).catch((failure: Error) => {
setOpeningPack(null)
tell(failure.message)
})
},
[onOpenPack, tell]
)
useEffect(() => {
if (notice === null) {
return
@@ -217,9 +233,17 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps
return (
<div className="flex h-full flex-col">
<StudioToolbar world={world} onHelp={() => setHelpOpen(true)} onSettings={() => setSettingsOpen(true)} onDisconnect={onDisconnect} />
<StudioToolbar world={world} openingPack={openingPack} loadPacks={loadPacks} onOpenPack={openPack} onHelp={() => setHelpOpen(true)} onSettings={() => setSettingsOpen(true)} onDisconnect={onDisconnect} />
<SidebarSlot.Provider value={sidebarSlot}>
<div className="flex min-h-0 flex-1 gap-1.5 pr-1.5">
<div className="relative flex min-h-0 flex-1 gap-1.5 pr-1.5">
{openingPack !== null && (
<div className="absolute inset-0 z-20 flex items-center justify-center bg-background/70 backdrop-motion">
<div className="popup flex items-center gap-2 px-4 py-3 dialog-motion">
<Glyph glyph="refresh" className="animate-spin" />
Opening {openingPack.name}…
</div>
</div>
)}
<ViewList views={views} current={viewId} onSelect={selectView} slotRef={setSidebarSlot} />
{viewId === 'regions' && regions.length > 1 && (
<SidebarPanel className="flex-1 overflow-y-auto p-1.5">
@@ -0,0 +1,66 @@
import { useState } from 'react'
import { Button } from '@/components/ui/button'
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'
import { cn } from '@/lib/utils'
import type { StudioPack, WorldInfo } from '../bridge/types'
import { Glyph } from './Glyph'
interface PackSwitcherProps {
world: WorldInfo
/** The pack the studio is switching to, while the server opens it. */
opening: StudioPack | null
loadPacks(): Promise<StudioPack[]>
onOpenPack(pack: StudioPack): void
onDisconnect(): void
}
/** The open pack in the window's bar, which lists the server's packs to switch the studio to, as IntelliJ's project widget does. */
export function PackSwitcher({ world, opening, loadPacks, onOpenPack, onDisconnect }: PackSwitcherProps): React.JSX.Element {
const [packs, setPacks] = useState<StudioPack[] | null>(null)
const refreshPacks = (open: boolean): void => {
if (!open) {
return
}
loadPacks()
.then(setPacks)
.catch(() => setPacks([]))
}
const shownName = opening?.name ?? world.dimensionName
const shownVersion = opening?.version ?? world.packVersion
return (
<DropdownMenu onOpenChange={refreshPacks}>
<DropdownMenuTrigger asChild disabled={opening !== null}>
<Button variant="ghost" size="sm" className="h-[30px] max-w-[50%] gap-2 px-2 font-semibold data-[state=open]:bg-accent">
<PackBadge name={shownName} />
<span className="truncate">{shownName}</span>
{shownVersion !== undefined && <span className="shrink-0 font-normal text-secondary-text tabular-nums">v{shownVersion}</span>}
<Glyph glyph={opening === null ? 'chevronDown' : 'refresh'} className={cn(opening !== null && 'animate-spin')} />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-64">
{packs === null && <p className="px-2 py-1 text-muted-foreground">Listing packs…</p>}
{packs?.length === 0 && <p className="px-2 py-1 text-muted-foreground">No packs to switch to</p>}
{packs?.map((pack) => {
const current = pack.key === world.dimension
return (
<DropdownMenuItem key={pack.key} onSelect={() => !current && onOpenPack(pack)} className={cn(current && 'bg-selection')}>
<PackBadge name={pack.name} />
<span className="min-w-0 flex-1 truncate">{pack.name}</span>
<span className="shrink-0 text-[11.5px] text-secondary-text tabular-nums">v{pack.version}</span>
</DropdownMenuItem>
)
})}
<div className="-mx-1 my-1 h-px bg-border" />
<DropdownMenuItem onSelect={onDisconnect}>Disconnect</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}
function PackBadge({ name }: { name: string }): React.JSX.Element {
return (
<span className="flex size-5 shrink-0 items-center justify-center rounded-[5px] bg-primary text-[11px] font-semibold text-primary-foreground uppercase">
{name.charAt(0)}
</span>
)
}
@@ -5,35 +5,31 @@ import { Kbd } from '@/components/ui/kbd'
import { Separator } from '@/components/ui/separator'
import { Toggle } from '@/components/ui/toggle'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
import type { WorldInfo } from '../bridge/types'
import type { StudioPack, WorldInfo } from '../bridge/types'
import { Glyph } from './Glyph'
import type { StudioToggles } from './MapStudio'
import type { ShortcutAction } from './shortcuts'
import { useKeyText } from './useBindings'
import { IrisLogo } from './IrisLogo'
import { PackSwitcher } from './PackSwitcher'
interface StudioToolbarProps {
world: WorldInfo
/** The pack the studio is switching to, while the server opens it. */
openingPack: StudioPack | null
loadPacks(): Promise<StudioPack[]>
onOpenPack(pack: StudioPack): void
onHelp(): void
onSettings(): void
onDisconnect(): void
}
/** The window's bar: the pack the studio is connected to, which leads back to the world list, and the studio's own buttons. */
export function StudioToolbar({ world, onHelp, onSettings, onDisconnect }: StudioToolbarProps): React.JSX.Element {
/** The window's bar: the pack the studio is on, which switches to another, and the studio's own buttons. */
export function StudioToolbar({ world, openingPack, loadPacks, onOpenPack, onHelp, onSettings, onDisconnect }: StudioToolbarProps): React.JSX.Element {
return (
<header className="flex h-10 shrink-0 items-center gap-1 px-1.5">
<IrisLogo className="mx-[5px] size-5" />
<IconHint hint="Back to the world list">
<Button variant="ghost" size="sm" className="h-[30px] max-w-[50%] gap-2 px-2 font-semibold" onClick={onDisconnect}>
<span className="flex size-5 shrink-0 items-center justify-center rounded-[5px] bg-primary text-[11px] font-semibold text-primary-foreground uppercase">
{world.dimensionName.charAt(0)}
</span>
<span className="truncate">{world.dimensionName}</span>
{world.packVersion !== undefined && <span className="shrink-0 font-normal text-secondary-text tabular-nums">v{world.packVersion}</span>}
<Glyph glyph="chevronDown" />
</Button>
</IconHint>
<PackSwitcher world={world} opening={openingPack} loadPacks={loadPacks} onOpenPack={onOpenPack} onDisconnect={onDisconnect} />
<div className="flex-1" />
<MainToolbarButton action="help" hint="Show every mouse and key shortcut" onClick={onHelp}>
<Glyph glyph="help" large />