use bevy::{ input::mouse::{AccumulatedMouseScroll, MouseScrollPixelsPerLine}, prelude::*, window::PrimaryWindow, }; use crate::world::WorldMap; pub struct CameraPlugin; const DRAG_BUTTONS: [MouseButton; 2] = [MouseButton::Middle, MouseButton::Right]; impl Plugin for CameraPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, spawn_camera).add_systems( Update, (keyboard_pan, drag_pan, scroll_zoom, clamp_to_world).chain(), ); } } #[derive(Component, Clone, Debug)] pub struct CameraController { pub pan_speed: f32, pub fast_multiplier: f32, pub zoom_per_line: f32, pub min_scale: f32, pub max_scale: f32, } impl Default for CameraController { fn default() -> Self { Self { pan_speed: 600.0, fast_multiplier: 3.0, zoom_per_line: 0.15, min_scale: 0.2, max_scale: 4.0, } } } fn spawn_camera(mut commands: Commands, map: Res) { commands.spawn(( Camera2d, CameraController::default(), Transform::from_translation((map.world_size() / 2.0).extend(0.0)), )); } fn ortho(projection: &mut Projection) -> &mut OrthographicProjection { match projection { Projection::Orthographic(o) => o, _ => panic!("camera must use an orthographic projection"), } } fn keyboard_pan( keys: Res>, time: Res