diff --git a/src/map_builders.rs b/src/map_builders.rs new file mode 100644 index 0000000..4831ac9 --- /dev/null +++ b/src/map_builders.rs @@ -0,0 +1,64 @@ +mod bsp_dungeon; +mod bsp_interior; +mod cellular_automata; +mod common; +mod dla; +mod drunkard; +mod maze; +mod prefab_builder; +mod simple_map; +mod voronoi; +mod waveform_collapse; + +use crate::{Map, Position}; +use bsp_dungeon::BspDungeonBuilder; +use bsp_interior::BspInteriorBuilder; +use cellular_automata::CellularAutomataBuilder; +use common::*; +use dla::DLABuilder; +use drunkard::DrunkardsWalkBuilder; +use maze::MazeBuilder; +use prefab_builder::PrefabBuilder; +use simple_map::SimpleMapBuilder; +use specs::prelude::*; +use voronoi::VoronoiCellBuilder; +use waveform_collapse::WaveformCollapseBuilder; + +pub trait MapBuilder { + fn get_map(&self) -> Map; + fn get_starting_position(&self) -> Position; + fn get_snapshot_history(&self) -> Vec; + fn build_map(&mut self); + fn spawn_entities(&mut self, ecs: &mut World); + fn take_snapshot(&mut self); +} + +pub fn random_builder(new_depth: i32) -> Box { + // let mut rng = rltk::RandomNumberGenerator::new(); + // let mut result: Box = match rng.roll_dice(1, 16) { + // 1 => Box::new(BspDungeonBuilder::new(new_depth)), + // 2 => Box::new(BspInteriorBuilder::new(new_depth)), + // 3 => Box::new(CellularAutomataBuilder::new(new_depth)), + // 4 => Box::new(DrunkardsWalkBuilder::open_area(new_depth)), + // 5 => Box::new(DrunkardsWalkBuilder::open_halls(new_depth)), + // 6 => Box::new(DrunkardsWalkBuilder::winding_passages(new_depth)), + // 7 => Box::new(DrunkardsWalkBuilder::fat_passages(new_depth)), + // 8 => Box::new(DrunkardsWalkBuilder::fearful_symmetry(new_depth)), + // 9 => Box::new(MazeBuilder::new(new_depth)), + // 10 => Box::new(DLABuilder::walk_inwards(new_depth)), + // 11 => Box::new(DLABuilder::walk_outwards(new_depth)), + // 12 => Box::new(DLABuilder::central_attractor(new_depth)), + // 13 => Box::new(DLABuilder::insectoid(new_depth)), + // 14 => Box::new(VoronoiCellBuilder::pythagoras(new_depth)), + // 15 => Box::new(VoronoiCellBuilder::manhattan(new_depth)), + // _ => Box::new(SimpleMapBuilder::new(new_depth)), + // }; + // + // if rng.roll_dice(1, 3) == 1 { + // result = Box::new(WaveformCollapseBuilder::derived_map(new_depth, result)); + // } + // + // result + + Box::new(PrefabBuilder::new(new_depth)) +} diff --git a/src/map_builders/mod.rs b/src/map_builders/mod.rs deleted file mode 100644 index 561f7e1..0000000 --- a/src/map_builders/mod.rs +++ /dev/null @@ -1,62 +0,0 @@ -mod bsp_dungeon; -mod bsp_interior; -mod cellular_automata; -mod common; -mod dla; -mod drunkard; -mod maze; -mod prefab_builder; -mod simple_map; -mod voronoi; -mod waveform_collapse; - -use crate::{Map, Position}; -use bsp_dungeon::BspDungeonBuilder; -use bsp_interior::BspInteriorBuilder; -use cellular_automata::CellularAutomataBuilder; -use common::*; -use dla::DLABuilder; -use drunkard::DrunkardsWalkBuilder; -use maze::MazeBuilder; -use prefab_builder::PrefabBuilder; -use simple_map::SimpleMapBuilder; -use specs::prelude::*; -use voronoi::VoronoiCellBuilder; -use waveform_collapse::WaveformCollapseBuilder; - -pub trait MapBuilder { - fn get_map(&self) -> Map; - fn get_starting_position(&self) -> Position; - fn get_snapshot_history(&self) -> Vec; - fn build_map(&mut self); - fn spawn_entities(&mut self, ecs: &mut World); - fn take_snapshot(&mut self); -} - -pub fn random_builder(new_depth: i32) -> Box { - let mut rng = rltk::RandomNumberGenerator::new(); - let mut result: Box = match rng.roll_dice(1, 16) { - 1 => Box::new(BspDungeonBuilder::new(new_depth)), - 2 => Box::new(BspInteriorBuilder::new(new_depth)), - 3 => Box::new(CellularAutomataBuilder::new(new_depth)), - 4 => Box::new(DrunkardsWalkBuilder::open_area(new_depth)), - 5 => Box::new(DrunkardsWalkBuilder::open_halls(new_depth)), - 6 => Box::new(DrunkardsWalkBuilder::winding_passages(new_depth)), - 7 => Box::new(DrunkardsWalkBuilder::fat_passages(new_depth)), - 8 => Box::new(DrunkardsWalkBuilder::fearful_symmetry(new_depth)), - 9 => Box::new(MazeBuilder::new(new_depth)), - 10 => Box::new(DLABuilder::walk_inwards(new_depth)), - 11 => Box::new(DLABuilder::walk_outwards(new_depth)), - 12 => Box::new(DLABuilder::central_attractor(new_depth)), - 13 => Box::new(DLABuilder::insectoid(new_depth)), - 14 => Box::new(VoronoiCellBuilder::pythagoras(new_depth)), - 15 => Box::new(VoronoiCellBuilder::manhattan(new_depth)), - _ => Box::new(SimpleMapBuilder::new(new_depth)), - }; - - if rng.roll_dice(1, 3) == 1 { - result = Box::new(WaveformCollapseBuilder::derived_map(new_depth, result)); - } - - result -} diff --git a/src/map_builders/prefab_builder/mod.rs b/src/map_builders/prefab_builder.rs similarity index 100% rename from src/map_builders/prefab_builder/mod.rs rename to src/map_builders/prefab_builder.rs diff --git a/src/map_builders/waveform_collapse/mod.rs b/src/map_builders/waveform_collapse.rs similarity index 100% rename from src/map_builders/waveform_collapse/mod.rs rename to src/map_builders/waveform_collapse.rs