diff --git a/examples/builder_data.rs b/examples/builder_data.rs new file mode 100644 index 0000000..2d71c06 --- /dev/null +++ b/examples/builder_data.rs @@ -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 MapFilter for IncrementData { + fn modify_map(&self, rng: &mut rand::prelude::StdRng, map: &mapgen::Map) -> mapgen::Map { + let map = map.clone(); + map.data.value += 1; + map + } +} + +fn main() { + let map = MapBuilder::::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); +}