use flatland_protocol::{
ChatMessage, EntityId, HarvestResult, Intent, Seq, SessionId, Snapshot, Tick, TickDelta,
};
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum SessionEvent {
Welcome {
session_id: SessionId,
entity_id: EntityId,
snapshot: Snapshot,
},
ContentUpdated {
snapshot: Snapshot,
},
Tick(TickDelta),
IntentAck {
entity_id: EntityId,
seq: Seq,
tick: Tick,
},
Chat(ChatMessage),
HarvestResult(HarvestResult),
CraftResult(flatland_protocol::CraftResult),
Death(flatland_protocol::DeathNotice),
Interaction(flatland_protocol::InteractionNotice),
ShopOpened(flatland_protocol::ShopCatalog),
UseResult(flatland_protocol::UseResult),
Disconnected {
reason: Option<String>,
},
}
#[async_trait::async_trait]
pub trait PlayConnection: Send {
fn session_id(&self) -> SessionId;
fn entity_id(&self) -> EntityId;
async fn submit_intent(&self, intent: Intent) -> anyhow::Result<()>;
fn try_next_event(&mut self) -> Option<SessionEvent>;
async fn next_event(&mut self) -> Option<SessionEvent>;
fn disconnect(&self);
}