world_map_gen/
lib.rs

1//! Several kinds of random World maps generator for games
2//!
3//! This library provides a world maps generator with following interfaces:
4//!
5//! 1. Rust library as an API
6//! 2. CLI tool to generate maps in terminal as visual output or as JSON output
7//! 3. WebAssembly npm package for Web
8//!
9//! Please read README.md of repository hosted on GitHub.
10//!
11//! https://github.com/rhysd/world-map-gen
12//!
13//! This document explains 1., as an API library for Rust.
14//!
15//! This library provides some modules to handle a world map as one board filled up with cells.
16//!
17//! - `land`: `land::Land` struct represents each cell in a board
18//! - `board`: `board::Board` struct represents one world map. The struct is JSON serializable with `serde_json`
19//! - `draw`: Helper to draw a board to terminal or as JSON
20//! - `gen`: A random world map generator to build `board::Board` struct. It provides algorithms for 3 kinds of resolutions
21//! - `error`: Error type which may be returned from a map generator
22//!
23//! ```rust
24//! use world_map_gen::RandomBoardGen;
25//!
26//! // Create generator instance with default random number generator
27//! let mut generator = RandomBoardGen::default();
28//!
29//! // Generate 40x40 random world map. Map resolution (low, middle, high) is automatically
30//! // determined by its width and height here.
31//! //   - Low: width and height are less than 15
32//! //   - Middle: width and height are less than 120
33//! //   - High: Otherwise
34//! let board = generator.gen_auto(40, 40);
35//!
36//! // Iterate each cells per row
37//! for (i, row) in board.rows().enumerate() {
38//!     println!("Row: {}", i);
39//!     for cell in row {
40//!         // cell is a world_map_gen::land::Land instance
41//!
42//!         // Lands are categorized with kind (e.g. Sea, Plain, Forest, Mountain, ...)
43//!         println!("Kind: {:?}", cell.kind);
44//!
45//!         // Each cell as its altitude. For example, sea's altitude is lower and mountain's is
46//!         // higher
47//!         println!("Altitude: {}", cell.altitude);
48//!     }
49//! }
50//! ```
51
52#![deny(missing_docs)]
53
54#[macro_use]
55extern crate lazy_static;
56#[macro_use]
57extern crate serde_derive;
58
59
60pub mod board;
61pub mod draw;
62pub mod error;
63pub mod gen;
64pub mod land;
65#[cfg(target_arch = "wasm32")]
66pub mod wasm;
67
68mod color;
69mod large_gen;
70mod middle_gen;
71mod slope;
72
73pub use crate::board::Board;
74pub use crate::error::Result;
75pub use crate::gen::RandomBoardGen;
76pub use crate::land::LandKind;
77
78use cfg_if::cfg_if;
79
80cfg_if! {
81    // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
82    // allocator.
83    if #[cfg(feature = "wee_alloc")] {
84        extern crate wee_alloc;
85        #[global_allocator]
86        static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
87    }
88}