Files
Billiards/controllers/game/modes/base_mode.gd
itdominator b931ef5a01 feat(game): improve mode state handling and active player UI
* Rename and consolidate ball state tracking across game modes
* Add ball finalization and win-condition hooks
* Track foul points by negating reaped ball points
* Update turn switching and ball processing flow
* Add active-player indicator to the camera controller UI
* Refresh active-player label when the turn changes
2026-08-12 21:38:49 -05:00

82 lines
2.5 KiB
GDScript

class_name BaseMode extends Node
# NOTE: The ball's queue_free is called higher up and after game mode handles
# the ball. Never call it in a given game mode. A game mode should handle
# these signals to handle game related rules regarding ball sinks.
var turn_count: int = 1
var player_1_points: int = 0
var player_2_points: int = 0
# NOTE: Kinda a super tracker of balls. Not all entries
# generated are used depending on the game type.
var ball_states: Dictionary = {}
# NOTE: Used to track handoff logic and is cleared after eah switch accordingly.
var balls_sunk: Array = []
var balls_reaped: Array = []
# NOTE: Kinda a super tracker of the state of a ball.
# Not all entries are used depending on the game type.
var BALL_STATE: Dictionary = {
"turn": 0,
"player": "",
"sunk": false,
"reaped": false,
"valid_end": true,
"points": 0,
}
func _init() -> void:
pass
func generate_ball_states() -> Dictionary:
var state := {}
for i: int in range(1, 16):
var ball_name = "%02d_ball" % i
state[ball_name] = BALL_STATE.duplicate_deep()
state[ball_name]["points"] = i
return state
func ball_states_finalized() -> bool:
var i = 0
var size = ball_states.values().size() - 1
for ball_state in ball_states.values():
if not ball_state["reaped"] or not ball_state["sunk"]:
break
i += 1
return i == size
func process_win_condition() -> void:
assert(false, "This method needs to be overridden...")
func get_player() -> String:
return \
"Player 1" \
if \
Globals.game_data.client1 == Globals.multiplayer_data.current_turn_player_id \
else \
"Player 2"
func reap_ball(ball: Node3D) -> void:
balls_reaped.append(ball.name)
ball_states[ball.name]["turn"] = turn_count
ball_states[ball.name]["player"] = get_player()
ball_states[ball.name]["reaped"] = not ball_states[ball.name]["reaped"]
func process_ball(ball: Node3D) -> void:
balls_sunk.append(ball.name)
ball_states[ball.name]["turn"] = turn_count
ball_states[ball.name]["player"] = get_player()
ball_states[ball.name]["sunk"] = not ball_states[ball.name]["sunk"]
func handle_switch_user() -> void:
assert(false, "This method needs to be overridden...")