use galactica_content::Content; use galactica_galaxy::GxShipHandle; use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode}; use crate::{camera::Camera, inputstatus::InputStatus, PlayerStatus}; pub struct PlayerAgent { /// Which ship this player is controlling pub ship: Option, /// This player's camera pub camera: Camera, /// What buttons this player is pressing pub input: InputStatus, /// What the player currently has selected pub selection: Option<()>, } impl PlayerAgent { pub fn new(ship: GxShipHandle) -> Self { Self { input: InputStatus::new(), camera: Camera::new(), ship: Some(ship), selection: None, } } pub fn set_camera_aspect(&mut self, v: f32) { self.camera.aspect = v } pub fn process_key(&mut self, state: &ElementState, key: &VirtualKeyCode) { self.input.process_key(state, key) } pub fn process_click(&mut self, state: &ElementState, key: &MouseButton) { self.input.process_click(state, key) } pub fn process_scroll(&mut self, delta: &MouseScrollDelta, phase: &TouchPhase) { self.input.process_scroll(delta, phase) } pub fn step(&mut self, ct: &Content, status: PlayerStatus) { if self.input.v_scroll != 0.0 { self.camera.zoom = (self.camera.zoom + self.input.v_scroll) .clamp(ct.get_config().zoom_min, ct.get_config().zoom_max); self.input.v_scroll = 0.0; } self.camera.pos = status.pos; } }