accounts are now real
This commit is contained in:
51
src/bin/client/state.rs
Normal file
51
src/bin/client/state.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
use iris::prelude::*;
|
||||
use openworm::net::NetServerMsg;
|
||||
use std::thread::JoinHandle;
|
||||
|
||||
use crate::net::NetHandle;
|
||||
|
||||
#[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<WidgetId<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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user