Galactica/crates/playeragent/src/playeragent.rs

57 lines
1.4 KiB
Rust
Raw Normal View History

2024-01-11 11:28:51 -08:00
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<GxShipHandle>,
/// 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;
}
}