|
1 | 1 | use bevy::prelude::*;
|
2 | 2 | use dolly::prelude::*;
|
3 | 3 |
|
4 |
| -mod commands; |
5 |
| -pub use commands::OgleCommandExt; |
| 4 | +mod systems; |
6 | 5 |
|
7 | 6 | mod plugin;
|
8 | 7 | pub use plugin::OglePlugin;
|
9 | 8 |
|
10 |
| -#[derive(Resource, Debug, PartialEq)] |
| 9 | +/// System set to allow ordering of `OglePlugin` |
| 10 | +#[derive(Debug, Clone, Copy, SystemSet, PartialEq, Eq, Hash)] |
| 11 | +pub struct OgleSystemSet; |
| 12 | + |
| 13 | +#[derive(Component, Debug)] |
| 14 | +pub struct OgleCam { |
| 15 | + pub settings: OgleSettings, |
| 16 | + pub target: OgleTarget, |
| 17 | + pub mode: OgleMode, |
| 18 | + rig: CameraRig, |
| 19 | +} |
| 20 | + |
| 21 | +impl OgleCam { |
| 22 | + pub fn new(settings: OgleSettings) -> Self { |
| 23 | + Self { |
| 24 | + settings, |
| 25 | + target: Default::default(), |
| 26 | + mode: Default::default(), |
| 27 | + rig: CameraRig::builder() |
| 28 | + .with(Position::new(mint::Point3 { |
| 29 | + x: 0.0, |
| 30 | + y: 0.0, |
| 31 | + z: 1.0, |
| 32 | + })) |
| 33 | + .with(Smooth::new_position(1.5).predictive(false)) |
| 34 | + .build(), |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +#[derive(Clone, PartialEq, Debug, Default)] |
11 | 40 | pub enum OgleTarget {
|
12 | 41 | Position(Vec2),
|
13 | 42 | Entity(Entity),
|
14 | 43 | EntityWithOffset((Entity, Vec2)),
|
| 44 | + #[default] |
15 | 45 | None,
|
16 | 46 | }
|
17 | 47 |
|
18 |
| -impl Default for OgleTarget { |
19 |
| - fn default() -> Self { |
20 |
| - Self::None |
21 |
| - } |
22 |
| -} |
23 |
| - |
24 |
| -#[derive(States, Clone, PartialEq, Eq, Hash, Debug, Default)] |
| 48 | +#[derive(Clone, PartialEq, Eq, Hash, Debug, Default)] |
25 | 49 | pub enum OgleMode {
|
26 | 50 | /// The camera will not move under normal circumstances.
|
27 | 51 | #[default]
|
28 | 52 | Frozen,
|
| 53 | + /// The user can only zoom the camera. |
| 54 | + ZoomOnly, |
29 | 55 | /// The camera should exponentially follow its target.
|
30 | 56 | Following,
|
31 | 57 | /// The camera is in a detached pancam mode.
|
32 | 58 | Pancam,
|
33 | 59 | }
|
34 | 60 |
|
35 |
| -#[derive(Resource, Deref, DerefMut)] |
36 |
| -pub struct OgleRig(CameraRig); |
37 |
| - |
38 |
| -impl Default for OgleRig { |
39 |
| - fn default() -> Self { |
40 |
| - let pos = mint::Point3 { |
41 |
| - x: 0.0, |
42 |
| - y: 0.0, |
43 |
| - z: 1.0, |
44 |
| - }; |
45 |
| - Self( |
46 |
| - CameraRig::builder() |
47 |
| - .with(Position::new(pos)) |
48 |
| - .with(Smooth::new_position(1.5).predictive(false)) |
49 |
| - .build(), |
50 |
| - ) |
51 |
| - } |
52 |
| -} |
53 |
| - |
54 |
| -#[derive(Resource, Debug, Clone, Copy, PartialEq)] |
| 61 | +#[derive(Debug, Clone, Copy, PartialEq)] |
55 | 62 | pub struct OgleSettings {
|
56 | 63 | /// The minimum scale for the camera
|
57 |
| - /// |
58 |
| - /// The orthographic projection's scale will be clamped at this value when zooming in |
59 | 64 | pub min_scale: f32,
|
60 | 65 | /// The maximum scale for the camera
|
61 |
| - /// |
62 |
| - /// If present, the orthographic projection's scale will be clamped at |
63 |
| - /// this value when zooming out. |
64 |
| - pub max_scale: Option<f32>, |
| 66 | + pub max_scale: f32, |
65 | 67 | /// The minimum x position of the camera window
|
66 |
| - /// |
67 |
| - /// If present, the orthographic projection will be clamped to this boundary both |
68 |
| - /// when dragging the window, and zooming out. |
69 |
| - pub min_x: Option<f32>, |
| 68 | + pub min_x: f32, |
70 | 69 | /// The maximum x position of the camera window
|
71 |
| - /// |
72 |
| - /// If present, the orthographic projection will be clamped to this boundary both |
73 |
| - /// when dragging the window, and zooming out. |
74 |
| - pub max_x: Option<f32>, |
| 70 | + pub max_x: f32, |
75 | 71 | /// The minimum y position of the camera window
|
76 |
| - /// |
77 |
| - /// If present, the orthographic projection will be clamped to this boundary both |
78 |
| - /// when dragging the window, and zooming out. |
79 |
| - pub min_y: Option<f32>, |
| 72 | + pub min_y: f32, |
80 | 73 | /// The maximum y position of the camera window
|
81 |
| - /// |
82 |
| - /// If present, the orthographic projection will be clamped to this boundary both |
83 |
| - /// when dragging the window, and zooming out. |
84 |
| - pub max_y: Option<f32>, |
| 74 | + pub max_y: f32, |
85 | 75 | }
|
86 | 76 |
|
87 | 77 | impl Default for OgleSettings {
|
88 | 78 | fn default() -> Self {
|
89 | 79 | Self {
|
90 | 80 | min_scale: -(1.0 - 0.00001),
|
91 |
| - max_scale: None, |
92 |
| - min_x: None, |
93 |
| - max_x: None, |
94 |
| - min_y: None, |
95 |
| - max_y: None, |
| 81 | + max_scale: f32::INFINITY, |
| 82 | + min_x: f32::NEG_INFINITY, |
| 83 | + max_x: f32::INFINITY, |
| 84 | + min_y: f32::NEG_INFINITY, |
| 85 | + max_y: f32::INFINITY, |
96 | 86 | }
|
97 | 87 | }
|
98 | 88 | }
|
99 | 89 |
|
100 | 90 | pub mod prelude {
|
101 |
| - pub use super::{OgleCommandExt, OgleMode, OgleRig, OgleSettings, OgleTarget}; |
| 91 | + pub use super::{OgleCam, OgleMode, OgleSettings, OgleTarget}; |
102 | 92 | }
|
0 commit comments