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():
|
2024-02-28 11:15:58 +00:00
|
|
|
var visible_players := PerformanceComponent.get_visible_players_sorted_by_distance()
|
|
|
|
AnimationPerformance.update_animation_quality(visible_players)
|
2024-02-27 20:05:55 +00:00
|
|
|
|
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-28 11:15:58 +00:00
|
|
|
return id_to_player.get(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)
|