mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
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:
1 parent
8afbff4b42
commit
a8470c8178
6 files changed
+81
-16
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import type { BridgeClient, WorldRect } from '../bridge/BridgeClient'
|
||||
import { gridIndex } from '../bridge/tileDecoding'
|
||||
import { NO_LABEL, type BlockSource, type MapLabel, type MapTile, type Marker, type PickDisplay, type WorldInfo } from '../bridge/types'
|
||||
import { countShares, type PlacedTile, type Share } from './census'
|
||||
import { countShares, heightBandShares, heightsInArea, type PlacedTile, type Share } from './census'
|
||||
import { blockArt, type BlockArt } from '../scene/blockArt'
|
||||
import { hasBlocksAt, mapTileSource, type TileLayer } from './mapTileSource'
|
||||
import { drawPlayerArrow } from './playerArrow'
|
||||
@@ -40,6 +40,8 @@ export interface MapListener {
|
||||
|
||||
/** The views whose spots a noise picks, so they can draw that noise. */
|
||||
const PICK_NOISE_VIEWS = new Set(['biomes', 'regions'])
|
||||
/** The view that colours each spot by its terrain height instead of by what picked it. */
|
||||
const HEIGHT_VIEW = 'height'
|
||||
|
||||
/** What the map shows at a spot, read from the tiles already drawn. */
|
||||
export interface SpotSubjects {
|
||||
@@ -235,6 +237,7 @@ export class MapController {
|
||||
private style(): TileStyle {
|
||||
return {
|
||||
byBlock: this.toggles.blocks,
|
||||
byHeight: this.layer.view === HEIGHT_VIEW,
|
||||
shading: this.toggles.shading,
|
||||
regionBorders: this.toggles.regionBorders,
|
||||
highlight: this.highlight,
|
||||
@@ -373,6 +376,9 @@ export class MapController {
|
||||
}
|
||||
const screen = this.screenArea()
|
||||
const area = { minimumX: screen.minX, minimumZ: screen.minZ, maximumX: screen.maxX, maximumZ: screen.maxZ }
|
||||
if (this.layer.view === HEIGHT_VIEW) {
|
||||
return heightBandShares(heightsInArea(placed, area), this.world.fluidHeight)
|
||||
}
|
||||
return countShares(placed, area)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,29 @@ export function countShares(tiles: PlacedTile[], area: WorldArea): Share[] {
|
||||
.sort((first, second) => second.fraction - first.fraction)
|
||||
}
|
||||
|
||||
/** The terrain heights of the pixels of {@code tiles} inside {@code area}, sampled to a bounded count. */
|
||||
export function heightsInArea(tiles: PlacedTile[], area: WorldArea): number[] {
|
||||
const heights: number[] = []
|
||||
const totalPixels = tiles.reduce((sum, placed) => sum + placed.tile.size * placed.tile.size, 0)
|
||||
const stride = Math.max(1, Math.ceil(Math.sqrt(totalPixels / MAXIMUM_COUNTED_PIXELS)))
|
||||
for (const { tile, worldX, worldZ } of tiles) {
|
||||
if (tile.heights === null) {
|
||||
continue
|
||||
}
|
||||
const scale = tile.blocksPerPixel
|
||||
const firstX = Math.max(0, Math.ceil((area.minimumX - worldX) / scale))
|
||||
const endX = Math.min(tile.size, Math.ceil((area.maximumX - worldX) / scale))
|
||||
const firstZ = Math.max(0, Math.ceil((area.minimumZ - worldZ) / scale))
|
||||
const endZ = Math.min(tile.size, Math.ceil((area.maximumZ - worldZ) / scale))
|
||||
for (let pixelZ = firstZ; pixelZ < endZ; pixelZ += stride) {
|
||||
for (let pixelX = firstX; pixelX < endX; pixelX += stride) {
|
||||
heights.push(tile.heights[gridIndex(tile, pixelX, pixelZ)])
|
||||
}
|
||||
}
|
||||
}
|
||||
return heights
|
||||
}
|
||||
|
||||
/** The shares of the height bands the {@code heights} fall in, highest band first. */
|
||||
export function heightBandShares(heights: readonly number[], seaLevel: number): Share[] {
|
||||
const counts = new Map<number, number>()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { gridIndex } from '../bridge/tileDecoding'
|
||||
import { NO_BLOCK, NO_LABEL, type MapTile, type PickDisplay, type TileBlocks } from '../bridge/types'
|
||||
import { WATER_SURFACE_COLOR } from '../scene/waterTint'
|
||||
import { blend } from './heightColors'
|
||||
import { blend, heightColor } from './heightColors'
|
||||
|
||||
const WATER_OVER_GROUND = 0.65
|
||||
|
||||
@@ -15,6 +15,8 @@ export interface Highlight {
|
||||
export interface TileStyle {
|
||||
/** Colour by the block on top of each column instead of by label, where the tile carries its blocks. */
|
||||
byBlock: boolean
|
||||
/** Colour by the terrain height of each column, from the tile's heights, instead of by label. */
|
||||
byHeight?: boolean
|
||||
shading: boolean
|
||||
regionBorders: boolean
|
||||
highlight: Highlight | null
|
||||
@@ -25,7 +27,7 @@ export interface TileStyle {
|
||||
|
||||
export function styleKey(style: TileStyle): string {
|
||||
const highlight = style.highlight === null ? '' : `${style.highlight.kind}:${style.highlight.key}`
|
||||
return `${style.byBlock}|${style.shading}|${style.regionBorders}|${highlight}|${style.seaLevel}|${style.pickDisplay}`
|
||||
return `${style.byBlock}|${style.byHeight === true}|${style.shading}|${style.regionBorders}|${highlight}|${style.seaLevel}|${style.pickDisplay}`
|
||||
}
|
||||
|
||||
const UNKNOWN_SUBJECT = 0x5a5c62
|
||||
@@ -64,10 +66,14 @@ export function stylePixels(tile: MapTile, style: TileStyle): Uint8ClampedArray<
|
||||
// The bare noise is read by its brightness, which relief shading would mix up.
|
||||
const shading = style.shading && heights !== null && !(pickNoise !== null && style.pickDisplay === 'noise')
|
||||
const highlighted = highlightCells(tile, style)
|
||||
const heightColored = style.byHeight === true && blocks === null && heights !== null
|
||||
for (let pixelZ = 0; pixelZ < size; pixelZ++) {
|
||||
for (let pixelX = 0; pixelX < size; pixelX++) {
|
||||
const cell = gridIndex(tile, pixelX, pixelZ)
|
||||
let color = blocks === null ? labelColor(colors, tile.subjects[cell]) : blockColor(blocks, cell, heights, style.seaLevel)
|
||||
if (heightColored) {
|
||||
color = heightColor(heights[cell], style.seaLevel)
|
||||
}
|
||||
if (pickNoise !== null) {
|
||||
color = byNoise(color, pickNoise[cell], style.pickDisplay)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,13 @@ const VIEW_ICONS: Record<string, IdeIconName> = {
|
||||
biomes: 'views/biomes',
|
||||
regions: 'views/regions',
|
||||
rivers: 'views/rivers',
|
||||
height: 'shading',
|
||||
'land-biomes': 'views/biomes',
|
||||
'sea-biomes': 'views/biomes',
|
||||
'cave-biomes': 'views/biomes',
|
||||
'object-load': 'views/objects',
|
||||
'decorator-load': 'decoration',
|
||||
'layer-load': 'groups',
|
||||
caveProfiles: 'views/cave-profiles',
|
||||
treeProfiles: 'views/tree-profiles',
|
||||
formationProfiles: 'views/formation-profiles',
|
||||
|
||||
Reference in new issue
Block a user