Skip to main content

flatland_play_loop/
local.rs

1//! Client-local play state (not mirrored from server).
2
3use flatland_client_ui::{HudViewMode, MapTargetState, MovementState};
4
5use crate::chat::ChatSession;
6
7#[derive(Debug)]
8pub struct PlayLocalState {
9    pub movement: MovementState,
10    pub map_target: MapTargetState,
11    pub auto_nav_goal: Option<(f32, f32)>,
12    pub chat: ChatSession,
13    pub hud_view: HudViewMode,
14    pub mouse_hover: Option<(f32, f32)>,
15    pub was_harvesting: bool,
16}
17
18impl PlayLocalState {
19    pub fn new(keys: flatland_client_lib::ClientKeyBindings) -> Self {
20        let hud_view = flatland_client_lib::ClientConfig::load()
21            .hud_view
22            .as_deref()
23            .and_then(HudViewMode::from_label)
24            .unwrap_or_default();
25        Self {
26            movement: MovementState::with_keys(keys),
27            map_target: MapTargetState::default(),
28            auto_nav_goal: None,
29            chat: ChatSession::default(),
30            hud_view,
31            mouse_hover: None,
32            was_harvesting: false,
33        }
34    }
35
36    pub fn cycle_hud_view(&mut self) {
37        self.hud_view = self.hud_view.cycle();
38        let mut cfg = flatland_client_lib::ClientConfig::load();
39        let _ = cfg.save_hud_view(self.hud_view.label());
40    }
41
42    pub fn clear_nav(&mut self) {
43        self.map_target.deactivate();
44        self.auto_nav_goal = None;
45        self.movement.reset();
46    }
47}