diff --git a/adapters/bukkit/plugin/src/main/java/art/arcane/iris/IrisRuntime.java b/adapters/bukkit/plugin/src/main/java/art/arcane/iris/IrisRuntime.java
index 0c49e7b1f..15f49ffb3 100644
--- a/adapters/bukkit/plugin/src/main/java/art/arcane/iris/IrisRuntime.java
+++ b/adapters/bukkit/plugin/src/main/java/art/arcane/iris/IrisRuntime.java
@@ -79,6 +79,7 @@ import art.arcane.iris.studio.jigsaw.JigsawStudioService;
import art.arcane.iris.studio.object.ObjectSVC;
import art.arcane.iris.studio.object.ObjectStudioSaveService;
import art.arcane.iris.studio.view.BukkitGuiHost;
+import art.arcane.iris.studio.view.BukkitStudioPackSwitch;
import art.arcane.iris.studio.view.GuiHost;
import art.arcane.iris.studio.view.PregeneratorJob;
import art.arcane.iris.studio.wand.WandSVC;
@@ -977,6 +978,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
return;
}
BukkitGuiHost.install();
+ BukkitStudioPackSwitch.install();
StudioAppInstaller.installInBackground();
// super.onEnable() already registers this instance as a listener.
plugin.enablePlugin();
diff --git a/adapters/bukkit/plugin/src/main/java/art/arcane/iris/studio/view/BukkitStudioPackSwitch.java b/adapters/bukkit/plugin/src/main/java/art/arcane/iris/studio/view/BukkitStudioPackSwitch.java
new file mode 100644
index 000000000..c8214d6bd
--- /dev/null
+++ b/adapters/bukkit/plugin/src/main/java/art/arcane/iris/studio/view/BukkitStudioPackSwitch.java
@@ -0,0 +1,85 @@
+/*
+ * Iris is a World Generator for Minecraft Bukkit Servers
+ * Copyright (c) 2022 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.studio.view;
+
+import art.arcane.iris.Iris;
+import art.arcane.iris.platform.bukkit.plugin.VolmitSender;
+import art.arcane.iris.studio.StudioSVC;
+import art.arcane.iris.studio.bridge.StudioBridge;
+import art.arcane.iris.studio.bridge.StudioBridges;
+import art.arcane.iris.studio.bridge.StudioPack;
+import art.arcane.iris.studio.bridge.StudioPackSwitch;
+import art.arcane.iris.studio.object.StudioOpenCoordinator;
+import art.arcane.iris.world.IrisToolbelt;
+import art.arcane.iris.world.task.J;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+/** Switches the studio between the packs in the workspace by opening a studio world for the chosen one. */
+public final class BukkitStudioPackSwitch implements StudioPackSwitch {
+ /** The seed {@code /iris studio open} opens with unless told otherwise. */
+ private static final long STUDIO_SEED = 1337L;
+
+ public static void install() {
+ StudioBridges.usePackSwitch(new BukkitStudioPackSwitch());
+ }
+
+ @Override
+ public List packs() {
+ return StudioPack.inWorkspace(Iris.service(StudioSVC.class).getWorkspaceFolder());
+ }
+
+ @Override
+ public CompletableFuture open(String pack, UUID openerId) {
+ CompletableFuture opening = new CompletableFuture<>();
+ J.s(() -> Iris.service(StudioSVC.class)
+ .openTracked(senderFor(openerId), STUDIO_SEED, pack, StudioOpenCoordinator.StudioOpenKind.STANDARD, () -> {
+ }, world -> {
+ })
+ .whenComplete((result, failure) -> {
+ if (failure != null) {
+ opening.completeExceptionally(failure);
+ return;
+ }
+ opening.complete(result);
+ }));
+ return opening.thenApply(result -> bridgeTo(result.world(), openerId));
+ }
+
+ /** The opener, so the new studio moves them as {@code /iris studio open} would; the console when they are gone. */
+ private static VolmitSender senderFor(UUID openerId) {
+ Player opener = openerId == null ? null : Bukkit.getPlayer(openerId);
+ return new VolmitSender(opener == null ? Bukkit.getConsoleSender() : opener);
+ }
+
+ private static StudioBridge bridgeTo(World world, UUID openerId) {
+ try {
+ return StudioBridges.open(world.getName(), IrisToolbelt.access(world)::getEngine, openerId);
+ } catch (IOException error) {
+ throw new UncheckedIOException(error);
+ }
+ }
+}
diff --git a/core/src/main/java/art/arcane/iris/studio/bridge/StudioBridge.java b/core/src/main/java/art/arcane/iris/studio/bridge/StudioBridge.java
index e93b4d670..9a88ae297 100644
--- a/core/src/main/java/art/arcane/iris/studio/bridge/StudioBridge.java
+++ b/core/src/main/java/art/arcane/iris/studio/bridge/StudioBridge.java
@@ -98,6 +98,9 @@ public final class StudioBridge implements AutoCloseable {
private static final long ASSET_CACHE_SECONDS = 86_400L;
private static final String OVERRIDE_PREFIX = "set.";
private static final int LARGEST_BODY_BYTES = 4 * 1024 * 1024;
+ private static final long PACK_OPEN_TIMEOUT_MINUTES = 5;
+ /** How long a bridge the studio switched away from stays up, so its answer naming the new bridge gets out first. */
+ private static final long REPLACED_BRIDGE_GRACE_SECONDS = 5;
private static final String VIEW_BIOMES = "biomes";
private static final String VIEW_REGIONS = "regions";
private static final String VIEW_RIVERS = "rivers";
@@ -277,6 +280,8 @@ public final class StudioBridge implements AutoCloseable {
case "saved-worlds" -> sendJson(exchange, STATUS_OK, List.of());
case "events" -> streamEvents(exchange);
case "teleport" -> teleport(exchange, query);
+ case "packs" -> sendJson(exchange, STATUS_OK, packs(exchange));
+ case "open-pack" -> openPack(exchange, query);
case "open" -> throw new RequestError(STATUS_NOT_FOUND, "Opening a pack file from the studio is not available in Iris v4");
default -> throw new RequestError(STATUS_NOT_FOUND, "No such endpoint: " + endpoint);
}
@@ -645,6 +650,41 @@ public final class StudioBridge implements AutoCloseable {
sendJson(exchange, STATUS_OK, new MessageBody(null));
}
+ private List packs(HttpExchange exchange) {
+ requireMethod(exchange, "GET");
+ StudioPackSwitch packSwitch = StudioBridges.packSwitch();
+ return packSwitch == null ? List.of() : packSwitch.packs();
+ }
+
+ /** Replaces the studio world with one of another pack and answers with the new world's bridge, then closes this one. */
+ private void openPack(HttpExchange exchange, Query query) throws IOException {
+ requireMethod(exchange, "POST");
+ StudioPackSwitch packSwitch = StudioBridges.packSwitch();
+ if (packSwitch == null) {
+ throw new RequestError(STATUS_NOT_FOUND, "This server cannot switch packs from the studio");
+ }
+ StudioBridge opened = awaitPackOpen(packSwitch.open(query.text("pack"), world.openerId()));
+ sendJson(exchange, STATUS_OK, new OpenedBridge(opened.worldName(), opened.port(), opened.token()));
+ if (opened != this) {
+ CompletableFuture.runAsync(() -> StudioBridges.close(worldName()),
+ CompletableFuture.delayedExecutor(REPLACED_BRIDGE_GRACE_SECONDS, TimeUnit.SECONDS));
+ }
+ }
+
+ private static StudioBridge awaitPackOpen(CompletableFuture opening) {
+ try {
+ return opening.get(PACK_OPEN_TIMEOUT_MINUTES, TimeUnit.MINUTES);
+ } catch (ExecutionException failure) {
+ Throwable cause = failure.getCause() == null ? failure : failure.getCause();
+ throw new RequestError(STATUS_CONFLICT, "Could not open the pack: " + cause.getMessage());
+ } catch (TimeoutException slow) {
+ throw new RequestError(STATUS_UNAVAILABLE, "The pack is still opening; the server will show it when it is ready");
+ } catch (InterruptedException interrupted) {
+ Thread.currentThread().interrupt();
+ throw new RequestError(STATUS_UNAVAILABLE, "The bridge stopped while the pack opened");
+ }
+ }
+
private void streamEvents(HttpExchange exchange) throws IOException {
requireMethod(exchange, "GET");
Headers headers = exchange.getResponseHeaders();
@@ -797,6 +837,9 @@ public final class StudioBridge implements AutoCloseable {
private record ErrorBody(String error) {
}
+ private record OpenedBridge(String world, int port, String token) {
+ }
+
private record MessageBody(String message) {
}
diff --git a/core/src/main/java/art/arcane/iris/studio/bridge/StudioBridges.java b/core/src/main/java/art/arcane/iris/studio/bridge/StudioBridges.java
index 72faf966c..483c6c5ea 100644
--- a/core/src/main/java/art/arcane/iris/studio/bridge/StudioBridges.java
+++ b/core/src/main/java/art/arcane/iris/studio/bridge/StudioBridges.java
@@ -40,6 +40,7 @@ public final class StudioBridges {
private static final Path CONNECTION_FOLDER = Path.of(System.getProperty("user.home"), ".iris", "studio", "bridges");
private static final String OWNER_ONLY = "rw-------";
private static final Map OPEN = new ConcurrentHashMap<>();
+ private static volatile StudioPackSwitch packSwitch;
private StudioBridges() {
}
@@ -61,6 +62,24 @@ public final class StudioBridges {
return bridge;
}
+ /** Lets the studio switch packs through {@code packSwitch}; without one the studio offers no other pack. */
+ public static void usePackSwitch(StudioPackSwitch packSwitch) {
+ StudioBridges.packSwitch = packSwitch;
+ }
+
+ static StudioPackSwitch packSwitch() {
+ return packSwitch;
+ }
+
+ public static synchronized void close(String worldName) {
+ StudioBridge bridge = OPEN.remove(worldName);
+ if (bridge == null) {
+ return;
+ }
+ bridge.close();
+ withdraw(bridge);
+ }
+
public static synchronized void closeAll() {
StudioWindow.closeAll();
for (StudioBridge bridge : OPEN.values()) {
diff --git a/core/src/main/java/art/arcane/iris/studio/bridge/StudioPack.java b/core/src/main/java/art/arcane/iris/studio/bridge/StudioPack.java
new file mode 100644
index 000000000..5e2896240
--- /dev/null
+++ b/core/src/main/java/art/arcane/iris/studio/bridge/StudioPack.java
@@ -0,0 +1,78 @@
+/*
+ * Iris is a World Generator for Minecraft Servers
+ * Copyright (c) 2026 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.studio.bridge;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonParser;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * A pack the studio can open: its folder, and the name and version its dimension file gives.
+ *
+ * @param key the pack's folder, which names its dimension file too
+ */
+public record StudioPack(String key, String name, int version) {
+ private static final int UNVERSIONED = 1;
+
+ /** The packs in the workspace by name; a folder without a readable dimension file of its own name is no pack. */
+ public static List inWorkspace(File workspace) {
+ File[] folders = workspace.listFiles(File::isDirectory);
+ if (folders == null) {
+ return List.of();
+ }
+ return Arrays.stream(folders)
+ .map(StudioPack::read)
+ .filter(Objects::nonNull)
+ .sorted(Comparator.comparing(StudioPack::name, String.CASE_INSENSITIVE_ORDER))
+ .toList();
+ }
+
+ static StudioPack read(File folder) {
+ String key = folder.getName();
+ File dimensionFile = new File(folder, "dimensions/" + key + ".json");
+ if (!dimensionFile.isFile()) {
+ return null;
+ }
+ try (Reader reader = Files.newBufferedReader(dimensionFile.toPath(), StandardCharsets.UTF_8)) {
+ JsonObject dimension = JsonParser.parseReader(reader).getAsJsonObject();
+ return new StudioPack(key, textOr(dimension.get("name"), key), versionOf(dimension.get("version")));
+ } catch (IOException | JsonParseException | IllegalStateException | NumberFormatException unreadable) {
+ return null;
+ }
+ }
+
+ private static String textOr(JsonElement element, String fallback) {
+ return element != null && element.isJsonPrimitive() && !element.getAsString().isBlank() ? element.getAsString() : fallback;
+ }
+
+ private static int versionOf(JsonElement element) {
+ return element != null && element.isJsonPrimitive() ? element.getAsInt() : UNVERSIONED;
+ }
+}
diff --git a/core/src/main/java/art/arcane/iris/studio/bridge/StudioPackSwitch.java b/core/src/main/java/art/arcane/iris/studio/bridge/StudioPackSwitch.java
new file mode 100644
index 000000000..f367d9c44
--- /dev/null
+++ b/core/src/main/java/art/arcane/iris/studio/bridge/StudioPackSwitch.java
@@ -0,0 +1,36 @@
+/*
+ * Iris is a World Generator for Minecraft Servers
+ * Copyright (c) 2026 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.studio.bridge;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+/** Opens the studio on another pack, on a platform that can replace the open studio world. */
+public interface StudioPackSwitch {
+ /** The packs the studio can open, in the order to list them. */
+ List packs();
+
+ /**
+ * Replaces the open studio world with one of {@code pack} and opens a bridge to the new world.
+ *
+ * @param openerId the player the old studio was opened for, who moves to the new one; null for the console
+ */
+ CompletableFuture open(String pack, UUID openerId);
+}
diff --git a/core/src/main/java/art/arcane/iris/studio/bridge/StudioWorld.java b/core/src/main/java/art/arcane/iris/studio/bridge/StudioWorld.java
index 39f8441ec..70d792a91 100644
--- a/core/src/main/java/art/arcane/iris/studio/bridge/StudioWorld.java
+++ b/core/src/main/java/art/arcane/iris/studio/bridge/StudioWorld.java
@@ -51,6 +51,10 @@ final class StudioWorld {
return name;
}
+ UUID openerId() {
+ return openerId;
+ }
+
/** The world's engine and what the bridge draws it with; null while the world has no running engine. */
synchronized Session session() {
if (session != null && isRunning(session.engine())) {
diff --git a/core/src/test/java/art/arcane/iris/studio/bridge/StudioPackTest.java b/core/src/test/java/art/arcane/iris/studio/bridge/StudioPackTest.java
new file mode 100644
index 000000000..9a006d88f
--- /dev/null
+++ b/core/src/test/java/art/arcane/iris/studio/bridge/StudioPackTest.java
@@ -0,0 +1,55 @@
+package art.arcane.iris.studio.bridge;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class StudioPackTest {
+ @Rule
+ public TemporaryFolder workspace = new TemporaryFolder();
+
+ @Test
+ public void aPackIsNamedAndVersionedByItsDimensionFile() throws IOException {
+ dimension("natureplanet", "{\"name\": \"Etopia\", \"version\": 100}");
+
+ assertEquals(List.of(new StudioPack("natureplanet", "Etopia", 100)), StudioPack.inWorkspace(workspace.getRoot()));
+ }
+
+ @Test
+ public void commentsInTheDimensionFileAreRead() throws IOException {
+ dimension("overworld", "{\n // the pack's name\n \"name\": \"Overworld\",\n \"version\": 3\n}");
+
+ assertEquals(List.of(new StudioPack("overworld", "Overworld", 3)), StudioPack.inWorkspace(workspace.getRoot()));
+ }
+
+ @Test
+ public void aDimensionWithoutNameOrVersionFallsBackToItsFolderAndTheFirstVersion() throws IOException {
+ dimension("bare", "{}");
+
+ assertEquals(List.of(new StudioPack("bare", "bare", 1)), StudioPack.inWorkspace(workspace.getRoot()));
+ }
+
+ @Test
+ public void foldersWithoutTheirDimensionFileAreNoPacks() throws IOException {
+ workspace.newFolder("notes");
+ dimension("broken", "{\"name\": ");
+ dimension("zeta", "{\"name\": \"zeta\"}");
+ dimension("alpha", "{\"name\": \"Alpha\"}");
+
+ assertEquals(List.of("Alpha", "zeta"), StudioPack.inWorkspace(workspace.getRoot()).stream().map(StudioPack::name).toList());
+ }
+
+ private void dimension(String pack, String json) throws IOException {
+ File dimensions = new File(workspace.getRoot(), pack + "/dimensions");
+ Files.createDirectories(dimensions.toPath());
+ Files.writeString(new File(dimensions, pack + ".json").toPath(), json, StandardCharsets.UTF_8);
+ }
+}
diff --git a/studio/src/renderer/src/App.tsx b/studio/src/renderer/src/App.tsx
index 97fd80594..176842839 100644
--- a/studio/src/renderer/src/App.tsx
+++ b/studio/src/renderer/src/App.tsx
@@ -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)}
/>
)
diff --git a/studio/src/renderer/src/bridge/BridgeClient.ts b/studio/src/renderer/src/bridge/BridgeClient.ts
index 4d7673a95..a4fad0d72 100644
--- a/studio/src/renderer/src/bridge/BridgeClient.ts
+++ b/studio/src/renderer/src/bridge/BridgeClient.ts
@@ -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 {
+ 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 {
+ return this.json(`open-pack?${new URLSearchParams({ pack: packKey })}`, { method: 'POST' })
+ }
+
async teleport(worldX: number, worldZ: number): Promise {
await this.json(`teleport?x=${worldX}&z=${worldZ}`, { method: 'POST' })
}
diff --git a/studio/src/renderer/src/bridge/types.ts b/studio/src/renderer/src/bridge/types.ts
index 5beaef684..b68f1041f 100644
--- a/studio/src/renderer/src/bridge/types.ts
+++ b/studio/src/renderer/src/bridge/types.ts
@@ -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
diff --git a/studio/src/renderer/src/studio/MapStudio.tsx b/studio/src/renderer/src/studio/MapStudio.tsx
index b774da892..2374a9ffe 100644
--- a/studio/src/renderer/src/studio/MapStudio.tsx
+++ b/studio/src/renderer/src/studio/MapStudio.tsx
@@ -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
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(null)
const [viewId, setViewId] = useState(world.views[0]?.id ?? 'biomes')
const [toggles, setToggles] = useState({ 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(null)
const [sceneProgress, setSceneProgress] = useState(null)
const [sidebarSlot, setSidebarSlot] = useState(null)
+ const [openingPack, setOpeningPack] = useState(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 (
+ )}
{viewId === 'regions' && regions.length > 1 && (
diff --git a/studio/src/renderer/src/studio/PackSwitcher.tsx b/studio/src/renderer/src/studio/PackSwitcher.tsx
new file mode 100644
index 000000000..2457541d8
--- /dev/null
+++ b/studio/src/renderer/src/studio/PackSwitcher.tsx
@@ -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
+ 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(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 (
+
+
+
+
+
+ {packs === null &&
Listing packs…
}
+ {packs?.length === 0 &&
No packs to switch to
}
+ {packs?.map((pack) => {
+ const current = pack.key === world.dimension
+ return (
+ !current && onOpenPack(pack)} className={cn(current && 'bg-selection')}>
+
+ {pack.name}
+ v{pack.version}
+
+ )
+ })}
+
+ Disconnect
+
+
+ )
+}
+
+function PackBadge({ name }: { name: string }): React.JSX.Element {
+ return (
+
+ {name.charAt(0)}
+
+ )
+}
diff --git a/studio/src/renderer/src/studio/StudioToolbar.tsx b/studio/src/renderer/src/studio/StudioToolbar.tsx
index a49e8076a..e9b9e7a6e 100644
--- a/studio/src/renderer/src/studio/StudioToolbar.tsx
+++ b/studio/src/renderer/src/studio/StudioToolbar.tsx
@@ -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
+ 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 (
-
-
-
+