godot-webrtc-mplayer-testing/scripts/objects/lobby.gd

40 lines
1 KiB
GDScript3
Raw Permalink Normal View History

2021-12-07 16:43:37 -06:00
extends HBoxContainer
2021-12-08 16:35:37 -06:00
class_name LobbyControl
2021-12-11 00:08:28 -06:00
export(String) var uuid = "Some UUID"
2021-12-08 16:35:37 -06:00
export(String) var display_name = "Lobby" setget set_display_name
2021-12-07 16:43:37 -06:00
export(int) var max_players = 20 setget set_max_players
export(int) var current_players = 1 setget set_current_players
export(bool) var locked = false
func _ready():
_update_text()
func _update_text():
2021-12-08 16:35:37 -06:00
$Label.text = "%s (%d/%d players)" % [display_name, current_players, max_players]
2021-12-11 00:08:28 -06:00
const keys = ["uuid", "display_name", "max_players", "current_players", "locked"]
2021-12-08 16:35:37 -06:00
func set_with_dict(dict):
if dict.has("name"): self.display_name = dict["name"]
2021-12-21 16:40:58 -06:00
if dict.has("currentPlayers"): self.current_players = dict["currentPlayers"]
if dict.has("maxPlayers"): self.max_players = dict["maxPlayers"]
2021-12-08 16:35:37 -06:00
for k in keys:
if dict.has(k):
self[k] = dict[k]
2021-12-07 16:43:37 -06:00
2021-12-08 16:35:37 -06:00
func set_display_name(t):
display_name = t
2021-12-07 16:43:37 -06:00
_update_text()
func set_max_players(n):
max_players = n
_update_text()
func set_current_players(n):
current_players = n
_update_text()
2021-12-08 16:35:37 -06:00
func _on_join_pressed():
2021-12-11 00:08:28 -06:00
Global.client.join_lobby(uuid)