refactors entity spawning

This commit is contained in:
Llywelwyn 2023-07-21 10:58:58 +01:00
parent e72d1bd694
commit 8664a8e066
13 changed files with 286 additions and 83 deletions

View file

@ -12,17 +12,13 @@ pub struct MazeBuilder {
depth: i32,
history: Vec<Map>,
noise_areas: HashMap<i32, Vec<usize>>,
spawn_list: Vec<(usize, String)>,
}
impl MapBuilder for MazeBuilder {
fn build_map(&mut self, rng: &mut RandomNumberGenerator) {
return self.build(rng);
}
fn spawn_entities(&mut self, ecs: &mut World) {
for area in self.noise_areas.iter() {
spawner::spawn_region(ecs, area.1, self.depth);
}
}
// Getters
fn get_map(&mut self) -> Map {
return self.map.clone();
@ -30,6 +26,9 @@ impl MapBuilder for MazeBuilder {
fn get_starting_pos(&mut self) -> Position {
return self.starting_position.clone();
}
fn get_spawn_list(&self) -> &Vec<(usize, String)> {
return &self.spawn_list;
}
// Mapgen visualisation stuff
fn get_snapshot_history(&self) -> Vec<Map> {
return self.history.clone();
@ -53,6 +52,7 @@ impl MazeBuilder {
depth: new_depth,
history: Vec::new(),
noise_areas: HashMap::new(),
spawn_list: Vec::new(),
}
}
@ -75,6 +75,11 @@ impl MazeBuilder {
// Now we build a noise map for use in spawning entities later
self.noise_areas = generate_voronoi_spawn_regions(&self.map, rng);
// Spawn the entities
for area in self.noise_areas.iter() {
spawner::spawn_region(&self.map, rng, area.1, self.depth, &mut self.spawn_list);
}
}
}