reactor_camera/
components.rs1use bevy::prelude::*;
2use reactor_spatial::prelude::*;
3
4#[derive(Component, Default, Clone, Copy, PartialEq, Debug, Reflect)]
6pub struct MainCamera;
7
8#[derive(Component, Default, Clone, Copy, PartialEq, Debug, Reflect)]
10pub struct MainCameraShouldTarget;
11
12#[derive(Component, Default, Clone, Copy, PartialEq, Eq, Debug, Reflect)]
14pub struct CameraTarget(pub Option<Entity>);
15
16#[derive(Component, Default, Clone, Copy, PartialEq, Debug, Reflect)]
18pub enum CameraStyle {
19 DeadZone(DeadZone),
21 ScreenByScreen,
23 #[default]
24 Exact,
26}
27
28#[derive(Default, Clone, Copy, PartialEq, Debug, Reflect)]
30pub struct DeadZone {
31 pub width: f32,
33 pub height: f32,
35}
36
37impl DeadZone {
38 pub fn new(width: f32, height: f32) -> Self {
40 Self { width, height }
41 }
42
43 pub fn half_width(&self) -> f32 {
45 self.width / 2.
46 }
47
48 pub fn half_height(&self) -> f32 {
50 self.height / 2.
51 }
52}
53
54#[derive(Component, Clone, Copy, PartialEq, Debug, Reflect)]
56pub struct CameraLerp {
57 pub factor: Vec2,
59}
60
61impl CameraLerp {
62 pub fn new(factor: f32) -> Self {
64 Self {
65 factor: Vec2::new(factor, factor),
66 }
67 }
68}
69
70impl Default for CameraLerp {
71 fn default() -> Self {
72 Self { factor: Vec2::ONE }
73 }
74}
75
76#[derive(Component, Default, Clone, Copy, PartialEq, Debug, Reflect)]
78pub struct CameraLead {
79 pub lead_amount: Vec2,
81 pub last_target_position: Option<Position2D>,
83}
84
85impl CameraLead {
86 pub fn new(lead_amount: Vec2) -> Self {
88 Self {
89 lead_amount,
90 last_target_position: None,
91 }
92 }
93}
94
95#[derive(Bundle, Default)]
97pub struct CameraBundle2D {
98 pub spatial: SpatialBundle2DRaw,
100 pub camera_bundle: Camera2dBundle,
102 pub style: CameraStyle,
104 pub lerp: CameraLerp,
106 pub lead: CameraLead,
108 pub target: CameraTarget,
110}