updated demo

This commit is contained in:
klangner 2020-09-22 20:54:19 +02:00
parent ce1229830f
commit 416cd633eb
6 changed files with 24 additions and 22 deletions

View File

@ -5,7 +5,7 @@
```
wasm-pack build
cd www
npm run build
npm run start
```
This app uses:

View File

@ -1,19 +1,16 @@
use wasm_bindgen::prelude::*;
use web_sys;
use rand::prelude::*;
use mapgen::{
map_builder::{
MapBuilder,
cellular_automata::CellularAutomataGen,
simple_rooms::SimpleRoomsGen,
bsp_interior::BspInteriorGen,
starting_point::{AreaStartingPosition, XStart, YStart},
cull_unreachable::CullUnreachable,
distant_exit::DistantExit,
rooms_corridors_nearest::NearestCorridors,
drunkard::DrunkardsWalkGen,
},
map::TileType,
use mapgen::{MapBuilder, TileType};
use mapgen::filter::{
CellularAutomata,
SimpleRooms,
BspInterior,
{AreaStartingPosition, XStart, YStart},
CullUnreachable,
DistantExit,
NearestCorridors,
DrunkardsWalk,
};
@ -38,7 +35,8 @@ impl World {
pub fn new_cellular_automata(width: u32, height: u32, seed: u32) -> World {
World::print_map_info(format!("Cellular Automata with the seed: {}", seed));
let mut rng = StdRng::seed_from_u64(seed as u64);
let map = MapBuilder::new(CellularAutomataGen::new())
let map = MapBuilder::new()
.with(CellularAutomata::new())
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
.with(CullUnreachable::new())
.with(DistantExit::new())
@ -55,7 +53,8 @@ impl World {
pub fn new_simple_rooms(width: u32, height: u32, seed: u32) -> World {
World::print_map_info(format!("Simple Rooms with the seed: {}", seed));
let mut rng = StdRng::seed_from_u64(seed as u64);
let map = MapBuilder::new(SimpleRoomsGen::new())
let map = MapBuilder::new()
.with(SimpleRooms::new())
.with(NearestCorridors::new())
.build_map_with_rng(width as usize, height as usize, &mut rng);
let tiles = (0..map.tiles.len())
@ -70,7 +69,8 @@ impl World {
pub fn new_bsp_interior(width: u32, height: u32, seed: u32) -> World {
World::print_map_info(format!("BSP Interior with the seed: {}", seed));
let mut rng = StdRng::seed_from_u64(seed as u64);
let map = MapBuilder::new(BspInteriorGen::new())
let map = MapBuilder::new()
.with(BspInterior::new())
.build_map_with_rng(width as usize, height as usize, &mut rng);
let tiles = (0..map.tiles.len())
.map(|i| if map.tiles[i] == TileType::Floor {Cell::Floor} else {Cell::Wall})
@ -84,7 +84,8 @@ impl World {
pub fn new_drunkard(width: u32, height: u32, seed: u32) -> World {
World::print_map_info(format!("Drunkard with the seed: {}", seed));
let mut rng = StdRng::seed_from_u64(seed as u64);
let map = MapBuilder::new(DrunkardsWalkGen::open_halls())
let map = MapBuilder::new()
.with(DrunkardsWalk::open_halls())
.build_map_with_rng(width as usize, height as usize, &mut rng);
let tiles = (0..map.tiles.len())
.map(|i| if map.tiles[i] == TileType::Floor {Cell::Floor} else {Cell::Wall})

File diff suppressed because one or more lines are too long

Binary file not shown.

2
docs/bootstrap.js vendored
View File

@ -222,7 +222,7 @@
/******/ promises.push(installedWasmModuleData);
/******/ else {
/******/ var importObject = wasmImportObjects[wasmModuleId]();
/******/ var req = fetch(__webpack_require__.p + "" + {"../pkg/mapgen_demo_bg.wasm":"cbb67d3121ca19dbc9af"}[wasmModuleId] + ".module.wasm");
/******/ var req = fetch(__webpack_require__.p + "" + {"../pkg/mapgen_demo_bg.wasm":"5a858ffd967a1d3be2df"}[wasmModuleId] + ".module.wasm");
/******/ var promise;
/******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') {
/******/ promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {

View File

@ -38,6 +38,7 @@
<a class="dropdown-item" id="cellular-automata-option">Cellular Automata</a>
<a class="dropdown-item" id="simple-rooms-option">Simple Rooms</a>
<a class="dropdown-item" id="bsp-interior-option">BSP Interior</a>
<a class="dropdown-item" id="drunkard-option">Drunkard Walk</a>
<a class="dropdown-item" id="random-option">Random Generator</a>
</div>
</li>