51 lines
1022 B
Rust
51 lines
1022 B
Rust
use crate::net::NetHandle;
|
|
use iris::prelude::*;
|
|
use openworm::net::NetServerMsg;
|
|
use std::thread::JoinHandle;
|
|
|
|
#[derive(Default)]
|
|
pub struct Connect {
|
|
pub handle: Option<JoinHandle<()>>,
|
|
}
|
|
|
|
pub struct Login {
|
|
pub handle: NetHandle,
|
|
}
|
|
|
|
pub struct LoggedIn {
|
|
pub network: NetHandle,
|
|
pub msgs: Vec<NetServerMsg>,
|
|
pub channel: Option<WidgetRef<Span>>,
|
|
pub username: String,
|
|
}
|
|
|
|
pub enum ClientState {
|
|
Connect(Connect),
|
|
Login(Login),
|
|
LoggedIn(LoggedIn),
|
|
}
|
|
|
|
impl Default for ClientState {
|
|
fn default() -> Self {
|
|
Self::Connect(Default::default())
|
|
}
|
|
}
|
|
|
|
impl ClientState {
|
|
pub fn take(&mut self) -> Self {
|
|
std::mem::take(self)
|
|
}
|
|
pub fn exit(&mut self) {
|
|
let s = self.take();
|
|
match s {
|
|
ClientState::Connect(_) => (),
|
|
ClientState::Login(Login { handle }) => {
|
|
handle.exit();
|
|
}
|
|
ClientState::LoggedIn(state) => {
|
|
state.network.exit();
|
|
}
|
|
}
|
|
}
|
|
}
|