1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
use crate::{
config::TILESET_SCALING,
content::materials::MaterialId,
proc_gen::{
Biome,
tileset_loader::{Tile, TileOrientation, TilesetPixelType},
},
sim::cell::Cell,
};
pub struct MinesBiome;
impl Biome for MinesBiome {
fn derive_world_from_tile(&self, tile: &Tile) -> Vec<Cell> {
let tp = TILESET_SCALING.pow(2) as u32;
let mut cells =
vec![Cell::void(); (tile.dimensions.short * tile.dimensions.long * tp) as usize];
let ey = match tile.orientation {
TileOrientation::Horizontal => tile.dimensions.short,
TileOrientation::Vertical => tile.dimensions.long,
};
let ex = match tile.orientation {
TileOrientation::Horizontal => tile.dimensions.long,
TileOrientation::Vertical => tile.dimensions.short,
};
for y in 0..ey {
for x in 0..ex {
let idx = (x + y * ex) * tp;
for i in 0..tp {
cells[(idx + i) as usize] = match tile.pixels[(x + y * ex) as usize] {
TilesetPixelType::Void => Cell::void(),
TilesetPixelType::Terrain => Cell::from_material(MaterialId::Dirt),
}
}
}
}
cells
}
}
|