Make the Caves view a viewer only

The Caves view no longer edits cave files. It shows each cave at the
chosen size and variant, and redraws when a file is saved. The form,
creating caves from the studio and EditableSceneView.showsNodes() are
gone.
This commit is contained in:
piexel committed 2026-11-13 09:53:30 +01:00
1 parent 263f5baa3c
commit 22d69f362f
9 files changed
+14 -151

No files matched your search

+1 -2
View File
@@ -550,8 +550,7 @@ final class RuinScenes implements SceneView {
settings (`NodeSettings`, shown as the pack's schema describes their type), the nodes it holds and the `Edits` the
studio may make (a child list to move nodes into, whether it moves, the `Addition`s it offers). Places in the file
are `JsonPath`s of `Key` and `Index` steps. The studio writes the file itself, rewriting only what changes; the
view never writes. A view whose file reads as one node of settings returns false from `showsNodes()`, and the
studio shows that node's settings beside the scene instead of a graph. A view whose entries the studio may create and delete returns a `SceneCreation` from
view never writes. A view whose entries the studio may create and delete returns a `SceneCreation` from
`creation()`: the resource kind of its files, the starter JSON of a new entry and the text other files name an
entry by; the studio does the writing, listing of uses and trashing.
- Absent values are empty, never blank or `-1`: an entry without a group, a node that draws no part of the scene
@@ -21,14 +21,6 @@ public interface EditableSceneView extends SceneView {
*/
NodeGraph graph(PackWorld world, String key, JsonText text);
/**
* Whether the studio shows the file's graph as nodes under the scene, which is the default. A view whose file reads
* as one node of settings says no, and the studio shows those settings beside the scene instead.
*/
default boolean showsNodes() {
return true;
}
/** How the studio creates and removes entries of this view; empty when it may not, which is the default. */
default Optional<SceneCreation> creation() {
return Optional.empty();
@@ -385,7 +385,7 @@ public final class StudioBridge implements AutoCloseable {
boolean editable = editors.edits(view.id());
SceneSizesWire sizes = scenes.sizes(view.id()).map(SceneSizesWire::of).orElse(null);
return new SceneViewInfo(view.id(), view.label(), view.description(), editable, editable && editors.creates(view.id()),
editable && editors.showsNodes(view.id()), scenes.isBaked(view.id()), scenes.hasParts(view.id()), sizes);
scenes.isBaked(view.id()), scenes.hasParts(view.id()), sizes);
}).toList();
}
@@ -922,8 +922,8 @@ public final class StudioBridge implements AutoCloseable {
/** A scene view as the studio lists it; {@code editable} when its entries can be edited as nodes, {@code creatable} when they can also be created and deleted, {@code baked} when their bake can be timed, {@code parts} when the blocks of a scene can be told by the part that placed them. */
/** @param sizes null when the view's entries each have a size of their own */
private record SceneViewInfo(String id, String label, String description, boolean editable, boolean creatable, boolean nodes,
boolean baked, boolean parts, SceneSizesWire sizes) {
private record SceneViewInfo(String id, String label, String description, boolean editable, boolean creatable, boolean baked,
boolean parts, SceneSizesWire sizes) {
}
private record SceneSizesWire(List<Integer> blocksAcross, int opening) {
@@ -119,11 +119,6 @@ public final class StudioEditors {
return save(viewId, key, file, text);
}
/** Whether the studio shows the files of {@code viewId} as nodes, rather than as one node's settings beside the scene. */
public boolean showsNodes(String viewId) {
return views.ask(viewId, "tell whether its files show as nodes", EditableSceneView::showsNodes);
}
/** Whether entries of {@code viewId} can be created and removed from the studio. */
public boolean creates(String viewId) {
return views.ask(viewId, "tell whether entries are created", view -> view.creation().isPresent());
@@ -5,11 +5,10 @@ import art.arcane.iris.engine.object.TestSettings;
import com.volmit.geometry.BlockPosition;
import com.volmit.object.GeneratedObject;
import com.volmit.object.ObjectBlock;
import com.volmit.tooling.GraphNode;
import com.volmit.tooling.JsonText;
import com.volmit.tooling.NodeGraph;
import com.volmit.tooling.EditableSceneView;
import com.volmit.tooling.SceneEntry;
import com.volmit.tooling.SceneRequest;
import com.volmit.tooling.SceneView;
import org.junit.Test;
import java.util.HashSet;
@@ -88,22 +87,9 @@ public class CaveScenesTest {
}
@Test
public void aCaveFileIsOneNodeWithASectionForEachPart() {
NodeGraph graph = view.graph(world, "deep/mixed", JsonText.parse(MIXED));
assertFalse(view.showsNodes());
GraphNode cave = graph.roots().getFirst();
assertEquals("mixed", cave.title());
assertTrue(cave.children().isEmpty());
assertEquals(List.of("Cave", "Tunnel", "Cavern", "Pillars"), cave.settings().stream().map(GraphNode.NodeSettings::title).toList());
}
@Test
public void anUnwrittenPartHasASectionSoSettingItWritesIt() {
NodeGraph graph = view.graph(world, "tunnels", JsonText.parse(TUNNELS_ONLY));
assertEquals(List.of("Cave", "Tunnel", "Cavern (unset)", "Pillars (unset)"),
graph.roots().getFirst().settings().stream().map(GraphNode.NodeSettings::title).toList());
public void theViewOnlyShowsCavesAndEditsNone() {
SceneView registered = view;
assertFalse(registered instanceof EditableSceneView);
}
private GeneratedObject scene(String key, int variant, int size) {
@@ -1,70 +0,0 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.modules.carve;
import com.volmit.tooling.GraphNode;
import com.volmit.tooling.GraphNode.Edits;
import com.volmit.tooling.GraphNode.NodeSettings;
import com.volmit.tooling.JsonPath;
import com.volmit.tooling.JsonText;
import com.volmit.tooling.NodeGraph;
import java.util.List;
import java.util.OptionalInt;
import java.util.Set;
/**
* A cave file as one node of settings, a section each for the cave, its tunnels, its caverns and their pillars. Every
* section is there, written or not, since setting a value in one writes it into the file.
*/
final class CaveGraph {
private static final String TUNNEL = "tunnel";
private static final String CAVERN = "cavern";
private static final String PILLARS = "pillars";
private static final String UNWRITTEN = " (unset)";
private static final Set<String> NONE_ELSEWHERE = Set.of();
private CaveGraph() {
}
/** @throws IllegalArgumentException when the file does not hold an object */
static NodeGraph of(String name, JsonText text) {
if (!(text.root() instanceof JsonText.Obj root)) {
throw new IllegalArgumentException("The file does not hold an object");
}
JsonPath tunnelPath = JsonPath.ROOT.member(TUNNEL);
JsonPath cavernPath = JsonPath.ROOT.member(CAVERN);
JsonPath pillarsPath = cavernPath.member(PILLARS);
List<NodeSettings> sections = List.of(
new NodeSettings("Cave", JsonPath.ROOT, Cave.class, Set.of(TUNNEL, CAVERN)),
new NodeSettings(titled("Tunnel", root.get(TUNNEL).isPresent()), tunnelPath, CaveTunnel.class, NONE_ELSEWHERE),
new NodeSettings(titled("Cavern", root.get(CAVERN).isPresent()), cavernPath, CaveCavern.class, Set.of(PILLARS)),
new NodeSettings(titled("Pillars", hasMember(root, CAVERN, PILLARS)), pillarsPath, CavePillars.class, NONE_ELSEWHERE));
GraphNode cave = new GraphNode("Cave", name, JsonPath.ROOT, OptionalInt.empty(), List.of(), sections, List.of(), Edits.NONE);
return new NodeGraph(List.of(cave));
}
private static String titled(String section, boolean written) {
return written ? section : section + UNWRITTEN;
}
private static boolean hasMember(JsonText.Obj root, String member, String inner) {
return root.get(member).orElse(null) instanceof JsonText.Obj object && object.get(inner).isPresent();
}
}
@@ -20,14 +20,10 @@ package art.arcane.iris.modules.carve;
import com.volmit.object.GeneratedObject;
import com.volmit.resource.ResourceId;
import com.volmit.tooling.EditableSceneView;
import com.volmit.tooling.JsonText;
import com.volmit.tooling.NodeGraph;
import com.volmit.tooling.SceneCreation;
import com.volmit.tooling.SceneEntry;
import com.volmit.tooling.SceneFile;
import com.volmit.tooling.SceneRequest;
import com.volmit.tooling.SceneSizes;
import com.volmit.tooling.SceneView;
import com.volmit.world.PackWorld;
import java.util.LinkedHashMap;
@@ -38,19 +34,11 @@ import java.util.Optional;
/**
* The studio's Caves view: every cave of the pack's {@code caves/} folder carved over a square of the world under a
* flat surface, the carved space drawn as blocks so its shape shows. Each variant is the same cave elsewhere in the
* world. A cave's settings are shown beside it, and the studio redraws the cave as they change.
* world. A viewer only: caves are written in their files, and the studio redraws a cave when its file is saved.
*/
public final class CaveScenes implements EditableSceneView {
public final class CaveScenes implements SceneView {
private static final ResourceId ID = ResourceId.parse("iris:carve/caves");
private static final char FOLDER_SEPARATOR = '/';
/** Other files name a cave by its bare key, in a {@code caves} list. */
private static final String REFERENCE_PREFIX = "";
private static final String STARTER = """
{
"tunnel": {"width": {"min": 4, "max": 7}, "stretch": 96}
}
""";
private static final SceneCreation CREATION = new SceneCreation(CaveResources.CAVES, STARTER, REFERENCE_PREFIX);
@Override
public ResourceId id() {
@@ -91,29 +79,6 @@ public final class CaveScenes implements EditableSceneView {
return Optional.of(world.state(Previews.class, ignored -> new Previews()).of(world, new Place(id, request.variant(), size), cave));
}
@Override
public Optional<SceneFile> fileOf(PackWorld world, String key) {
ResourceId id = world.resources().idOf(key);
return world.resources().ids(CaveResources.CAVES).contains(id)
? Optional.of(new SceneFile(CaveResources.CAVES, id))
: Optional.empty();
}
@Override
public NodeGraph graph(PackWorld world, String key, JsonText text) {
return CaveGraph.of(key.substring(key.lastIndexOf(FOLDER_SEPARATOR) + 1), text);
}
@Override
public boolean showsNodes() {
return false;
}
@Override
public Optional<SceneCreation> creation() {
return Optional.of(CREATION);
}
private static SceneEntry entryOf(ResourceId id) {
String path = id.path();
int lastSeparator = path.lastIndexOf(FOLDER_SEPARATOR);
-2
View File
@@ -40,8 +40,6 @@ export interface SceneEntry {
export interface SceneViewInfo extends ModuleViewInfo {
editable: boolean
creatable: boolean
/** Whether an editable view's files show as nodes under the scene; else as one node's settings beside it. */
nodes: boolean
baked: boolean
parts: boolean
/** The sizes the scenes can be built at, or null when each entry has its own. */
@@ -65,10 +65,8 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce
const bakeTiming = useBakeTiming(client, view.id, entry?.key ?? null, view.baked, packRevision, tell)
const editor = useNodeEditor(client, view.id, view.editable ? (entry?.key ?? null) : null, packRevision, tell)
const editsAsForm = view.editable && !view.nodes
const [selectedPath, setSelectedPath] = useState<JsonPath | null>(null)
const roots = editor.state?.roots ?? null
const selected = roots === null ? null : editsAsForm ? (roots[0] ?? null) : selectedPath !== null ? nodeWithPath(roots, selectedPath) : null
const selected = editor.state?.roots != null && selectedPath !== null ? nodeWithPath(editor.state.roots, selectedPath) : null
const values = useMemo(() => (editor.state === null ? undefined : parsedText(editor.state.text)), [editor.state])
const suggestions = useMemo(() => new SuggestionStore((of) => client.suggestions(of)), [client, packRevision])
@@ -133,7 +131,7 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce
onSize={(next) => setChosenSize({ viewId: view.id, size: next })}
onPick={view.parts ? pickPart : undefined}
/>
{view.editable && !editsAsForm && entry !== null && (
{view.editable && entry !== null && (
<NodePane
editor={editor}
entryKey={entry.key}