diff --git a/systems/scoreboard/scoreboard.gd b/systems/scoreboard/scoreboard.gd new file mode 100644 index 0000000..718d414 --- /dev/null +++ b/systems/scoreboard/scoreboard.gd @@ -0,0 +1,45 @@ +class_name Scoreboard extends Node + +# define the properties +@export var num_teams: int = 1 +@export var num_players_per_team: int = 1 + +# define the scoreboard dictionary +var scoreboard := {} + +# initialize the scoreboard +func _init() -> void: + scoreboard = {} + for team in range(1, num_teams + 1): + scoreboard[team] = {} + for player in range(1, num_players_per_team + 1): + scoreboard[team][player] = {'O': 0, 'D': 0, 'S': 0} + +# update score function +func update_score(team: int, player: int, points: int, category: String) -> void: + if not scoreboard.has(team) or not scoreboard[team].has(player): + push_warning("Team or player not found in the scoreboard.") + return + if category not in ['O', 'D', 'S']: + push_warning("Invalid category. Please use 'O' for Offense, 'D' for Defense, or 'S' for Style.") + return + scoreboard[team][player][category] += points + +# get player score function +func get_player_score(team: int, player: int) -> Dictionary: + if not scoreboard.has(team) or not scoreboard[team].has(player): + push_warning("Team or player not found in the scoreboard.") + return {} + return scoreboard[team][player] + +# get team score function +func get_team_score(team: int) -> Dictionary: + if not scoreboard.has(team): + push_warning("Team not found in the scoreboard.") + return {} + var team_score = {'O': 0, 'D': 0, 'S': 0} + for player_scores in scoreboard[team].values(): + team_score['O'] += player_scores['O'] + team_score['D'] += player_scores['D'] + team_score['S'] += player_scores['S'] + return team_score diff --git a/systems/scoreboard/scoreboard.tscn b/systems/scoreboard/scoreboard.tscn new file mode 100644 index 0000000..b11d077 --- /dev/null +++ b/systems/scoreboard/scoreboard.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://cupyjjyhjh5bq"] + +[ext_resource type="Script" path="res://systems/scoreboard/scoreboard.gd" id="1_alsat"] + +[node name="Scoreboard" type="Node2D"] +script = ExtResource("1_alsat")