pub struct LobbyManager { /* private fields */ }Expand description
Server-side manager for all active lobbies.
Implementations§
Source§impl LobbyManager
impl LobbyManager
pub fn new() -> Self
Sourcepub fn create_lobby(
&mut self,
host_id: PlayerId,
host_name: impl Into<String>,
name: impl Into<String>,
config: LobbyConfig,
) -> Result<LobbyId, LobbyError>
pub fn create_lobby( &mut self, host_id: PlayerId, host_name: impl Into<String>, name: impl Into<String>, config: LobbyConfig, ) -> Result<LobbyId, LobbyError>
Create a new lobby. The host is automatically added as the first player.
Sourcepub fn destroy_lobby(&mut self, id: LobbyId) -> Result<(), LobbyError>
pub fn destroy_lobby(&mut self, id: LobbyId) -> Result<(), LobbyError>
Destroy a lobby, removing all players from the tracking map.
Sourcepub fn join(
&mut self,
player_id: PlayerId,
player_name: impl Into<String>,
lobby_id: LobbyId,
password: &str,
) -> Result<(), LobbyError>
pub fn join( &mut self, player_id: PlayerId, player_name: impl Into<String>, lobby_id: LobbyId, password: &str, ) -> Result<(), LobbyError>
Add a player to a lobby.
Sourcepub fn leave(&mut self, player_id: PlayerId) -> Result<LobbyId, LobbyError>
pub fn leave(&mut self, player_id: PlayerId) -> Result<LobbyId, LobbyError>
Remove a player from their current lobby.
Sourcepub fn set_ready(
&mut self,
player_id: PlayerId,
ready: bool,
) -> Result<(), LobbyError>
pub fn set_ready( &mut self, player_id: PlayerId, ready: bool, ) -> Result<(), LobbyError>
Set the ready state of a player.
Sourcepub fn kick(
&mut self,
host_id: PlayerId,
target_id: PlayerId,
) -> Result<(), LobbyError>
pub fn kick( &mut self, host_id: PlayerId, target_id: PlayerId, ) -> Result<(), LobbyError>
Host kicks a player.
Sourcepub fn start_game(&mut self, host_id: PlayerId) -> Result<(), LobbyError>
pub fn start_game(&mut self, host_id: PlayerId) -> Result<(), LobbyError>
Attempt to start the game. Called by host or automatically when all ready.
Returns Ok(()) and transitions lobby to Countdown.
Sourcepub fn tick(&mut self, dt: f32) -> Vec<LobbyId>
pub fn tick(&mut self, dt: f32) -> Vec<LobbyId>
Tick all lobby countdowns. Returns a list of lobby IDs that transitioned to InGame.
Sourcepub fn end_game(&mut self, lobby_id: LobbyId) -> Result<(), LobbyError>
pub fn end_game(&mut self, lobby_id: LobbyId) -> Result<(), LobbyError>
Mark a lobby as finished and transition to Postgame.
Sourcepub fn reset_lobby(&mut self, lobby_id: LobbyId) -> Result<(), LobbyError>
pub fn reset_lobby(&mut self, lobby_id: LobbyId) -> Result<(), LobbyError>
Reset lobby back to waiting state.
pub fn lobby(&self, id: LobbyId) -> Option<&Lobby>
pub fn lobby_for_player(&self, player_id: PlayerId) -> Option<&Lobby>
pub fn lobby_count(&self) -> usize
Sourcepub fn public_lobbies(&self) -> Vec<&Lobby>
pub fn public_lobbies(&self) -> Vec<&Lobby>
All public lobbies sorted by player count (descending).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LobbyManager
impl RefUnwindSafe for LobbyManager
impl Send for LobbyManager
impl Sync for LobbyManager
impl Unpin for LobbyManager
impl UnsafeUnpin for LobbyManager
impl UnwindSafe for LobbyManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.