honeycomb_render/render/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
pub mod camera;
pub mod picking;
pub mod scene;
pub mod update;

use crate::capture::FocusedCapture;
use crate::resources::{
    DartHeadMul, DartRenderColor, DartShrink, DartWidth, EdgeRenderColor, EdgeWidth,
    VertexRenderColor, VertexWidth,
};
use bevy::prelude::*;
use bevy_mod_outline::OutlinePlugin;
use bevy_mod_picking::selection::SelectionPluginSettings;
use bevy_mod_picking::DefaultPickingPlugins;

/// Plugin handling scene setup and updates.
pub struct ScenePlugin;

impl Plugin for ScenePlugin {
    fn build(&self, app: &mut App) {
        // camera
        app.add_systems(Startup, scene::setup_scene).add_systems(
            Update,
            camera::update_camera.run_if(camera::cursor_in_render),
        );

        // picking
        app.add_plugins(DefaultPickingPlugins.build())
            .add_plugins(OutlinePlugin)
            .insert_resource(SelectionPluginSettings::default())
            .add_systems(Update, picking::update_picking);

        // update displayed content

        // FocusedCapture change
        app.add_systems(
            Update,
            (
                update::dart_render,
                update::vertices_render,
                update::edges_render,
            )
                .run_if(
                    resource_changed::<FocusedCapture>
                        .and_then(not(resource_added::<FocusedCapture>)),
                ),
        );

        // dart updates
        app.add_systems(
            Update,
            (update::dart_render, update::dart_mat_handle).run_if(
                resource_changed::<DartRenderColor>
                    .and_then(not(resource_added::<DartRenderColor>)),
            ),
        );
        app.add_systems(
            Update,
            update::dart_heads_handle.run_if(
                resource_changed::<DartWidth>
                    .and_then(not(resource_added::<DartWidth>))
                    .or_else(
                        resource_changed::<DartHeadMul>
                            .and_then(not(resource_added::<DartHeadMul>)),
                    ),
            ),
        );
        app.add_systems(
            Update,
            update::dart_bodies_handles.run_if(
                resource_changed::<DartWidth>
                    .and_then(not(resource_added::<DartWidth>))
                    .or_else(
                        resource_changed::<DartShrink>.and_then(not(resource_added::<DartShrink>)),
                    ),
            ),
        );
        app.add_systems(
            Update,
            (update::dart_heads_transform, update::dart_bodies_transform)
                .run_if(resource_changed::<DartShrink>.and_then(not(resource_added::<DartShrink>))),
        );

        // vertex updates
        app.add_systems(
            Update,
            (update::vertices_render, update::vertices_mat_handle).run_if(
                resource_changed::<VertexRenderColor>
                    .and_then(not(resource_added::<VertexRenderColor>)),
            ),
        );
        app.add_systems(
            Update,
            update::vertices_handle.run_if(
                resource_changed::<VertexWidth>.and_then(not(resource_added::<VertexWidth>)),
            ),
        );
        // edge updates
        app.add_systems(
            Update,
            (update::edges_render, update::edges_mat_handle).run_if(
                resource_changed::<EdgeRenderColor>
                    .and_then(not(resource_added::<EdgeRenderColor>)),
            ),
        );
        app.add_systems(
            Update,
            update::edges_handle
                .run_if(resource_changed::<EdgeWidth>.and_then(not(resource_added::<EdgeWidth>))),
        );
    }
}