|
6 | 6 | pub mod builtin; |
7 | 7 | pub mod debounced_input; |
8 | 8 | pub mod head; |
9 | | -pub mod plugin; |
10 | 9 | pub mod reg; |
11 | 10 | pub mod storage; |
12 | 11 | pub mod vm; |
13 | 12 |
|
| 13 | +use bevy_app::{App, Plugin, Update}; |
14 | 14 | pub use builtin::{BuiltinNodes, Builtins}; |
| 15 | +use gantz_core::Node; |
15 | 16 | pub use head::{ |
16 | 17 | CompiledModule, FocusedHead, HeadRef, HeadTabOrder, HeadVms, OpenHead, OpenHeadData, |
17 | 18 | OpenHeadDataReadOnly, WorkingGraph, |
18 | 19 | }; |
19 | | -pub use plugin::GantzPlugin; |
20 | 20 | pub use reg::{Registry, lookup_node, timestamp}; |
21 | 21 | pub use vm::{EvalCompleted, EvalEvent, EvalKind}; |
22 | 22 |
|
| 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 | + |
23 | 69 | /// Clone a graph. |
24 | 70 | pub fn clone_graph<N: Clone>( |
25 | 71 | graph: &gantz_core::node::graph::Graph<N>, |
|
0 commit comments