BattleManager is the entry point for every match in Beast Card Clash. It extends StateMachine and is attached to the battle scene. It is responsible for constructing the human player, spawning AI bots, wiring up signal connections, and initializing the battlefield before the state machine begins managing turn flow.
BattleManager is a scene-level node, not an autoload. It exists only while the battle scene is active. For global singletons, see Autoloads.Class overview
battle_manager.gd
Initializes players
Creates the human player from
PlayerStats and generates 1–3 AI bots with random decks.Wires the UI
Connects
BattleUI to player data and disables the 3D dice (via BattleWorld) until the state machine permits a roll.Connects signals
Links
deck_updated on the human player to BattleUI.set_hand_from_deck so the hand rerenders automatically.Feeds the state machine
Exposes the populated
players array so the StateMachine can iterate over participants during each phase.Properties
Maximum number of participants in a single battle, including the human player and all bots. Default:
4.Exported reference to the
BattleUI node in the battle scene. Assign this in the Godot Inspector.Exported reference to the
BattleWorld node, which owns the 3D dice and rocks. BattleManager calls battle_world.set_dice(false) during setup_world() to disable dice interaction at match start.The single human
Player instance. Populated by setup_player(). Use this reference anywhere you need to read or modify the human player’s state.All participants — the human player plus however many bots were created. The array is shuffled by
setup_bots() to randomize turn order, so position 0 is not guaranteed to be the human player. The StateMachine iterates this array to drive turns.All rock objects placed in the battle scene. Declared for future use by battle states that need to reference world positions.
Methods
setup_player()
Creates the human Player from the globally stored PlayerStats, builds their deck, appends them to players, and connects the deck_updated signal to keep the hand display in sync.
BattleUI.set_hand_from_deck fires automatically with the updated deck. You do not need to call set_hand_from_deck manually after this point.
setup_bots()
Spawns between 1 and MAX_PLAYERS - 1 AI bots, each with a freshly generated deck. After all bots are added, the full players array is shuffled to randomize turn order.
Chosen randomly via
randi_range(1, MAX_PLAYERS - 1). With MAX_PLAYERS = 4, this produces 1, 2, or 3 bots per battle.setup_ui()
Prepares the battle UI for the start of a match: refreshes all player stat panels, populates the human player’s hand from their current deck, and hides the end-of-game UI.
setup_ui() after both setup_player() and setup_bots() have completed, so players is fully populated when refresh_player_stats iterates over it.
setup_world()
Configures the 3D world elements. Disables dice interaction at match start so the player cannot roll before the state machine permits it.
BattleWorld.set_dice(enabled: bool) sets dice.clickable on the underlying Dice node. The battle state machine re-enables dice interaction at the start of the human player’s turn.
Initialization sequence
BattleStart calls all four setup methods in this order:
setup_player()
Create the human player, build their deck, and connect the
deck_updated → set_hand_from_deck signal.setup_bots()
Randomly generate 1–3 bots, append them to
players, then shuffle players to determine turn order.Signal wiring
The most important signal connection established byBattleManager is:
| Signal | Source | Target | Effect |
|---|---|---|---|
deck_updated | Player | BattleUI.set_hand_from_deck | Rerenders the hand display whenever the player’s deck changes |
Related pages
Battle state machine
How the five-phase state machine consumes
players and orchestrates turn flow.Card system
How
CardScene and the inner Card data class represent cards in the hand.Battle mechanics
Player-facing rules for how a battle round works.
Autoloads
Global singletons (
SceneManager, MusicManager, FlagsManager) available to BattleManager.