use bevy::prelude::*;
use dolly::prelude::*;
mod systems;
mod plugin;
pub use plugin::OglePlugin;
#[cfg(feature = "internal_bevy_egui")]
mod egui_support;
#[derive(Debug, Clone, Copy, SystemSet, PartialEq, Eq, Hash)]
pub enum OgleSystems {
Update,
Input,
Correction,
Commit,
}
#[derive(Component, Debug)]
#[require(Camera2d)]
pub struct OgleCam {
pub settings: OgleSettings,
pub target: OgleTarget,
pub mode: OgleMode,
rig: CameraRig,
}
impl OgleCam {
pub fn new(settings: OgleSettings, target: OgleTarget, mode: OgleMode) -> Self {
Self {
settings,
target,
mode,
rig: CameraRig::builder()
.with(Position::new(mint::Point3 {
x: 0.0,
y: 0.0,
z: 1.0,
}))
.with(Smooth::new_position(1.5).predictive(false))
.build(),
}
}
}
impl Default for OgleCam {
fn default() -> Self {
Self::new(Default::default(), Default::default(), Default::default())
}
}
impl OgleCam {
pub fn position(&self) -> Vec3 {
let position = self.rig.driver::<Position>().position;
Vec3 {
x: position.x,
y: position.y,
z: position.z,
}
}
pub fn teleport(&mut self, position: Vec3) {
self.rig = CameraRig::builder()
.with(Position::new(mint::Point3 {
x: position.x,
y: position.y,
z: position.z,
}))
.with(Smooth::new_position(1.5).predictive(false))
.build();
}
}
#[derive(Clone, PartialEq, Debug, Default)]
pub enum OgleTarget {
Position(Vec2),
Entity(Entity),
EntityWithOffset((Entity, Vec2)),
#[default]
None,
}
#[derive(Clone, PartialEq, Eq, Hash, Debug, Default)]
pub enum OgleMode {
#[default]
Frozen,
ZoomOnly,
MoveOnly,
Normal,
Pancam,
}
#[derive(Debug, Clone, PartialEq)]
pub struct OgleSettings {
pub zoom_sensitivity: f32,
pub bounds: OgleBoundingSettings,
pub pancam: OglePancamSettings,
}
impl Default for OgleSettings {
fn default() -> Self {
Self {
zoom_sensitivity: 100.0,
bounds: Default::default(),
pancam: Default::default(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct OglePancamSettings {
pub keyboard_speed: f32,
pub grab_buttons: Vec<MouseButton>,
pub up_keys: Vec<KeyCode>,
pub down_keys: Vec<KeyCode>,
pub left_keys: Vec<KeyCode>,
pub right_keys: Vec<KeyCode>,
}
impl Default for OglePancamSettings {
fn default() -> Self {
const GRAB_BUTTONS: [MouseButton; 3] =
[MouseButton::Left, MouseButton::Right, MouseButton::Middle];
const UP_KEYS: [KeyCode; 2] = [KeyCode::ArrowUp, KeyCode::KeyW];
const DOWN_KEYS: [KeyCode; 2] = [KeyCode::ArrowDown, KeyCode::KeyS];
const LEFT_KEYS: [KeyCode; 2] = [KeyCode::ArrowLeft, KeyCode::KeyA];
const RIGHT_KEYS: [KeyCode; 2] = [KeyCode::ArrowRight, KeyCode::KeyD];
Self {
keyboard_speed: 1000.0,
grab_buttons: GRAB_BUTTONS.to_vec(),
up_keys: UP_KEYS.to_vec(),
down_keys: DOWN_KEYS.to_vec(),
left_keys: LEFT_KEYS.to_vec(),
right_keys: RIGHT_KEYS.to_vec(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct OgleBoundingSettings {
pub enabled: bool,
pub min_scale: f32,
pub max_scale: f32,
pub min_x: f32,
pub max_x: f32,
pub min_y: f32,
pub max_y: f32,
}
impl Default for OgleBoundingSettings {
fn default() -> Self {
Self {
enabled: false,
min_scale: 0.00001,
max_scale: f32::INFINITY,
min_x: f32::NEG_INFINITY,
max_x: f32::INFINITY,
min_y: f32::NEG_INFINITY,
max_y: f32::INFINITY,
}
}
}
pub mod prelude {
pub use super::{OgleCam, OgleMode, OgleSettings, OgleTarget};
}