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

38 lines
908 B
GDScript3
Raw 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-07 16:43:37 -06:00
export(String) var id = "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]
const keys = ["id", "display_name", "max_players", "current_players", "locked"]
func set_with_dict(dict):
if dict.has("name"): self.display_name = dict["name"]
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-09 21:10:17 -06:00
Global.signaller_client.join_lobby(id)