Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion assets/locales/en-US/debug-tools.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ show-network-visualizer = Show Network Visualizer
frame-diagnostics = Frame Diagnostics
frames-per-second = Frames Per Second
frame-time = Frame Time
reset-min-max = Reset Min/Max
reset-min-max = Reset Min/Max

snapshot = Snapshot
take-snapshot = Take Snapshot
restore-snapshot = Restore Snapshot
34 changes: 34 additions & 0 deletions src/ui/debug_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ impl Plugin for DebugToolsPlugin {
fn build(&self, app: &mut App) {
app.add_plugin(FrameTimeDiagnosticsPlugin)
// .init_resource::<ShowNetworkVisualizer>()
.init_resource::<BonesSnapshot>()
.init_resource::<CoreDebugSettings>()
.init_resource::<ShowFameTimeDiagnostics>()
.add_system(sync_core_debug_settings)
Expand Down Expand Up @@ -52,6 +53,10 @@ fn sync_core_debug_settings(session: Option<ResMut<Session>>, settings: Res<Core
#[derive(Resource, Default, Deref, DerefMut)]
struct ShowFameTimeDiagnostics(pub bool);

/// Resource containing the bones snapshot.
#[derive(Default, Resource)]
struct BonesSnapshot(Option<bones::World>);

/// System that renders the debug tools window which can be toggled by pressing F12
fn debug_tools_window(
mut core_debug_settings: ResMut<CoreDebugSettings>,
Expand All @@ -61,6 +66,8 @@ fn debug_tools_window(
localization: Res<Localization>,
input: Res<Input<KeyCode>>,
mut show_inspector: ResMut<WorldInspectorEnabled>,
mut bones_world_snapshot: ResMut<BonesSnapshot>,
session: Option<ResMut<Session>>,
) {
let ctx = egui_context.ctx_mut();

Expand Down Expand Up @@ -118,6 +125,33 @@ fn debug_tools_window(
format!("{} ( F9 )", localization.get("show-frame-time-diagnostics")),
);

// Snapshot/Restore buttons
ui.add_space(2.0);
ui.heading(localization.get("snapshot"));
ui.horizontal(|ui| {
ui.scope(|ui| {
ui.set_enabled(session.is_some());

if ui.button(localization.get("take-snapshot")).clicked() {
if let Some(session) = &session {
bones_world_snapshot.0 = Some(session.snapshot());
}
}

ui.scope(|ui| {
ui.set_enabled(bones_world_snapshot.0.is_some());

if ui.button(localization.get("restore-snapshot")).clicked() {
if let Some(mut session) = session {
if let Some(snapshot) = &mut bones_world_snapshot.0 {
session.restore(&mut snapshot.clone())
}
}
}
});
});
});

// Show network visualizer
// ui.checkbox(
// &mut show_network_visualizer,
Expand Down