Files
Billiards/controllers/game/modes/base_mode.gd

69 lines
2.1 KiB
GDScript3
Raw Normal View History

2026-08-07 02:50:54 -05:00
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_state: Dictionary = {}
2026-08-07 02:50:54 -05:00
# 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,
2026-08-07 02:50:54 -05:00
}
func _init() -> void:
pass
2026-08-07 02:50:54 -05:00
func generate_ball_state() -> 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
2026-08-07 02:50:54 -05:00
return state
func which_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_state[ball.name]["turn"] = turn_count
ball_state[ball.name]["player"] = which_player()
ball_state[ball.name]["reaped"] = not ball_state[ball.name]["reaped"]
func process_ball(ball: Node3D) -> void:
balls_sunk.append(ball.name)
ball_state[ball.name]["turn"] = turn_count
ball_state[ball.name]["player"] = which_player()
ball_state[ball.name]["sunk"] = not ball_state[ball.name]["sunk"]
2026-08-07 02:50:54 -05:00
func handle_switch_user() -> void:
assert(false, "This method needs to be overridden...")