Let modules show block scenes in the studio

ModuleSetup.tooling() gives a ToolingRegistry, where a module registers
SceneViews: a catalogue of entries, each with variants the studio draws
in 3D, built from the pack for a world. View ids follow the module's id
and are unique; the frozen catalogue lists them by id.
This commit is contained in:
piexel committed 2026-11-06 01:18:45 +01:00
1 parent f57c2ce92c
commit a658cd2446
9 files changed
+164 -10

No files matched your search

@@ -1,16 +1,19 @@
package com.volmit;
import com.volmit.stage.StageGraph;
import com.volmit.tooling.ToolingRegistry;
/** What a module gets in {@link IrisModule#setup}: the stage graph it defines its stages in, the registry for
* everything else, and its own log. Stages and registrations are accepted only while {@code setup} runs; the log
* may be kept and used later, such as from lifecycle hooks.
* everything else it adds to generation, the registry for its studio tools, and its own log. Stages and registrations
* are accepted only while {@code setup} runs; the log may be kept and used later, such as from lifecycle hooks.
*/
public interface ModuleSetup {
StageGraph stages();
FeatureRegistry registry();
ToolingRegistry tooling();
/** This module's log, the same one its stages and lifecycle hooks see through their world. */
ModuleLog log();
}
@@ -0,0 +1,25 @@
package com.volmit.tooling;
import java.util.Objects;
/**
* One entry of a {@link SceneView}'s catalogue.
*
* @param key what the view names the entry by in {@link SceneView#scene}, such as an object's {@code trees/oak}
* @param name what the studio lists it as
* @param group the folder the studio lists it under, such as {@code trees}; blank for none
* @param variants how many scenes the entry has, at least 1
*/
public record SceneEntry(String key, String name, String group, int variants) {
public SceneEntry {
Objects.requireNonNull(key, "key");
Objects.requireNonNull(name, "name");
Objects.requireNonNull(group, "group");
if (key.isBlank()) {
throw new IllegalArgumentException("A scene entry needs a key");
}
if (variants < 1) {
throw new IllegalArgumentException("Scene entry " + key + " has " + variants + " variants; an entry has at least 1");
}
}
}
@@ -0,0 +1,35 @@
package com.volmit.tooling;
import com.volmit.object.GeneratedObject;
import com.volmit.resource.ResourceId;
import com.volmit.world.PackWorld;
import java.util.List;
import java.util.Optional;
/**
* A studio view of the block scenes a module builds from the pack, such as its objects: a catalogue of entries, each
* with variants the studio draws in 3D. The studio asks on its own threads, several at once, for a world of the pack
* it shows; a view keeps nothing between calls that the world's state ({@link PackWorld#state}) should keep.
*/
public interface SceneView {
/** The module's id, or one starting with it and {@code /}, such as {@code iris:objects}. */
ResourceId id();
/** The view's name in the studio's list of views, such as "Objects". */
String label();
/** One line on what the view shows. */
String description();
/** The view's entries in the world's pack, in the order the studio lists them. */
List<SceneEntry> entries(PackWorld world);
/**
* The blocks of one variant of the entry named {@code key}, its anchor where the studio centres the scene; empty
* when the pack has no such entry, or the entry has fewer variants.
*
* @param variant from 0 to the entry's {@link SceneEntry#variants()}, exclusive
*/
Optional<GeneratedObject> scene(PackWorld world, String key, int variant);
}
@@ -0,0 +1,11 @@
package com.volmit.tooling;
/**
* Where a module adds its tools to the studio, given in {@link com.volmit.ModuleSetup#tooling()} and accepted only while
* {@link com.volmit.IrisModule#setup} runs. A view's id is the module's id or starts with it and {@code /}; a second
* view with an id already registered fails the pack load, naming both modules.
*/
public interface ToolingRegistry {
/** Adds a view of block scenes the module builds from the pack, such as its objects. */
void registerSceneView(SceneView view);
}