Skip to content

Commit 1c706bd

Browse files
committed
build: wip
1 parent 4e17bfb commit 1c706bd

File tree

9 files changed

+401
-390
lines changed

9 files changed

+401
-390
lines changed

Cargo.toml

+8-4
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@ readme = "README.md"
2424

2525

2626
[workspace.dependencies]
27-
bevy = { version = "0.14.0", default-features = false }
27+
bevy = { version = "0.15.0", default-features = false }
2828

2929
[dependencies]
3030
bevy = { workspace = true, default-features = false, features = [
3131
"bevy_state",
3232
"bevy_core_pipeline",
3333
] }
34-
bevy_pancam = { version = "0.12.0", features = ["bevy_egui"] }
35-
dolly = "0.5.0"
34+
bevy_egui = { version = "0.31", optional = true, default-features = false }
35+
dolly = "0.6.0"
3636
mint = "0.5.9"
3737

3838
[dev-dependencies]
39-
wasm-bindgen-test = "0.3.42"
39+
wasm-bindgen-test = "0.3.47"
40+
41+
[features]
42+
default = ["bevy_egui"]
43+
bevy_egui = ["dep:bevy_egui"]

examples/demo/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ publish = false
1010
[dependencies]
1111
bevy = { workspace = true, default-features = true }
1212
bevy_ogle = { path = "../.." }
13-
bevy_egui = { version = "0.28.0" }
13+
bevy_egui = { version = "0.31.1" }
1414
rand = "0.8.5"

examples/demo/src/main.rs

+19-24
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ fn main() {
1212
.add_plugins(EguiPlugin)
1313
.add_plugins(OglePlugin {
1414
initial_settings: OgleSettings {
15-
min_x: Some(-500.0),
16-
max_x: Some(500.0),
17-
min_y: Some(-500.0),
18-
max_y: Some(500.0),
15+
min_x: -500.0,
16+
max_x: 500.0,
17+
min_y: -500.0,
18+
max_y: 500.0,
1919
..default()
2020
},
2121
})
@@ -28,37 +28,32 @@ fn main() {
2828
fn setup_scene(mut commands: Commands) {
2929
// Background
3030

31-
commands.spawn(SpriteBundle {
32-
sprite: Sprite {
31+
commands.spawn((
32+
Sprite {
3333
color: css::ORANGE.into(),
3434
custom_size: Some(Vec2::new(600.0, 600.0)),
3535
..default()
3636
},
37-
transform: Transform::from_xyz(0.0, 0.0, 0.),
38-
..default()
39-
});
40-
commands.spawn(SpriteBundle {
41-
sprite: Sprite {
37+
Transform::from_xyz(0.0, 0.0, 1.0),
38+
));
39+
commands.spawn((
40+
Sprite {
4241
color: css::LIME.into(),
4342
custom_size: Some(Vec2::new(500.0, 500.0)),
4443
..default()
4544
},
46-
transform: Transform::from_xyz(0.0, 0.0, 0.),
47-
..default()
48-
});
45+
Transform::from_xyz(0.0, 0.0, 2.0),
46+
));
4947

5048
// Moving thing for the camera to follow
5149
commands.spawn((
5250
ThingToFollow,
53-
SpriteBundle {
54-
sprite: Sprite {
55-
color: css::RED.into(),
56-
custom_size: Some(Vec2::new(5.0, 5.0)),
57-
..default()
58-
},
59-
transform: Transform::from_xyz(0.0, 0.0, 0.),
51+
Sprite {
52+
color: css::RED.into(),
53+
custom_size: Some(Vec2::new(5.0, 5.0)),
6054
..default()
6155
},
56+
Transform::from_xyz(0.0, 0.0, 3.0),
6257
));
6358
}
6459

@@ -68,9 +63,9 @@ fn move_target(
6863
mut gizmos: Gizmos,
6964
) {
7065
let mut transform = query_thing.single_mut();
71-
transform.translation.x += time.delta_seconds() * (random::<f32>() * 500.0 - 500.0 / 2.0);
72-
transform.translation.y += time.delta_seconds() * (random::<f32>() * 500.0 - 500.0 / 2.0);
73-
gizmos.rect_2d(transform.translation.xy(), 0.0, (5.0, 5.0).into(), css::RED);
66+
transform.translation.x += time.delta_secs() * (random::<f32>() * 500.0 - 500.0 / 2.0);
67+
transform.translation.y += time.delta_secs() * (random::<f32>() * 500.0 - 500.0 / 2.0);
68+
gizmos.rect_2d(transform.translation.xy(), (5.0, 5.0).into(), css::RED);
7469
}
7570

7671
fn control_camera_ui(

src/commands.rs

-75
This file was deleted.

src/lib.rs

+48-58
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,92 @@
11
use bevy::prelude::*;
22
use dolly::prelude::*;
33

4-
mod commands;
5-
pub use commands::OgleCommandExt;
4+
mod systems;
65

76
mod plugin;
87
pub use plugin::OglePlugin;
98

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)]
1140
pub enum OgleTarget {
1241
Position(Vec2),
1342
Entity(Entity),
1443
EntityWithOffset((Entity, Vec2)),
44+
#[default]
1545
None,
1646
}
1747

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)]
2549
pub enum OgleMode {
2650
/// The camera will not move under normal circumstances.
2751
#[default]
2852
Frozen,
53+
/// The user can only zoom the camera.
54+
ZoomOnly,
2955
/// The camera should exponentially follow its target.
3056
Following,
3157
/// The camera is in a detached pancam mode.
3258
Pancam,
3359
}
3460

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)]
5562
pub struct OgleSettings {
5663
/// The minimum scale for the camera
57-
///
58-
/// The orthographic projection's scale will be clamped at this value when zooming in
5964
pub min_scale: f32,
6065
/// 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,
6567
/// 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,
7069
/// 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,
7571
/// 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,
8073
/// 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,
8575
}
8676

8777
impl Default for OgleSettings {
8878
fn default() -> Self {
8979
Self {
9080
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,
9686
}
9787
}
9888
}
9989

10090
pub mod prelude {
101-
pub use super::{OgleCommandExt, OgleMode, OgleRig, OgleSettings, OgleTarget};
91+
pub use super::{OgleCam, OgleMode, OgleSettings, OgleTarget};
10292
}

0 commit comments

Comments
 (0)