Add (currently non-functional) example of using custom data in a filter.

This commit is contained in:
Nolan Darilek 2022-03-12 14:10:29 -06:00
parent 957dcca447
commit efad0132ff

35
examples/builder_data.rs Normal file
View File

@ -0,0 +1,35 @@
use mapgen::{
filter::{
AreaStartingPosition, CellularAutomata, CullUnreachable, NoiseGenerator, XStart, YStart,
},
BuilderData, MapBuilder, MapFilter,
};
#[derive(Clone, Default)]
struct MyData {
value: usize,
}
impl BuilderData for MyData {}
struct IncrementData;
impl<D: BuilderData> MapFilter<D> for IncrementData {
fn modify_map(&self, rng: &mut rand::prelude::StdRng, map: &mapgen::Map<D>) -> mapgen::Map<D> {
let map = map.clone();
map.data.value += 1;
map
}
}
fn main() {
let map = MapBuilder::<MyData>::new(20, 20)
.with(NoiseGenerator::uniform())
.with(CellularAutomata::new())
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
.with(CullUnreachable::new())
.with(Box::new(IncrementData))
.build();
println!("{:}", &map);
}