RoundManager
Orchestrates round lifecycles, phase transitions, and state management.
Types
Events
interface Events {OnRoundReset: ()}RoundConfig
interface RoundConfig {InitialPhase: string--
Which key in Phases to enter on Start()
UpdateInterval: number?--
Optional; seconds between ticks when no Driver is set (default 1)
AutoWirePlayers: boolean?--
Optional; if true, automatically connects to Players.PlayerAdded and Players.PlayerRemoving (default false)
StaleStateTimeout: number?--
Optional; seconds before a disconnected player's state is considered stale (default 30)
}The configuration table passed to RoundKit.new().
Functions
new
Constructs a new RoundManager.
Start
RoundManager:Start() → ()Starts the manager loop and initializes the first phase
Pause
RoundManager:Pause() → ()Stops the manager from updating.
Resume
RoundManager:Resume() → ()Resumes the manager loop.
TransitionTo
RoundManager:TransitionTo(phaseName: string,force: boolean?--
Internal use only; forces the transition even if the target phase is not allowed (used by Reset())
) → booleanEvaluates whetever the current phase can transition to the given phase Fires 'OnPhaseChanged' if the transition is successful.
Update
RoundManager:Update(dt: number) → ()Updates the round manager state, evaluates the current phase state, if it should transition, the win condition and manages stale player states.
CheckWinCondition
Checks the win condition and fires the OnWinConditionMet event if it is met. Fires 'OnWinConditionMet' if the win condition is met.
BuildContext
Builds a new context for the current state of the round manager.
EvaluateWinCondition
Evaluates the win condition and returns the outcome.
ResolveAllowedTransitions
Types
interface Phase {Name: string--
The name of the phase
AllowedTransitions: {[string]} | (ctx: Context) → {[string]}--
A list of phase names that this phase can transition to, or a function that returns such a list
Duration: number?--
Optional; the duration of this phase in seconds (default nil, meaning no automatic transition)
CanTransitionTo: (targetPhase: string) → boolean?--
Optional; a function that determines if the round can transition to the target phase (default nil, meaning always true)
EvaluateWinCondition: boolean?--
Optional; if true, the win condition will be evaluated at 'EvaluateWinConditionInterval' (defaults false)
EvaluateWinConditionInterval: number?--
Optional; the interval in seconds at which to evaluate the win condition (default 1)
OnEnter: (ctx: Context) → ()?--
Optional; a function that is called when the round enters this phase
OnUpdate: (dt: number) → ()?--
Optional; a function that is called every update tick while in this phase
}Resolves the allowed transitions for the given phase.
OnPlayerAdded
Detects when a player is added to the game. If the player already has round state (reconnection), triggers the reconnection policy. Otherwise, fires the 'OnPlayerJoined' event for the developer to handle.
CAUTION
You must connect this to Players.PlayerAdded (or similar) or set AutoWirePlayers to true for it to work.
OnPlayerJoined
Connects a callback to the OnPlayerJoined event.
CAUTION
You must connect :OnPlayerAdded to Players.PlayerAdded (or similar) or set AutoWirePlayers to true for it to work.
OnPlayerRemoving
Detects when a player is leaving the game. If the player has a round state, marks them as disconnected Fires the 'OnPlayerLeft' event for the developer to handle.
CAUTION
You must connect this to Players.PlayerRemoving (or similar) or set AutoWirePlayers to true for it to work.
CAUTION
The player round state is not removed from the registry, it is only marked as disconnected. This allows for reconnection policies to handle the player if they rejoin. Player's round state will be removed from the registry if it is considered stale (disconnected for longer than StaleStateTimeout seconds).
ClearRoundState
RoundManager:ClearRoundState() → ()Clears the round state, fires the OnRoundReset event. Fires 'OnRoundReset' when the round state is cleared.
Reset
RoundManager:Reset() → ()Resets the round state and forcefully transitions to the initial phase.
Destroy
RoundManager:Destroy() → ()Destroys the round manager, clears the round state, disconnects all connections, and destroys the event bus.