Skip to content

Commit

Permalink
add a feature for graph debug lines
Browse files Browse the repository at this point in the history
  • Loading branch information
JackCrumpLeys committed Aug 1, 2023
1 parent f950316 commit c667fab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ opt-level = 3

[features]
godmode = ["de_spawner/godmode"]
graph_debug_lines = ["de_energy/graph_debug_lines"]

[dependencies]
# DE
Expand Down Expand Up @@ -112,7 +113,6 @@ async-compat = "0.2.1"
async-std = "1.11"
async-tar = "0.4.2"
bevy = { version = "0.11", features = ["mp3"] }
bevy_prototype_debug_lines = { version="0.11", features = ["3d"] }
bincode = "2.0.0-rc.3"
chrono = "0.4.24"
clap = { version = "4.0", features = ["derive"] }
Expand Down
7 changes: 6 additions & 1 deletion crates/energy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ categories.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
graph_debug_lines = ["dep:bevy_prototype_debug_lines"]

[dependencies]
# DE
de_core.workspace = true
Expand All @@ -21,6 +24,8 @@ de_spawner.workspace = true

# Other
bevy.workspace = true
bevy_prototype_debug_lines.workspace = true
parry3d.workspace = true
tinyvec.workspace = true

# This cannot be a workspace dependency because it is optional
bevy_prototype_debug_lines = { version="0.11", features = ["3d"], optional = true }
14 changes: 11 additions & 3 deletions crates/energy/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashSet;

use bevy::prelude::*;
use bevy::utils::petgraph::prelude::*;
use bevy::utils::petgraph::visit::IntoNodeReferences;
use bevy::utils::Instant;
#[cfg(feature = "graph_debug_lines")]
use bevy_prototype_debug_lines::{DebugLines, DebugLinesPlugin};
use de_core::gamestate::GameState;
use de_core::objects::Active;
Expand All @@ -22,7 +22,6 @@ pub(crate) struct GraphPlugin;
impl Plugin for GraphPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((
DebugLinesPlugin::default(),
DespawnEventsPlugin::<&NearbyUnits, NearbyUnits>::default(),
))
.add_systems(OnEnter(GameState::Playing), setup)
Expand All @@ -36,10 +35,18 @@ impl Plugin for GraphPlugin {
update_graph
.in_set(GraphSystemSet::UpdateGraph)
.after(GraphSystemSet::UpdateNearby),
debug_lines.after(GraphSystemSet::UpdateGraph),

)
.run_if(in_state(GameState::Playing)),
);

#[cfg(feature = "graph_debug_lines")]
app.add_plugins(DebugLinesPlugin::default())
.add_systems(
PostUpdate,
(debug_lines)
.run_if(in_state(GameState::Playing)),
);
}
}

Expand Down Expand Up @@ -235,6 +242,7 @@ fn remove_old_nodes(
}
}

#[cfg(feature = "graph_debug_lines")]
fn debug_lines(
power_grid: Res<PowerGrid>,
query: Query<&Transform>,
Expand Down

0 comments on commit c667fab

Please sign in to comment.