Move developer-type code options to 'debug' feature

This commit is contained in:
Timothy Warren 2022-02-04 09:52:09 -05:00
parent c6cf07c8fd
commit 351b149b27
10 changed files with 46 additions and 16 deletions

View File

@ -7,12 +7,15 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
debug = []
default = ["rltk/opengl", "rltk/serde", "rltk/threaded"]
curses = ["rltk/curses", "rltk/serde"]
js = ["getrandom/js", "rltk/opengl", "rltk/serde"]
# WebAssembly Build
wasm = ["getrandom/js", "rltk/opengl", "rltk/serde"]
[dependencies]
getrandom = { version = "0.2.4" }
getrandom = { version = "0.2.4", optional = true }
lazy_static = "1.4.0"
regex = "1.5.4"
rltk = { version = "0.8.1", default-features = false }

View File

@ -1,10 +1,15 @@
include help-system.mk
FEATURES?=default
run: $(call print-help, run, Runs the binary in develop mode)
cargo run
cargo run --features $(FEATURES) --no-default-features
run-debug: $(call print-help, run-debug, Runs the binary with the 'debug' feature, which shows map generation, and other debug functionality)
cargo run --features debug
run-pi: $(call print-help, run-pi, Sets appropriate flags so that the game runs on a Raspberry Pi)
MESA_GL_VERSION_OVERRIDE=3.0 MESA_GLSL_VERSION_OVERRIDE=330 cargo run
MESA_GL_VERSION_OVERRIDE=3.0 MESA_GLSL_VERSION_OVERRIDE=330 cargo run --features $(FEATURES)
run-curses: $(call print-help, run-curses, Run the game in a console window via the curses library)
cargo run --features curses --no-default-features
@ -13,11 +18,11 @@ build:
cargo build
build-wasm: $(call print-help, build-wasm, Build the webassembly version of the game)
cargo build --release --target wasm32-unknown-unknown --features js
cargo build --release --target wasm32-unknown-unknown --features wasm
wasm-bindgen target/wasm32-unknown-unknown/release/roguelike_tutorial.wasm --out-dir wasm --no-modules --no-typescript
build-wasm-dev: $(call print-help, build-wasm-dev, Build the webassembly version of the game (dev version))
cargo build --target wasm32-unknown-unknown --features js
cargo build --target wasm32-unknown-unknown --features wasm
wasm-bindgen target/wasm32-unknown-unknown/debug/roguelike_tutorial.wasm --out-dir wasm --no-modules --no-typescript
clean: $(call print-help, clean, Removes save file and compilation artifacts)
@ -25,13 +30,13 @@ clean: $(call print-help, clean, Removes save file and compilation artifacts)
cargo clean
check: $(call print-help, check, Check code syntax)
cargo check
cargo check --features $(FEATURES)
check-wasm: $(call print-help, check-wasm, Check code syntax for webassembly build)
cargo check --target wasm32-unknown-unknown --features js
cargo check --target wasm32-unknown-unknown --features wasm
lint: $(call print-help, lint, Check code syntax and style)
cargo clippy
cargo clippy --features $(FEATURES)
fmt: $(call print-help, fmt, Runs formatter on code)
cargo +nightly fmt
@ -41,6 +46,6 @@ fix: $(call print-help, fix, Fixes some warnings, then runs the formatter)
make fmt
docs: $(call print-help, docs, Generates code docs)
cargo doc
cargo doc --features $(FEATURES)
.phony: run-pi clean check run fmt fix lint docs build build-wasm check-wasm build-wasm-dev

View File

@ -7,6 +7,11 @@ use crate::map::tile_glyph;
use crate::{colors, Map};
/// Whether to render an outline of the current map's boundaries
#[cfg(feature = "debug")]
const SHOW_BOUNDARIES: bool = true;
/// Whether to render an outline of the current map's boundaries
#[cfg(not(feature = "debug"))]
const SHOW_BOUNDARIES: bool = false;
/// Get the rectangle representing the current viewport

View File

