From efad0132ff011649d8c97c7d3d7c57a2d646214c Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Sat, 12 Mar 2022 14:10:29 -0600 Subject: [PATCH] Add (currently non-functional) example of using custom data in a filter. --- examples/builder_data.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 examples/builder_data.rs 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); +}