34 lines
595 B
GDScript3
Raw Normal View History

2024-01-28 18:18:16 +00:00
class_name PlayerManager
extends Node3D
2024-02-27 20:05:55 +00:00
var id_to_player = {}
2024-01-28 18:18:16 +00:00
func _ready():
Global.players = self
2024-02-27 20:05:55 +00:00
var timer := %UpdatePlayers as Timer
timer.timeout.connect(tick)
func tick():
PerformanceComponent.update_all_animations()
2024-01-28 18:18:16 +00:00
func add(player: Player):
2024-01-29 22:16:06 +00:00
if has(player.id):
return
2024-01-28 18:18:16 +00:00
add_child(player)
2024-02-27 20:05:55 +00:00
id_to_player[player.id] = player
2024-01-28 18:18:16 +00:00
func get_player(id: String) -> Player:
2024-02-27 20:05:55 +00:00
return id_to_player[id] as Player
2024-01-28 18:18:16 +00:00
2024-01-29 22:16:06 +00:00
func has(id: String) -> bool:
2024-02-27 20:05:55 +00:00
return id_to_player.has(id)
2024-01-29 22:16:06 +00:00
2024-01-28 18:18:16 +00:00
func remove(id: String):
2024-02-27 20:05:55 +00:00
if !id_to_player.has(id):
2024-01-28 21:08:08 +00:00
return
2024-02-27 20:05:55 +00:00
id_to_player[id].queue_free()
id_to_player.erase(id)