///|
/// HeightGrid — 高さ付き2Dグリッド(クォータービュー用)
pub(all) struct HeightGrid {
width : Int32
height : Int32
cells : Array[Tile]
heights : Array[Int32]
max_height : Int32
}
///|
pub fn HeightGrid::make(
width : Int32,
height : Int32,
fill : Tile,
max_height : Int32,
) -> HeightGrid {
let size = width * height
{
width,
height,
cells: Array::make(size, fill),
heights: Array::make(size, 0),
max_height,
}
}
///|
pub fn HeightGrid::in_bounds(self : HeightGrid, x : Int32, y : Int32) -> Bool {
x >= 0 && x < self.width && y >= 0 && y < self.height
}
///|
pub fn HeightGrid::get(self : HeightGrid, x : Int32, y : Int32) -> Tile {
self.cells[y * self.width + x]
}
///|
pub fn HeightGrid::set(
self : HeightGrid,
x : Int32,
y : Int32,
tile : Tile,
) -> Unit {
self.cells[y * self.width + x] = tile
}
///|
pub fn HeightGrid::get_height(self : HeightGrid, x : Int32, y : Int32) -> Int32 {
self.heights[y * self.width + x]
}
///|
pub fn HeightGrid::set_height(
self : HeightGrid,
x : Int32,
y : Int32,
h : Int32,
) -> Unit {
self.heights[y * self.width + x] = h
}
///|
pub fn HeightGrid::to_ascii(self : HeightGrid) -> String {
let buf = StringBuilder::StringBuilder()
for y in 0.. Grid2D {
let grid = Grid2D::make(self.width, self.height, Wall)
for y in 0..