Add height, biome layer and load map views to the studio

- Serve the seven Swing tile views from the bridge
- Colour the height view in the app from tile heights
This commit is contained in:
piexel committed 2026-11-15 11:17:34 +01:00
1 parent 8afbff4b42
commit a8470c8178
6 files changed
+81 -16

No files matched your search

@@ -90,11 +90,26 @@ public final class StudioBridge implements AutoCloseable {
static final int STATUS_SERVER_ERROR = 500;
static final int STATUS_UNAVAILABLE = 503;
private static final String VIEW_HEIGHT = "height";
private static final String GROUP_WORLD = "WORLD";
private static final String GROUP_BIOME_LAYERS = "BIOME_LAYERS";
private static final String GROUP_DIAGNOSTICS = "DIAGNOSTICS";
private static final List<ViewInfo> VIEWS = List.of(
new ViewInfo(VIEW_BIOMES, "Biomes", "The biome at each spot, in the biome's colour", "WORLD", "World"),
new ViewInfo(VIEW_REGIONS, "Regions", "The region each spot belongs to", "WORLD", "World"),
new ViewInfo(VIEW_BIOMES, "Biomes", "The biome at each spot, in the biome's colour", GROUP_WORLD, "World"),
new ViewInfo(VIEW_REGIONS, "Regions", "The region each spot belongs to", GROUP_WORLD, "World"),
new ViewInfo(VIEW_HEIGHT, "Height", "Terrain height, from deep water to snowy peaks", GROUP_WORLD, "World"),
new ViewInfo(VIEW_RIVERS, "Rivers", "Streams, rivers, falls, ponds, lakes, sea inlets, grottos and cave pools from the hydrology",
"WORLD", "World"));
GROUP_WORLD, "World"),
new ViewInfo("land-biomes", "Land biomes", "The land biome each spot would get, also where the sea is", GROUP_BIOME_LAYERS, "Biome layers"),
new ViewInfo("sea-biomes", "Sea biomes", "The sea biome each spot would get, also where the land is", GROUP_BIOME_LAYERS, "Biome layers"),
new ViewInfo("cave-biomes", "Cave biomes", "The cave biome under each spot", GROUP_BIOME_LAYERS, "Biome layers"),
new ViewInfo("object-load", "Object load", "Configuration estimate of object density and chance, not measured performance",
GROUP_DIAGNOSTICS, "Diagnostics"),
new ViewInfo("decorator-load", "Decorator load", "Configuration estimate of decorator chance and stacks, not measured performance",
GROUP_DIAGNOSTICS, "Diagnostics"),
new ViewInfo("layer-load", "Layer load", "Configuration estimate of biome layer count, not measured performance",
GROUP_DIAGNOSTICS, "Diagnostics"));
private final StudioWorld world;
private final String token;
@@ -74,13 +74,14 @@ final class StudioTiles {
StudioTile biomesOrRegions(String view, String previewRegion, double startX, double startZ, double blocksPerPixel, int size,
boolean withHeights, BooleanSupplier cancelled) {
MapLayer layer = layerOf(view, previewRegion);
MapTileRenderer.TileRender render = renderer.prepareTile(startX, startZ, blocksPerPixel, size, layer, withHeights);
boolean heightsWanted = withHeights || layer.type() == TileType.HEIGHT;
MapTileRenderer.TileRender render = renderer.prepareTile(startX, startZ, blocksPerPixel, size, layer, heightsWanted);
MapTile tile = render.render(cancelled);
for (int attempt = 0; !render.complete() && attempt < MAX_FINISH_ATTEMPTS; attempt++) {
pause(cancelled);
tile = render.render(cancelled);
}
return wire(tile, blocksPerPixel, withHeights && tile.hasHeights());
return wire(tile, blocksPerPixel, heightsWanted && tile.hasHeights(), layer.type());
}
StudioTile rivers(double startX, double startZ, double blocksPerPixel, int size, BooleanSupplier cancelled) {
@@ -102,13 +103,20 @@ final class StudioTiles {
}
private static MapLayer layerOf(String view, String previewRegion) {
if ("regions".equals(view)) {
return previewRegion == null ? MapLayer.regions(PickDisplay.PICKS) : MapLayer.regionPreview(previewRegion, PickDisplay.PICKS);
}
return MapLayer.biomes(PickDisplay.PICKS, false);
return switch (view) {
case "regions" -> previewRegion == null ? MapLayer.regions(PickDisplay.PICKS) : MapLayer.regionPreview(previewRegion, PickDisplay.PICKS);
case "height" -> MapLayer.of(TileType.HEIGHT);
case "land-biomes" -> MapLayer.of(TileType.BIOME_LAND);
case "sea-biomes" -> MapLayer.of(TileType.BIOME_SEA);
case "cave-biomes" -> MapLayer.of(TileType.CAVE_LAND);
case "object-load" -> MapLayer.of(TileType.OBJECT_LOAD);
case "decorator-load" -> MapLayer.of(TileType.DECORATOR_LOAD);
case "layer-load" -> MapLayer.of(TileType.LAYER_LOAD);
default -> MapLayer.biomes(PickDisplay.PICKS, false);
};
}
private StudioTile wire(MapTile tile, double blocksPerPixel, boolean withHeights) {
private StudioTile wire(MapTile tile, double blocksPerPixel, boolean withHeights, TileType legendType) {
int size = tile.size();
int grid = size + 2;
Labelling labelling = new Labelling();
@@ -125,7 +133,7 @@ final class StudioTiles {
}
}
}
List<StudioTile.Label> labels = labelling.labels(renderer);
List<StudioTile.Label> labels = labelling.labels(renderer, legendType);
return new StudioTile(size, blocksPerPixel, tile.subjectKind().name(), labels, subjects, regions, heights);
}
@@ -156,12 +164,12 @@ final class StudioTiles {
});
}
List<StudioTile.Label> labels(MapTileRenderer renderer) {
List<StudioTile.Label> labels(MapTileRenderer renderer, TileType legendType) {
List<StudioTile.Label> labels = new ArrayList<>();
for (short id : usedLabelIds) {
MapLabels.Label label = renderer.labels().label(id);
labels.add(new StudioTile.Label(label.kind().name(), label.key(), label.name(),
renderer.legendColor(label, TileType.BIOME) & RGB));
renderer.legendColor(label, legendType) & RGB));
}
return labels;
}