feat(game): refactor ball state and turn handling

* Replace `valid_end` with `is_foul` for invalid ball sinks
* Rename and centralize ball state tracking
* Add ball finalization and win-condition hooks
* Update turn switching to retain the player after valid sinks
* Apply negative points to reaped balls
* Add active-player indicator to the camera UI
* Emit active-player updates when the turn changes
This commit is contained in:
2026-08-12 22:14:03 -05:00
parent 09369d3dd4
commit c95cc511e6
9 changed files with 166 additions and 77 deletions

View File

@@ -9,32 +9,43 @@ func reap_ball(ball: Node3D) -> void:
if ball.name == "09_ball":
# TODO: 9 ball must not be be destroyed. Handle rule...
ball_state[ball.name]["valid_end"] = false
pass
ball_states[ball.name]["is_foul"] = true
func process_ball(ball: Node3D) -> void:
super(ball)
if ball.name == "09_ball":
# TODO: 9 ball must be sunk last. Handle rule...
ball_state[ball.name]["valid_end"] = false
pass
ball_states[ball.name]["is_foul"] = true
func handle_switch_user() -> void:
push_warning("Balls reaped: ", balls_reaped.size() )
push_warning("Balls sunk: ", balls_sunk.size() )
var switch_player: bool = true
if not balls_reaped.is_empty():
# TODO: Handle points, etc
for ball_name in balls_reaped:
ball_states[ball_name]["points"] = -ball_states[ball_name]["points"]
balls_reaped.clear()
if balls_sunk.is_empty():
Globals.game_state.switch_active_player()
turn_count += 1
if not balls_sunk.is_empty():
# TODO: Handle points, etc, insure 9-ball not sunk unless last.
# Insure we process stripped vs solid ball and apropriate points accordingly.
# ball_states[ball.name]["is_foul"] = true
switch_player = false
balls_sunk.clear()
if ball_states_finalized():
process_win_condition()
return
# TODO: Handle points, etc
# Globals.multiplayer_data.current_turn_player_id
if switch_player:
Globals.game_state.switch_active_player()
turn_count += 1
else:
turn_count += 1
balls_sunk.clear()
turn_count += 1
func process_win_condition() -> void:
pass