Skip to main content

flatland_client_lib/
session.rs

1//! Client-side session events (decoded from server messages).
2
3use flatland_protocol::{
4    ChatMessage, EntityId, HarvestResult, Intent, Seq, SessionId, Snapshot, Tick, TickDelta,
5};
6
7#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
8pub enum SessionEvent {
9    Welcome {
10        session_id: SessionId,
11        entity_id: EntityId,
12        snapshot: Snapshot,
13    },
14    /// Map/recipe/catalog reload — apply snapshot static layers in place.
15    ContentUpdated {
16        snapshot: Snapshot,
17    },
18    Tick(TickDelta),
19    IntentAck {
20        entity_id: EntityId,
21        seq: Seq,
22        tick: Tick,
23    },
24    Chat(ChatMessage),
25    HarvestResult(HarvestResult),
26    CraftResult(flatland_protocol::CraftResult),
27    Death(flatland_protocol::DeathNotice),
28    Interaction(flatland_protocol::InteractionNotice),
29    ShopOpened(flatland_protocol::ShopCatalog),
30    UseResult(flatland_protocol::UseResult),
31    Disconnected {
32        reason: Option<String>,
33    },
34}
35
36/// Gameplay session handle (remote TCP or in-process worker).
37#[async_trait::async_trait]
38pub trait PlayConnection: Send {
39    fn session_id(&self) -> SessionId;
40    fn entity_id(&self) -> EntityId;
41    async fn submit_intent(&self, intent: Intent) -> anyhow::Result<()>;
42    fn try_next_event(&mut self) -> Option<SessionEvent>;
43    async fn next_event(&mut self) -> Option<SessionEvent>;
44    fn disconnect(&self);
45}