@ -35,7 +35,6 @@ mod voronoi;
mod voronoi_spawning;
mod waveform_collapse;
use ::rltk::prelude::*;
use ::specs::prelude::*;
use area_ending_point::{AreaEndingPosition, XEnd, YEnd};
use area_starting_points::{AreaStartingPosition, XStart, YStart};
@ -345,7 +344,9 @@ pub fn random_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
}
pub fn level_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
console::log(format!("Depth: {}", new_depth));
#[cfg(feature = "debug")]
::rltk::console::log(format!("Depth: {}", new_depth));
match new_depth {
1 => town_builder(new_depth, width, height),
2 => forest_builder(new_depth, width, height),

View File

@ -136,7 +136,8 @@ impl PrefabBuilder {
build_data.spawn_list.push((idx, "Watch Fire".to_string()));
}
_ => {
rltk::console::log(format!("Unknown glyph loading map: {}", (ch as u8) as char));
#[cfg(feature = "debug")]
::rltk::console::log(format!("Unknown glyph loading map: {}", (ch as u8) as char));
}
}
}

View File

@ -66,7 +66,8 @@ pub fn build_patterns(
// Dedupe
if dedupe {
rltk::console::log(format!(
#[cfg(feature = "debug")]
::rltk::console::log(format!(
"Pre de-duplication, there are {} patterns",
patterns.len()
));
@ -75,7 +76,8 @@ pub fn build_patterns(
let set: HashSet<Vec<TileType>> = patterns.drain(..).collect();
patterns.extend(set.into_iter());
rltk::console::log(format!("There are {} patterns", patterns.len()));
#[cfg(feature = "debug")]
::rltk::console::log(format!("There are {} patterns", patterns.len()));
}
patterns

View File

@ -194,7 +194,9 @@ impl Solver {
}
if possible_options.is_empty() {
rltk::console::log("Oh no! It's not possible!");
#[cfg(feature = "debug")]
::rltk::console::log("Oh no! It's not possible!");
self.possible = false;
return true;

View File

@ -196,6 +196,7 @@ impl RawMaster {
for (i, item) in self.raws.items.iter().enumerate() {
if used_names.contains(&item.name) {
#[cfg(feature = "debug")]
console::log(format!(
"WARNING - duplicate item name in raws [{}]",
item.name
@ -208,6 +209,7 @@ impl RawMaster {
}
for (i, mob) in self.raws.mobs.iter().enumerate() {
if used_names.contains(&mob.name) {
#[cfg(feature = "debug")]
console::log(format!(
"WARNING - duplicate mob name in raws [{}]",
mob.name
@ -218,6 +220,7 @@ impl RawMaster {
}
for (i, prop) in self.raws.props.iter().enumerate() {
if used_names.contains(&prop.name) {
#[cfg(feature = "debug")]
console::log(format!(
"WARNING - duplicate prop name in raws [{}]",
prop.name
@ -229,6 +232,7 @@ impl RawMaster {
for spawn in self.raws.spawn_table.iter() {
if !used_names.contains(&spawn.name) {
#[cfg(feature = "debug")]
console::log(format!(
"WARNING - Spawn tables references unspecified entity [{}]",
spawn.name
@ -392,6 +396,7 @@ pub fn string_to_slot(slot: &str) -> EquipmentSlot {
"Hands" => EquipmentSlot::Hands,
"Melee" => EquipmentSlot::Melee,
_ => {
#[cfg(feature = "debug")]
console::log(format!("Warning: unknown equipment slot type [{}]", slot));
EquipmentSlot::Melee
@ -738,6 +743,7 @@ pub fn spawn_named_mob(
skills.skills.insert(Skill::Magic, *sk.1);
}
_ => {
#[cfg(feature = "debug")]
console::log(format!("Unknown skill referenced [{}]", sk.0));
}
}

View File

@ -163,6 +163,7 @@ pub fn spawn_entity(ecs: &mut World, spawn: &(&usize, &String)) {
);
if item_result.is_none() {
#[cfg(feature = "debug")]
console::log(format!("WARNING: We don't know how to spawn [{}]!", name));
}
}

View File

@ -11,8 +11,12 @@ use crate::systems::{self, particle_system};
use crate::{camera, colors, damage_system, gamelog, player, saveload_system, spawner};
/// Whether to show a visual representation of map generation
#[cfg(not(feature = "debug"))]
pub const SHOW_MAPGEN_VISUALIZER: bool = false;
#[cfg(feature = "debug")]
pub const SHOW_MAPGEN_VISUALIZER: bool = true;
/// Whether to show an FPS counter
pub const SHOW_FPS: bool = true;