chore: Remove demo.
This commit is contained in:
parent
b76f7326d5
commit
b910c4ed89
BIN
demo/.DS_Store
vendored
BIN
demo/.DS_Store
vendored
Binary file not shown.
|
@ -1,28 +0,0 @@
|
|||
[package]
|
||||
name = "mapgen-demo"
|
||||
version = "0.1.2"
|
||||
authors = ["Krzysztof Langner <klangner@gmail.com>"]
|
||||
description = "Map generator demo"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/klangner/mapgen.rs"
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
mapgen = {path=".."}
|
||||
getrandom = { version = "0.2", features = ["js"] }
|
||||
rand = "0.8"
|
||||
wasm-bindgen = "0.2"
|
||||
js-sys = "0.3"
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "0.3.4"
|
||||
features = [
|
||||
'Document',
|
||||
'Element',
|
||||
'HtmlElement',
|
||||
'Node',
|
||||
'Window',
|
||||
]
|
|
@ -1,201 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2017 Krzysztof Langner
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -1,18 +0,0 @@
|
|||
# Demo application for mapgen
|
||||
|
||||
## Build the project:
|
||||
|
||||
```
|
||||
wasm-pack build
|
||||
cd www
|
||||
npm run server
|
||||
```
|
||||
|
||||
Deply application
|
||||
```
|
||||
cd www
|
||||
npm run build
|
||||
```
|
||||
|
||||
This app uses:
|
||||
* [Urizen OneBit Tilesets](https://vurmux.itch.io/urizen-onebit-tilesets)
|
Binary file not shown.
Before Width: | Height: | Size: 6.3 KiB |
|
@ -1,8 +0,0 @@
|
|||
#![enable(implicit_some)]
|
||||
|
||||
Grid((
|
||||
texture_width: 320,
|
||||
texture_height: 320,
|
||||
columns: 16,
|
||||
rows: 16,
|
||||
))
|
Binary file not shown.
Before Width: | Height: | Size: 44 KiB |
|
@ -1,8 +0,0 @@
|
|||
#![enable(implicit_some)]
|
||||
|
||||
Grid((
|
||||
texture_width: 261,
|
||||
texture_height: 261,
|
||||
columns: 20,
|
||||
rows: 20,
|
||||
))
|
203
demo/src/lib.rs
203
demo/src/lib.rs
|
@ -1,203 +0,0 @@
|
|||
use wasm_bindgen::prelude::*;
|
||||
use web_sys;
|
||||
use rand::prelude::*;
|
||||
use mapgen::{Map, MapBuilder, NoData, geometry::Point};
|
||||
use mapgen::filter::*;
|
||||
use mapgen::metric;
|
||||
|
||||
|
||||
#[wasm_bindgen]
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Cell {
|
||||
Floor = 0,
|
||||
Wall = 1,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct World {
|
||||
width: u32,
|
||||
height: u32,
|
||||
tiles: Vec<Cell>,
|
||||
map: Map<NoData>,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct Position {
|
||||
col: usize,
|
||||
row: usize,
|
||||
}
|
||||
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl World {
|
||||
|
||||
fn new(width: u32, height: u32, map: Map<NoData>) -> World {
|
||||
let tiles = (0..map.tiles.len())
|
||||
.map(|i| if map.tiles[i].is_walkable() {Cell::Floor} else {Cell::Wall})
|
||||
.collect();
|
||||
World { width, height, tiles, map }
|
||||
}
|
||||
|
||||
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(width as usize, height as usize)
|
||||
.with(NoiseGenerator::uniform())
|
||||
.with(CellularAutomata::new())
|
||||
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
|
||||
.with(CullUnreachable::new())
|
||||
.with(DistantExit::new())
|
||||
.build_with_rng(&mut rng);
|
||||
World::print_map_metrics(&map);
|
||||
World::new(width, height, map)
|
||||
}
|
||||
|
||||
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(width as usize, height as usize)
|
||||
.with(SimpleRooms::new())
|
||||
.with(NearestCorridors::new())
|
||||
.with(AreaStartingPosition::new(XStart::LEFT, YStart::TOP))
|
||||
.with(DistantExit::new())
|
||||
.build_with_rng(&mut rng);
|
||||
World::print_map_metrics(&map);
|
||||
World::new(width, height, map)
|
||||
}
|
||||
|
||||
pub fn new_bsp_rooms(width: u32, height: u32, seed: u32) -> World {
|
||||
World::print_map_info(format!("BSP Rooms with the seed: {}", seed));
|
||||
let mut rng = StdRng::seed_from_u64(seed as u64);
|
||||
let map = MapBuilder::new(width as usize, height as usize)
|
||||
.with(BspRooms::new())
|
||||
.with(NearestCorridors::new())
|
||||
.with(AreaStartingPosition::new(XStart::LEFT, YStart::BOTTOM))
|
||||
.with(DistantExit::new())
|
||||
.build_with_rng(&mut rng);
|
||||
World::print_map_metrics(&map);
|
||||
World::new(width, height, map)
|
||||
}
|
||||
|
||||
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(width as usize, height as usize)
|
||||
.with(BspInterior::new())
|
||||
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
|
||||
.with(CullUnreachable::new())
|
||||
.with(DistantExit::new())
|
||||
.build_with_rng(&mut rng);
|
||||
World::print_map_metrics(&map);
|
||||
World::new(width, height, map)
|
||||
}
|
||||
|
||||
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(width as usize, height as usize)
|
||||
.with(DrunkardsWalk::open_halls())
|
||||
.with(AreaStartingPosition::new(XStart::RIGHT, YStart::BOTTOM))
|
||||
.with(CullUnreachable::new())
|
||||
.with(DistantExit::new())
|
||||
.build_with_rng(&mut rng);
|
||||
World::print_map_metrics(&map);
|
||||
World::new(width, height, map)
|
||||
}
|
||||
|
||||
pub fn new_maze(width: u32, height: u32, seed: u32) -> World {
|
||||
World::print_map_info(format!("Maze with the seed: {}", seed));
|
||||
let mut rng = StdRng::seed_from_u64(seed as u64);
|
||||
let map = MapBuilder::new(width as usize, height as usize)
|
||||
.with(MazeBuilder::new())
|
||||
.with(AreaStartingPosition::new(XStart::LEFT, YStart::TOP))
|
||||
.with(DistantExit::new())
|
||||
.build_with_rng(&mut rng);
|
||||
World::print_map_metrics(&map);
|
||||
World::new(width, height, map)
|
||||
}
|
||||
|
||||
pub fn new_voronoi(width: u32, height: u32, seed: u32) -> World {
|
||||
World::print_map_info(format!("Voronoi Hive with the seed: {}", seed));
|
||||
let mut rng = StdRng::seed_from_u64(seed as u64);
|
||||
let map = MapBuilder::new(width as usize, height as usize)
|
||||
.with(VoronoiHive::new())
|
||||
.with(AreaStartingPosition::new(XStart::LEFT, YStart::TOP))
|
||||
.with(DistantExit::new())
|
||||
.build_with_rng(&mut rng);
|
||||
World::print_map_metrics(&map);
|
||||
World::new(width, height, map)
|
||||
}
|
||||
|
||||
pub fn new_random(width: u32, height: u32, seed: u32) -> World {
|
||||
let mut rng = rand::thread_rng();
|
||||
let px = rng.gen::<f32>();
|
||||
if px < 1.0/6.0 {
|
||||
World::new_cellular_automata(width, height, seed)
|
||||
} else if px < 2.0/6.0 {
|
||||
World::new_simple_rooms(width, height, seed)
|
||||
} else if px < 3.0/6.0 {
|
||||
World::new_drunkard(width, height, seed)
|
||||
} else if px < 4.0/6.0 {
|
||||
World::new_bsp_rooms(width, height, seed)
|
||||
} else if px < 5.0/6.0 {
|
||||
World::new_bsp_rooms(width, height, seed)
|
||||
} else {
|
||||
World::new_maze(width, height, seed)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn width(&self) -> u32 {
|
||||
self.width
|
||||
}
|
||||
|
||||
pub fn height(&self) -> u32 {
|
||||
self.height
|
||||
}
|
||||
|
||||
pub fn tiles(&self) -> *const Cell {
|
||||
self.tiles.as_ptr()
|
||||
}
|
||||
|
||||
pub fn player_pos(&self) -> Position {
|
||||
let p = self.map.starting_point.unwrap_or(Point::new(0, 0));
|
||||
Position { col: p.x, row: p.y }
|
||||
}
|
||||
|
||||
pub fn exit_pos(&self) -> Position {
|
||||
let p = self.map.exit_point.unwrap_or(Point::new(0, 0));
|
||||
Position { col: p.x, row: p.y }
|
||||
}
|
||||
|
||||
fn print_map_info(info: String) {
|
||||
let window = web_sys::window().expect("no global `window` exists");
|
||||
let document = window.document().expect("should have a document on window");
|
||||
let div = document.get_element_by_id("map-info").expect("Need div with id: map-info");
|
||||
div.set_inner_html(&info);
|
||||
}
|
||||
|
||||
fn print_map_metrics(map: &Map<NoData>) {
|
||||
let window = web_sys::window().expect("no global `window` exists");
|
||||
let document = window.document().expect("should have a document on window");
|
||||
let div = document.get_element_by_id("map-metrics").expect("Need div with id: map-metrics");
|
||||
let density = metric::density(map);
|
||||
let path_length = metric::path_length(map);
|
||||
let info = format!("Metrics: density: {}, path length: {}", density, path_length);
|
||||
div.set_inner_html(&info);
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Position {
|
||||
pub fn new(col: usize, row: usize) -> Position {
|
||||
Position { col, row }
|
||||
}
|
||||
|
||||
pub fn col(&self) -> usize {
|
||||
self.col
|
||||
}
|
||||
|
||||
pub fn row(&self) -> usize {
|
||||
self.row
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
pub fn set_panic_hook() {
|
||||
// When the `console_error_panic_hook` feature is enabled, we can call the
|
||||
// `set_panic_hook` function at least once during initialization, and then
|
||||
// we will get better error messages if our code ever panics.
|
||||
//
|
||||
// For more details see
|
||||
// https://github.com/rustwasm/console_error_panic_hook#readme
|
||||
#[cfg(feature = "console_error_panic_hook")]
|
||||
console_error_panic_hook::set_once();
|
||||
}
|
||||
|
BIN
demo/www/.DS_Store
vendored
BIN
demo/www/.DS_Store
vendored
Binary file not shown.
4
demo/www/.gitignore
vendored
4
demo/www/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
node_modules
|
||||
dist
|
||||
.bin/
|
||||
package-lock.json
|
Binary file not shown.
Before Width: | Height: | Size: 31 KiB |
Binary file not shown.
Before Width: | Height: | Size: 44 KiB |
5
demo/www/bootstrap.js
vendored
5
demo/www/bootstrap.js
vendored
|
@ -1,5 +0,0 @@
|
|||
// A dependency graph that contains any wasm must all be imported
|
||||
// asynchronously. This `bootstrap.js` file does the single async import, so
|
||||
// that no one else needs to worry about it again.
|
||||
import("./index.js")
|
||||
.catch(e => console.error("Error importing `index.js`:", e));
|
|
@ -1,71 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="icon" type="image/png" href="assets/favicon.ico" />
|
||||
<title>Mapgen demo</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
|
||||
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
|
||||
<style>
|
||||
body {
|
||||
background-color: lightgrey;
|
||||
}
|
||||
canvas {
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
<script src="./bootstrap.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<a class="navbar-brand" href="#">Mapgen demo</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
|
||||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="mx-auto" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav">
|
||||
<span class="navbar-text mr-2">Generator</span>
|
||||
<li class="nav-item dropdown">
|
||||
<button class="btn btn-secondary dropdown-toggle mr-2" type="button" id="generatorDropdown"
|
||||
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Random
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="generatorDropdown">
|
||||
<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-rooms-option">BSP 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="maze-option">Maze</a>
|
||||
<a class="dropdown-item" id="voronoi-option">Voronoi Hive</a>
|
||||
<a class="dropdown-item" id="random-option">Random</a>
|
||||
</div>
|
||||
</li>
|
||||
<span class="navbar-text mr-2">Seed</span>
|
||||
<input class="form-control mr-sm-2 w-25" id="seed" type="search" placeholder="random" aria-label="Seed">
|
||||
<button class="btn btn-outline-success my-2 my-sm-0" type="submit" id="refresh">Refresh</button>
|
||||
</ul>
|
||||
</div>
|
||||
<a class="github-button" href="https://github.com/klangner/mapgen.rs" data-icon="octicon-star"
|
||||
aria-label="Star ntkme/github-buttons on GitHub">Star</a>
|
||||
</nav>
|
||||
|
||||
<canvas id="mapgen-canvas"></canvas>
|
||||
<div id="map-info" style="text-align: center"></div>
|
||||
<div id="map-metrics" style="text-align: center"></div>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
|
||||
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
|
||||
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
|
||||
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
|
||||
<script async defer src="https://buttons.github.io/buttons.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,173 +0,0 @@
|
|||
import {Cell, World} from "mapgen-demo";
|
||||
import { memory } from "mapgen-demo/mapgen_demo_bg";
|
||||
|
||||
const CANVAS_SIZE = 750;
|
||||
const GRID_COLS = 80;
|
||||
const GRID_ROWS = 50;
|
||||
const CELL_SIZE = CANVAS_SIZE/GRID_ROWS;
|
||||
const TILE_SIZE = 39;
|
||||
|
||||
// Init canvas
|
||||
const canvas = document.getElementById("mapgen-canvas");
|
||||
canvas.height = CELL_SIZE * GRID_ROWS;
|
||||
canvas.width = CELL_SIZE * GRID_COLS;
|
||||
const ctx = canvas.getContext('2d');
|
||||
// Info box
|
||||
const infoDiv = document.getElementById('map-info');
|
||||
// API to the WASM
|
||||
let world = null;
|
||||
|
||||
// Load tiles bitmap
|
||||
let tiles_image = new Image();
|
||||
tiles_image.src = 'assets/tiles.png';
|
||||
|
||||
// Take provided seed or generate new one
|
||||
function get_seed() {
|
||||
var seed_text = document.getElementById("seed").value;
|
||||
if( seed_text.length > 0) {
|
||||
return Number(seed_text);
|
||||
}
|
||||
return Date.now();
|
||||
}
|
||||
|
||||
|
||||
function setGenerator(e) {
|
||||
document.getElementById("generatorDropdown").innerHTML = e.target.innerText;
|
||||
}
|
||||
|
||||
// Map generators
|
||||
function refreshMap() {
|
||||
var generator_name = document.getElementById("generatorDropdown").innerHTML;
|
||||
|
||||
switch(generator_name){
|
||||
case "Cellular Automata":
|
||||
world = World.new_cellular_automata(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "Simple Rooms":
|
||||
world = World.new_simple_rooms(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "BSP Rooms":
|
||||
world = World.new_bsp_rooms(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "BSP Interior":
|
||||
world = World.new_bsp_interior(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "Drunkard Walk":
|
||||
world = World.new_drunkard(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "Maze":
|
||||
world = World.new_maze(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "Voronoi Hive":
|
||||
world = World.new_voronoi(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
default:
|
||||
world = World.new_random(GRID_COLS, GRID_ROWS, get_seed());
|
||||
}
|
||||
|
||||
requestAnimationFrame(renderLoop);
|
||||
}
|
||||
|
||||
// Main loop
|
||||
function renderLoop() {
|
||||
// universe.tick();
|
||||
drawCells();
|
||||
requestAnimationFrame(renderLoop);
|
||||
};
|
||||
|
||||
const getIndex = (row, column) => {
|
||||
return row * GRID_COLS + column;
|
||||
};
|
||||
|
||||
const is_inner_wall = (tiles, col, row) => {
|
||||
for (let c = Math.max(col - 1, 0); c < Math.min(col + 2, GRID_COLS); c++) {
|
||||
for (let r = Math.max(row - 1, 0); r < Math.min(row + 2, GRID_ROWS); r++) {
|
||||
if ((c != col || r != row) && tiles[getIndex(r, c)] == Cell.Floor) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const draw_tile = (ctx, row, col, tile_type) => {
|
||||
var tile_x = 0;
|
||||
var tile_y = 0;
|
||||
if (tile_type == "floor") {
|
||||
tile_x = 3;
|
||||
tile_y = 2;
|
||||
} else if (tile_type == "wall") {
|
||||
tile_x = 0;
|
||||
tile_y = 3;
|
||||
} else if (tile_type == "player") {
|
||||
tile_x = 0;
|
||||
tile_y = 8;
|
||||
} else if (tile_type == "exit") {
|
||||
tile_x = 10;
|
||||
tile_y = 1;
|
||||
} else {
|
||||
tile_x = 18;
|
||||
tile_y = 0;
|
||||
}
|
||||
|
||||
ctx.drawImage(
|
||||
tiles_image,
|
||||
tile_x * TILE_SIZE + 3,
|
||||
tile_y * TILE_SIZE + 3,
|
||||
TILE_SIZE - 3,
|
||||
TILE_SIZE - 3,
|
||||
col * CELL_SIZE,
|
||||
row * CELL_SIZE,
|
||||
CELL_SIZE,
|
||||
CELL_SIZE);
|
||||
|
||||
}
|
||||
|
||||
const drawCells = () => {
|
||||
const tilesPtr = world.tiles();
|
||||
const tiles = new Uint8Array(memory.buffer, tilesPtr, GRID_COLS * GRID_ROWS);
|
||||
|
||||
// tiles
|
||||
for (let row = 0; row < GRID_ROWS; row++) {
|
||||
for (let col = 0; col < GRID_COLS; col++) {
|
||||
const idx = getIndex(row, col);
|
||||
if (tiles[idx] == Cell.Floor) {
|
||||
draw_tile(ctx, row, col, "floor");
|
||||
} else if (is_inner_wall(tiles, col, row)){
|
||||
draw_tile(ctx, row, col, "inner-wall");
|
||||
} else {
|
||||
draw_tile(ctx, row, col, "wall");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Player position
|
||||
let player = world.player_pos();
|
||||
draw_tile(ctx, player.row(), player.col(), "player");
|
||||
|
||||
// Exit position
|
||||
let exit = world.exit_pos();
|
||||
draw_tile(ctx, exit.row(), exit.col(), "exit");
|
||||
};
|
||||
|
||||
// Connect UI element
|
||||
document.getElementById('cellular-automata-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('simple-rooms-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('bsp-rooms-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('drunkard-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('bsp-interior-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('maze-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('voronoi-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('random-option').addEventListener('click', setGenerator);
|
||||
|
||||
document.getElementById('refresh').addEventListener('click', refreshMap);
|
||||
|
||||
refreshMap();
|
|
@ -1,41 +0,0 @@
|
|||
{
|
||||
"name": "create-wasm-app",
|
||||
"version": "0.1.0",
|
||||
"description": "create an app to consume rust-generated wasm packages",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"create-wasm-app": ".bin/create-wasm-app.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "webpack --config webpack.config.js",
|
||||
"server": "webpack-dev-server",
|
||||
"deploy": "gh-pages -d dist"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/rustwasm/create-wasm-app.git"
|
||||
},
|
||||
"keywords": [
|
||||
"webassembly",
|
||||
"wasm",
|
||||
"rust",
|
||||
"webpack"
|
||||
],
|
||||
"author": "Ashley Williams <ashley666ashley@gmail.com>",
|
||||
"license": "(MIT OR Apache-2.0)",
|
||||
"bugs": {
|
||||
"url": "https://github.com/rustwasm/create-wasm-app/issues"
|
||||
},
|
||||
"homepage": "https://github.com/rustwasm/create-wasm-app#readme",
|
||||
"dependencies": {
|
||||
"gh-pages": "^3.1.0",
|
||||
"mapgen-demo": "file:../pkg"
|
||||
},
|
||||
"devDependencies": {
|
||||
"hello-wasm-pack": "^0.1.0",
|
||||
"webpack": "^4.29.3",
|
||||
"webpack-cli": "^3.1.0",
|
||||
"webpack-dev-server": "^3.1.5",
|
||||
"copy-webpack-plugin": "^5.0.0"
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
entry: "./bootstrap.js",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "../../docs"),
|
||||
filename: "bootstrap.js",
|
||||
},
|
||||
mode: "development",
|
||||
plugins: [
|
||||
new CopyWebpackPlugin(['index.html', { from: 'assets', to: 'assets' }])
|
||||
],
|
||||
};
|
Loading…
Reference in New Issue
Block a user