Skip to content

Commit 33617df

Browse files
Merge pull request #171 from mitchmindtree/refactor
refactor: Rm plugin module, hide graph nav at root, make "Graph Config" work per-head
2 parents 43d6eda + 07d9400 commit 33617df

File tree

6 files changed

+262
-141
lines changed

6 files changed

+262
-141
lines changed

crates/bevy_gantz/src/lib.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,66 @@
66
pub mod builtin;
77
pub mod debounced_input;
88
pub mod head;
9-
pub mod plugin;
109
pub mod reg;
1110
pub mod storage;
1211
pub mod vm;
1312

13+
use bevy_app::{App, Plugin, Update};
1414
pub use builtin::{BuiltinNodes, Builtins};
15+
use gantz_core::Node;
1516
pub use head::{
1617
CompiledModule, FocusedHead, HeadRef, HeadTabOrder, HeadVms, OpenHead, OpenHeadData,
1718
OpenHeadDataReadOnly, WorkingGraph,
1819
};
19-
pub use plugin::GantzPlugin;
2020
pub use reg::{Registry, lookup_node, timestamp};
2121
pub use vm::{EvalCompleted, EvalEvent, EvalKind};
2222

23+
/// Plugin providing core gantz functionality.
24+
///
25+
/// Generic over `N`, the node type used in graphs.
26+
///
27+
/// This plugin:
28+
/// - Initializes core resources (Registry, HeadVms, etc.)
29+
/// - Registers event observers for head operations
30+
/// - Registers the eval event observer
31+
/// - Handles VM initialization for opened/replaced heads
32+
/// - Detects graph changes and recompiles VMs
33+
///
34+
/// Apps should also:
35+
/// - Insert a `BuiltinNodes<N>` resource with their builtin nodes
36+
/// - Add `GantzEguiPlugin` for egui integration (Views, GraphViews, etc.)
37+
pub struct GantzPlugin<N>(std::marker::PhantomData<N>);
38+
39+
impl<N> Default for GantzPlugin<N> {
40+
fn default() -> Self {
41+
Self(std::marker::PhantomData)
42+
}
43+
}
44+
45+
impl<N> Plugin for GantzPlugin<N>
46+
where
47+
N: 'static + Node + Clone + gantz_ca::CaHash + Send + Sync,
48+
{
49+
fn build(&self, app: &mut App) {
50+
app.init_resource::<FocusedHead>()
51+
.init_resource::<HeadTabOrder>()
52+
.init_resource::<Registry<N>>()
53+
.init_non_send_resource::<HeadVms>()
54+
// Register head event handlers.
55+
.add_observer(head::on_open::<N>)
56+
.add_observer(head::on_replace::<N>)
57+
.add_observer(head::on_close::<N>)
58+
.add_observer(head::on_branch::<N>)
59+
// Register eval event handler.
60+
.add_observer(vm::on_eval)
61+
// VM init observers.
62+
.add_observer(vm::on_head_opened::<N>)
63+
.add_observer(vm::on_head_replaced::<N>)
64+
// Graph recompilation system.
65+
.add_systems(Update, vm::update::<N>);
66+
}
67+
}
68+
2369
/// Clone a graph.
2470
pub fn clone_graph<N: Clone>(
2571
graph: &gantz_core::node::graph::Graph<N>,

crates/bevy_gantz/src/plugin.rs

Lines changed: 0 additions & 56 deletions
This file was deleted.

crates/gantz_egui/src/widget.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
33
pub use command_palette::CommandPalette;
44
pub use gantz::{Gantz, GantzState, update_graph_pane_head};
5+
pub use graph_config::{GraphConfig, GraphConfigResponse};
56
pub use graph_scene::{GraphScene, GraphSceneState};
67
pub use graph_select::GraphSelect;
78
pub use graph_tab::{GraphTab, GraphTabResponse};
9+
pub use head_name_edit::{HeadNameEditResponse, head_name, head_name_edit};
810
pub use head_row::{HeadRowResponse, HeadRowType, fmt_commit_timestamp, head_row};
911
pub use history_view::{HistoryMode, HistoryView, HistoryViewState};
1012
pub use label_button::LabelButton;
@@ -16,9 +18,11 @@ pub use perf_view::{PerfCapture, PerfView};
1618

1719
pub mod command_palette;
1820
pub mod gantz;
21+
pub mod graph_config;
1922
pub mod graph_scene;
2023
pub mod graph_select;
2124
pub mod graph_tab;
25+
pub mod head_name_edit;
2226
pub mod head_row;
2327
pub mod history_view;
2428
pub mod label_button;

0 commit comments

Comments
 (0)