plaza_lobby 0.7.3

Single-server lobby and room management for the Plaza real-time shared-state framework.
Documentation
use crate::error::LobbyError;
use crate::op_payloads::RoomSettings;
use crate::room::RoomHandle;
use std::sync::Arc;
use crate::RoomId;
use async_trait::async_trait;
use plaza::agent::AgentId;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

/// Trait for a factory that knows how to create and spawn a specific type of game room.
/// The application developer implements this trait for each distinct game type their lobby supports.
#[async_trait]
pub trait RoomFactory: Send + Sync + 'static {
  /// The type for custom game-specific settings, part of `RoomSettings`.
  type CustomGameSettings: Clone + Debug + Send + Sync + 'static + Serialize + for<'de> Deserialize<'de> + Default;
  /// The game-specific `Op` type for the rooms this factory creates.
  type GameOp: Clone + Debug + Send + Sync + 'static + Serialize + for<'de> Deserialize<'de>;
  /// The `AgentId` type used within the game rooms.
  type GameID: AgentId;
  /// The game-specific `StateType` for the rooms.
  type GameStateType: Clone + Debug + Send + Sync + 'static + Default;

  /// Creates, configures and spawns a new game room, returning the handle the
  /// lobby will hold it by.
  ///
  /// The handle is a trait object so that it names neither
  /// [`GameOp`](Self::GameOp) nor [`GameStateType`](Self::GameStateType), which
  /// are the two a room in another process could not supply. Return an
  /// [`InProcessRoomHandle`](crate::room::InProcessRoomHandle) for a room that
  /// runs here, or your own type for one that does not.
  ///
  /// A lobby that needs to speak to its rooms in their own op vocabulary keeps
  /// its own `RoomId -> CommandSender` map beside this. That map is application
  /// knowledge; putting it on the handle would put `GameOp` back into the
  /// trait.
  ///
  /// # Arguments
  /// * `room_id`: The unique ID pre-assigned to this room by the [`InMemoryLobbyManager`](crate::manager::InMemoryLobbyManager).
  /// * `room_settings`: The full settings for this room, including custom game settings.
  async fn spawn_room(
    &self,
    room_id: RoomId,
    room_settings: &RoomSettings<Self::CustomGameSettings>,
  ) -> Result<Arc<dyn RoomHandle<Self::GameID, Self::CustomGameSettings>>, LobbyError>;
}