34 lines
595 B
GDScript
34 lines
595 B
GDScript
class_name PlayerManager
|
|
extends Node3D
|
|
|
|
var id_to_player = {}
|
|
|
|
func _ready():
|
|
Global.players = self
|
|
|
|
var timer := %UpdatePlayers as Timer
|
|
timer.timeout.connect(tick)
|
|
|
|
func tick():
|
|
PerformanceComponent.update_all_animations()
|
|
|
|
func add(player: Player):
|
|
if has(player.id):
|
|
return
|
|
|
|
add_child(player)
|
|
id_to_player[player.id] = player
|
|
|
|
func get_player(id: String) -> Player:
|
|
return id_to_player[id] as Player
|
|
|
|
func has(id: String) -> bool:
|
|
return id_to_player.has(id)
|
|
|
|
func remove(id: String):
|
|
if !id_to_player.has(id):
|
|
return
|
|
|
|
id_to_player[id].queue_free()
|
|
id_to_player.erase(id)
|