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    NpcTalkOpened(flatland_protocol::NpcTalkOpened),
31    NpcTalkPending(flatland_protocol::NpcTalkPending),
32    NpcTalkReply(flatland_protocol::NpcTalkReply),
33    NpcTalkClosed(flatland_protocol::NpcTalkClosed),
34    NpcTalkError(flatland_protocol::NpcTalkError),
35    UseResult(flatland_protocol::UseResult),
36    QuestOffer(flatland_protocol::QuestOffer),
37    QuestAccepted(flatland_protocol::QuestNotice),
38    QuestWithdrawn(flatland_protocol::QuestNotice),
39    QuestStepCompleted(flatland_protocol::QuestNotice),
40    QuestCompleted(flatland_protocol::QuestNotice),
41    Disconnected {
42        reason: Option<String>,
43    },
44}
45
46/// Gameplay session handle (remote TCP or in-process worker).
47#[async_trait::async_trait]
48pub trait PlayConnection: Send {
49    fn session_id(&self) -> SessionId;
50    fn entity_id(&self) -> EntityId;
51    async fn submit_intent(&self, intent: Intent) -> anyhow::Result<()>;
52    fn try_next_event(&mut self) -> Option<SessionEvent>;
53    async fn next_event(&mut self) -> Option<SessionEvent>;
54    fn disconnect(&self);
55}