refactors mapgen into chained builders
This commit is contained in:
parent
8a5600267c
commit
dd367dc39b
22 changed files with 1381 additions and 1480 deletions
26
src/map_builders/room_based_starting_position.rs
Normal file
26
src/map_builders/room_based_starting_position.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use super::{BuilderMap, MetaMapBuilder, Position};
|
||||
use rltk::RandomNumberGenerator;
|
||||
|
||||
pub struct RoomBasedStartingPosition {}
|
||||
|
||||
impl MetaMapBuilder for RoomBasedStartingPosition {
|
||||
fn build_map(&mut self, rng: &mut rltk::RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||
self.build(rng, build_data);
|
||||
}
|
||||
}
|
||||
|
||||
impl RoomBasedStartingPosition {
|
||||
#[allow(dead_code)]
|
||||
pub fn new() -> Box<RoomBasedStartingPosition> {
|
||||
Box::new(RoomBasedStartingPosition {})
|
||||
}
|
||||
|
||||
fn build(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||
if let Some(rooms) = &build_data.rooms {
|
||||
let start_pos = rooms[0].centre();
|
||||
build_data.starting_position = Some(Position { x: start_pos.0, y: start_pos.1 });
|
||||
} else {
|
||||
panic!("RoomBasedStartingPosition only works after rooms have been created");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue