refactored to new
This commit is contained in:
parent
dc66f7e11b
commit
3e40de60a5
|
@ -1,7 +1,7 @@
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use web_sys;
|
use web_sys;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use mapgen::{MapBuilder, TileType};
|
use mapgen::{Map, MapBuilder, TileType};
|
||||||
use mapgen::filter::*;
|
use mapgen::filter::*;
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +23,13 @@ pub struct World {
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl World {
|
impl World {
|
||||||
|
|
||||||
|
fn new(width: u32, height: u32, map: &Map) -> World {
|
||||||
|
let tiles = (0..map.tiles.len())
|
||||||
|
.map(|i| if map.tiles[i] == TileType::Floor {Cell::Floor} else {Cell::Wall})
|
||||||
|
.collect();
|
||||||
|
World { width, height, tiles }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_cellular_automata(width: u32, height: u32, seed: u32) -> World {
|
pub fn new_cellular_automata(width: u32, height: u32, seed: u32) -> World {
|
||||||
World::print_map_info(format!("Cellular Automata with the seed: {}", seed));
|
World::print_map_info(format!("Cellular Automata with the seed: {}", seed));
|
||||||
let mut rng = StdRng::seed_from_u64(seed as u64);
|
let mut rng = StdRng::seed_from_u64(seed as u64);
|
||||||
|
@ -33,13 +40,7 @@ impl World {
|
||||||
.with(CullUnreachable::new())
|
.with(CullUnreachable::new())
|
||||||
.with(DistantExit::new())
|
.with(DistantExit::new())
|
||||||
.build_with_rng(&mut rng);
|
.build_with_rng(&mut rng);
|
||||||
let tiles = (0..map.tiles.len())
|
World::new(width, height, &map)
|
||||||
.map(|i| if map.tiles[i] == TileType::Floor {Cell::Floor} else {Cell::Wall})
|
|
||||||
.collect();
|
|
||||||
World {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
tiles }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_simple_rooms(width: u32, height: u32, seed: u32) -> World {
|
pub fn new_simple_rooms(width: u32, height: u32, seed: u32) -> World {
|
||||||
|
@ -49,13 +50,7 @@ impl World {
|
||||||
.with(SimpleRooms::new())
|
.with(SimpleRooms::new())
|
||||||
.with(NearestCorridors::new())
|
.with(NearestCorridors::new())
|
||||||
.build_with_rng(&mut rng);
|
.build_with_rng(&mut rng);
|
||||||
let tiles = (0..map.tiles.len())
|
World::new(width, height, &map)
|
||||||
.map(|i| if map.tiles[i] == TileType::Floor {Cell::Floor} else {Cell::Wall})
|
|
||||||
.collect();
|
|
||||||
World {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
tiles }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_bsp_interior(width: u32, height: u32, seed: u32) -> World {
|
pub fn new_bsp_interior(width: u32, height: u32, seed: u32) -> World {
|
||||||
|
@ -64,13 +59,7 @@ impl World {
|
||||||
let map = MapBuilder::new(80, 50)
|
let map = MapBuilder::new(80, 50)
|
||||||
.with(BspInterior::new())
|
.with(BspInterior::new())
|
||||||
.build_with_rng(&mut rng);
|
.build_with_rng(&mut rng);
|
||||||
let tiles = (0..map.tiles.len())
|
World::new(width, height, &map)
|
||||||
.map(|i| if map.tiles[i] == TileType::Floor {Cell::Floor} else {Cell::Wall})
|
|
||||||
.collect();
|
|
||||||
World {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
tiles }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_drunkard(width: u32, height: u32, seed: u32) -> World {
|
pub fn new_drunkard(width: u32, height: u32, seed: u32) -> World {
|
||||||
|
@ -81,13 +70,7 @@ impl World {
|
||||||
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
|
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
|
||||||
.with(CullUnreachable::new())
|
.with(CullUnreachable::new())
|
||||||
.build_with_rng(&mut rng);
|
.build_with_rng(&mut rng);
|
||||||
let tiles = (0..map.tiles.len())
|
World::new(width, height, &map)
|
||||||
.map(|i| if map.tiles[i] == TileType::Floor {Cell::Floor} else {Cell::Wall})
|
|
||||||
.collect();
|
|
||||||
World {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
tiles }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_random(width: u32, height: u32, seed: u32) -> World {
|
pub fn new_random(width: u32, height: u32, seed: u32) -> World {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user