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 wasm-pack build
cd www cd www
npm run build npm run start
``` ```
This app uses: This app uses:

View File

@ -1,19 +1,16 @@
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use web_sys; use web_sys;
use rand::prelude::*; use rand::prelude::*;
use mapgen::{ use mapgen::{MapBuilder, TileType};
map_builder::{ use mapgen::filter::{
MapBuilder, CellularAutomata,
cellular_automata::CellularAutomataGen, SimpleRooms,
simple_rooms::SimpleRoomsGen, BspInterior,
bsp_interior::BspInteriorGen, {AreaStartingPosition, XStart, YStart},
starting_point::{AreaStartingPosition, XStart, YStart}, CullUnreachable,
cull_unreachable::CullUnreachable, DistantExit,
distant_exit::DistantExit, NearestCorridors,
rooms_corridors_nearest::NearestCorridors, DrunkardsWalk,
drunkard::DrunkardsWalkGen,
},
map::TileType,
}; };
@ -38,7 +35,8 @@ impl World {
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);
let map = MapBuilder::new(CellularAutomataGen::new()) let map = MapBuilder::new()
.with(CellularAutomata::new())
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER)) .with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
.with(CullUnreachable::new()) .with(CullUnreachable::new())
.with(DistantExit::new()) .with(DistantExit::new())
@ -55,7 +53,8 @@ impl World {
pub fn new_simple_rooms(width: u32, height: u32, seed: u32) -> World { pub fn new_simple_rooms(width: u32, height: u32, seed: u32) -> World {
World::print_map_info(format!("Simple Rooms with the seed: {}", seed)); World::print_map_info(format!("Simple Rooms with the seed: {}", seed));
let mut rng = StdRng::seed_from_u64(seed as u64); 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()) .with(NearestCorridors::new())
.build_map_with_rng(width as usize, height as usize, &mut rng); .build_map_with_rng(width as usize, height as usize, &mut rng);
let tiles = (0..map.tiles.len()) let tiles = (0..map.tiles.len())
@ -70,7 +69,8 @@ impl World {
pub fn new_bsp_interior(width: u32, height: u32, seed: u32) -> World { pub fn new_bsp_interior(width: u32, height: u32, seed: u32) -> World {
World::print_map_info(format!("BSP Interior with the seed: {}", seed)); World::print_map_info(format!("BSP Interior with the seed: {}", seed));
let mut rng = StdRng::seed_from_u64(seed as u64); 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); .build_map_with_rng(width as usize, height as usize, &mut rng);
let tiles = (0..map.tiles.len()) let tiles = (0..map.tiles.len())
.map(|i| if map.tiles[i] == TileType::Floor {Cell::Floor} else {Cell::Wall}) .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 { pub fn new_drunkard(width: u32, height: u32, seed: u32) -> World {
World::print_map_info(format!("Drunkard with the seed: {}", seed)); World::print_map_info(format!("Drunkard with the seed: {}", seed));
let mut rng = StdRng::seed_from_u64(seed as u64); 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); .build_map_with_rng(width as usize, height as usize, &mut rng);
let tiles = (0..map.tiles.len()) let tiles = (0..map.tiles.len())
.map(|i| if map.tiles[i] == TileType::Floor {Cell::Floor} else {Cell::Wall}) .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); /******/ promises.push(installedWasmModuleData);
/******/ else { /******/ else {
/******/ var importObject = wasmImportObjects[wasmModuleId](); /******/ 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; /******/ var promise;
/******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') { /******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') {
/******/ promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) { /******/ 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="cellular-automata-option">Cellular Automata</a>
<a class="dropdown-item" id="simple-rooms-option">Simple Rooms</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="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> <a class="dropdown-item" id="random-option">Random Generator</a>
</div> </div>
</li> </li>