mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-19 19:44:46 +00:00
✨ simple scoreboard system
This commit is contained in:
parent
3f19e3e033
commit
e6cd2a79c6
45
systems/scoreboard/scoreboard.gd
Normal file
45
systems/scoreboard/scoreboard.gd
Normal file
|
|
@ -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
|
||||
6
systems/scoreboard/scoreboard.tscn
Normal file
6
systems/scoreboard/scoreboard.tscn
Normal file
|
|
@ -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")
|
||||
Loading…
Reference in a new issue