mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +00:00
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:
1 parent
263f5baa3c
commit
22d69f362f
9 files changed
+14
-151
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user