mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Add pattern views to the studio tooling
A StudioView is now either a SceneView (block scenes) or a PatternView: entries a module lays out from above, one block per column, at a depth below the top, over a PatternArea. BlockPattern holds the picks and the blocks they index. Both kinds register through ToolingRegistry.registerView and share one id space in the host.
This commit is contained in:
1 parent
a658cd2446
commit
2befcb9487
13 files changed
+275
-59
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* What a {@link PatternView} places over a square of columns: the distinct blocks, and which of them each column holds,
|
||||
* row by row from the north west.
|
||||
*/
|
||||
public final class BlockPattern {
|
||||
/** What {@link #pickAt} gives for a column the pattern places nothing at. */
|
||||
public static final int NO_BLOCK = -1;
|
||||
|
||||
private final int columns;
|
||||
private final List<BlockState> blocks;
|
||||
private final int[] picks;
|
||||
|
||||
private BlockPattern(int columns, List<BlockState> blocks, int[] picks) {
|
||||
this.columns = columns;
|
||||
this.blocks = List.copyOf(blocks);
|
||||
this.picks = picks;
|
||||
}
|
||||
|
||||
/**
|
||||
* The pattern of {@code columns} by {@code columns} columns holding {@code columnBlocks}, row by row from the north
|
||||
* west, null where nothing is placed.
|
||||
*/
|
||||
public static BlockPattern of(int columns, BlockState[] columnBlocks) {
|
||||
if (columns < 1 || columnBlocks.length != columns * columns) {
|
||||
throw new IllegalArgumentException("A pattern " + columns + " columns across holds " + columns * columns
|
||||
+ " columns, not " + columnBlocks.length);
|
||||
}
|
||||
List<BlockState> blocks = new ArrayList<>();
|
||||
Map<BlockState, Integer> indexByBlock = new HashMap<>();
|
||||
int[] picks = new int[columnBlocks.length];
|
||||
for (int column = 0; column < columnBlocks.length; column++) {
|
||||
BlockState block = columnBlocks[column];
|
||||
picks[column] = block == null ? NO_BLOCK : indexByBlock.computeIfAbsent(block, added -> {
|
||||
blocks.add(added);
|
||||
return blocks.size() - 1;
|
||||
});
|
||||
}
|
||||
return new BlockPattern(columns, blocks, picks);
|
||||
}
|
||||
|
||||
public int columns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
/** The distinct blocks the pattern places, in the order they first appear. */
|
||||
public List<BlockState> blocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/** Which of {@link #blocks()} the column holds, or {@link #NO_BLOCK}. */
|
||||
public int pickAt(int column, int row) {
|
||||
return picks[row * columns + column];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
/**
|
||||
* A square of columns a {@link PatternView} is asked for: {@code columns} by {@code columns} of them, one every
|
||||
* {@code blocksPerColumn} blocks, the first at block ({@code x}, {@code z}), row by row from the north west.
|
||||
*/
|
||||
public record PatternArea(int x, int z, int columns, int blocksPerColumn) {
|
||||
public PatternArea {
|
||||
if (columns < 1) {
|
||||
throw new IllegalArgumentException("A pattern area has at least 1 column across, not " + columns);
|
||||
}
|
||||
if (blocksPerColumn < 1) {
|
||||
throw new IllegalArgumentException("A pattern area has a column every block or farther apart, not every " + blocksPerColumn);
|
||||
}
|
||||
}
|
||||
|
||||
/** The block x of the column {@code column} across. */
|
||||
public int blockX(int column) {
|
||||
return x + column * blocksPerColumn;
|
||||
}
|
||||
|
||||
/** The block z of the row {@code row} down. */
|
||||
public int blockZ(int row) {
|
||||
return z + row * blocksPerColumn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* One entry of a {@link PatternView}'s catalogue.
|
||||
*
|
||||
* @param key what the view names the entry by in {@link PatternView#pattern}
|
||||
* @param name what the studio lists it as, such as "Layer 1"
|
||||
* @param group what the studio lists it under, such as its biome's name; blank for none
|
||||
* @param depths how many blocks deep the entry can reach, at least 1
|
||||
* @param facts short lines the studio shows with the entry, such as "2 to 4 blocks thick"
|
||||
*/
|
||||
public record PatternEntry(String key, String name, String group, int depths, List<String> facts) {
|
||||
public PatternEntry {
|
||||
Objects.requireNonNull(key, "key");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Objects.requireNonNull(group, "group");
|
||||
facts = List.copyOf(facts);
|
||||
if (key.isBlank()) {
|
||||
throw new IllegalArgumentException("A pattern entry needs a key");
|
||||
}
|
||||
if (depths < 1) {
|
||||
throw new IllegalArgumentException("Pattern entry " + key + " reaches " + depths + " blocks deep; an entry reaches at least 1");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A studio view of the block patterns a module lays over the world, such as a biome's palettes: a catalogue of
|
||||
* entries, each drawn from above, one block per column, at a depth below its top.
|
||||
*/
|
||||
public non-sealed interface PatternView extends StudioView {
|
||||
/** The view's entries in the world's pack, in the order the studio lists them. */
|
||||
List<PatternEntry> entries(PackWorld world);
|
||||
|
||||
/**
|
||||
* The blocks the entry named {@code key} places {@code depth} blocks below its top across {@code area}, as the world
|
||||
* places them; empty when the pack has no such entry.
|
||||
*
|
||||
* @param depth from 0, the top block, to the entry's {@link PatternEntry#depths()}, exclusive
|
||||
*/
|
||||
Optional<BlockPattern> pattern(PackWorld world, String key, int depth, PatternArea area);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.List;
|
||||
@@ -9,19 +8,9 @@ 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.
|
||||
* with variants the studio draws in 3D.
|
||||
*/
|
||||
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();
|
||||
|
||||
public non-sealed interface SceneView extends StudioView {
|
||||
/** The view's entries in the world's pack, in the order the studio lists them. */
|
||||
List<SceneEntry> entries(PackWorld world);
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
/**
|
||||
* A view a module adds to the studio, of one of the kinds the studio draws. 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 sealed interface StudioView permits SceneView, PatternView {
|
||||
/** 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();
|
||||
}
|
||||
@@ -3,9 +3,9 @@ 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.
|
||||
* view with an id already registered, of either kind, 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);
|
||||
/** Adds a view to the studio: block scenes such as the pack's objects, or block patterns such as its palettes. */
|
||||
void registerView(StudioView view);
|
||||
}
|
||||
Reference in new issue
Block a user