mirror of
https://github.com/zyllian/classics.git
synced 2025-05-10 04:56:40 -07:00
make generation presets use string ids
This commit is contained in:
parent
21217a3597
commit
55bbb3a59c
4 changed files with 100 additions and 11 deletions
|
@ -1,7 +1,8 @@
|
|||
use internment::Intern;
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::Level;
|
||||
use super::{block::BLOCK_STRING_ID_MAP, Level};
|
||||
|
||||
/// enum for different kinds of level generation
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
@ -29,7 +30,7 @@ pub enum FlatPreset {
|
|||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct FlatLayer {
|
||||
/// the block for the layer
|
||||
pub block: u8,
|
||||
pub block: String,
|
||||
/// the depth of the layer
|
||||
pub depth: usize,
|
||||
}
|
||||
|
@ -60,11 +61,17 @@ impl LevelGeneration {
|
|||
FlatPreset::StoneAndGrass => {
|
||||
custom_layers = vec![
|
||||
FlatLayer {
|
||||
block: 1,
|
||||
block: "stone".to_owned(),
|
||||
depth: level.y_size / 2 - 4,
|
||||
},
|
||||
FlatLayer { block: 3, depth: 3 },
|
||||
FlatLayer { block: 2, depth: 1 },
|
||||
FlatLayer {
|
||||
block: "dirt".to_owned(),
|
||||
depth: 3,
|
||||
},
|
||||
FlatLayer {
|
||||
block: "grass".to_owned(),
|
||||
depth: 1,
|
||||
},
|
||||
];
|
||||
layers_ref = &custom_layers;
|
||||
}
|
||||
|
@ -75,10 +82,18 @@ impl LevelGeneration {
|
|||
|
||||
let mut y = 0;
|
||||
for layer in layers_ref {
|
||||
let block = Intern::new(layer.block.to_string());
|
||||
for _ in 0..layer.depth {
|
||||
for x in 0..level.x_size {
|
||||
for z in 0..level.z_size {
|
||||
level.set_block(x, y, z, layer.block);
|
||||
level.set_block(
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
*BLOCK_STRING_ID_MAP
|
||||
.get(&block)
|
||||
.expect("missing block type!"),
|
||||
);
|
||||
}
|
||||
}
|
||||
y += 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue