add option to turn devtools off (#17)
Reviewed-on: #17 Co-authored-by: luckyturtledev <git@lukas1818.de> Co-committed-by: luckyturtledev <git@lukas1818.de>
This commit is contained in:
parent
2416ffd7dc
commit
fe6651d573
2 changed files with 35 additions and 10 deletions
|
@ -19,9 +19,11 @@ pub fn draw(state: &crate::State, _engine: &comfy::EngineContext<'_>) {
|
|||
ZLayer::MapMax - i,
|
||||
Vec2::ONE
|
||||
);
|
||||
if state.dev {
|
||||
draw_rect_outline(coords.as_vec2(), Vec2::ONE, 0.1, RED, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
draw_circle(state.ghost.overworld_pos, 0.5, RED, ZLayer::Ghost.into());
|
||||
}
|
||||
|
||||
|
|
37
src/main.rs
37
src/main.rs
|
@ -10,17 +10,31 @@ mod activities;
|
|||
mod game;
|
||||
mod ui;
|
||||
|
||||
use std::env::var;
|
||||
|
||||
use self::{
|
||||
activities::{house::HouseState, overworld::worldgen::Overworld, Activity},
|
||||
game::Ghost
|
||||
};
|
||||
use comfy::{
|
||||
etagere::euclid::default, init_game_config, pollster, run_comfy_main_async,
|
||||
DevConfig, EngineContext, EngineState, GameConfig, GameLoop, HashMap, IVec2
|
||||
init_game_config, pollster, run_comfy_main_async, DevConfig, EngineContext,
|
||||
EngineState, GameConfig, GameLoop, HashMap, IVec2
|
||||
};
|
||||
|
||||
const GAME_NAME: &str = "Powercreep";
|
||||
|
||||
/// true if devtools should be enable
|
||||
fn dev_from_env() -> bool {
|
||||
match var("DEV").as_ref().map(|f| f.as_str()) {
|
||||
Ok("false") => false,
|
||||
Ok("true") => true,
|
||||
#[cfg(debug_assertions)]
|
||||
_ => true,
|
||||
#[cfg(not(debug_assertions))]
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct State {
|
||||
setup_called: bool,
|
||||
|
@ -28,7 +42,9 @@ struct State {
|
|||
ghost: Ghost,
|
||||
overworld: Overworld,
|
||||
houses: HashMap<IVec2, HouseState>,
|
||||
score: f32
|
||||
score: f32,
|
||||
/// show dev tools
|
||||
dev: bool
|
||||
}
|
||||
|
||||
impl State {
|
||||
|
@ -52,7 +68,10 @@ impl State {
|
|||
|
||||
impl GameLoop for State {
|
||||
fn new(_c: &mut EngineState) -> Self {
|
||||
Self::default()
|
||||
Self {
|
||||
dev: dev_from_env(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &mut EngineContext<'_>) {
|
||||
|
@ -67,15 +86,19 @@ impl GameLoop for State {
|
|||
}
|
||||
|
||||
fn config(config: GameConfig) -> GameConfig {
|
||||
let dev = DevConfig {
|
||||
#[cfg(debug_assertions)]
|
||||
let dev = if dev_from_env() {
|
||||
DevConfig {
|
||||
show_fps: true,
|
||||
..Default::default()
|
||||
}
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
GameConfig {
|
||||
tonemapping_enabled: true,
|
||||
dev,
|
||||
..Default::default()
|
||||
target_framerate: 165,
|
||||
..config
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue