WIP cleanup

This commit is contained in:
Daniel Flanagan 2021-12-07 16:43:37 -06:00
parent 7f1e8d26ef
commit cdd3a00186
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
11 changed files with 73 additions and 24 deletions

20
objects/lobby.tscn Normal file
View file

@ -0,0 +1,20 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scripts/objects/lobby.gd" type="Script" id=1]
[node name="Control" type="HBoxContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 0
size_flags_vertical = 0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="."]
margin_right = 1024.0
margin_bottom = 600.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Lobby Name"

View file

@ -11,7 +11,7 @@ config_version=4
[application] [application]
config/name="kdt" config/name="kdt"
run/main_scene="res://screens/main.tscn" run/main_scene="res://screens/main_menu.tscn"
config/icon="res://assets/img/icon.png" config/icon="res://assets/img/icon.png"
[autoload] [autoload]
@ -22,10 +22,6 @@ Global="*res://scripts/global/global.gd"
singletons=[ "res://webrtc/webrtc.tres" ] singletons=[ "res://webrtc/webrtc.tres" ]
[network]
ssl/certificates="res://ca-certificates.crt"
[physics] [physics]
common/enable_pause_aware_picking=true common/enable_pause_aware_picking=true

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=4 format=2]
[ext_resource path="res://scripts/screens/multiplayer.gd" type="Script" id=1] [ext_resource path="res://scripts/screens/lobby_browser.gd" type="Script" id=1]
[ext_resource path="res://assets/theme.tres" type="Theme" id=2] [ext_resource path="res://assets/theme.tres" type="Theme" id=2]
[ext_resource path="res://objects/lobby.tscn" type="PackedScene" id=3]
[node name="Control" type="MarginContainer"] [node name="Control" type="MarginContainer"]
anchor_right = 1.0 anchor_right = 1.0
@ -112,6 +113,8 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Control" parent="v/body/lobbies" instance=ExtResource( 3 )]
[connection signal="pressed" from="v/head/back" to="." method="_on_back_pressed"] [connection signal="pressed" from="v/head/back" to="." method="_on_back_pressed"]
[connection signal="pressed" from="v/head/create_lobby" to="." method="_on_create_lobby_pressed"] [connection signal="pressed" from="v/head/create_lobby" to="." method="_on_create_lobby_pressed"]
[connection signal="pressed" from="v/head/join" to="." method="_on_join_pressed"] [connection signal="pressed" from="v/head/join" to="." method="_on_join_pressed"]

View file

@ -1,12 +1,12 @@
[gd_scene load_steps=5 format=2] [gd_scene load_steps=5 format=2]
[ext_resource path="res://scripts/screens/main.gd" type="Script" id=1] [ext_resource path="res://assets/fonts/iosevkalyte/iosevkalyte-regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/fonts/iosevkalyte/iosevkalyte-regular.ttf" type="DynamicFontData" id=2] [ext_resource path="res://assets/theme.tres" type="Theme" id=2]
[ext_resource path="res://assets/theme.tres" type="Theme" id=3] [ext_resource path="res://scripts/screens/main_menu.gd" type="Script" id=3]
[sub_resource type="DynamicFont" id=1] [sub_resource type="DynamicFont" id=1]
size = 70 size = 70
font_data = ExtResource( 2 ) font_data = ExtResource( 1 )
[node name="Control" type="MarginContainer"] [node name="Control" type="MarginContainer"]
anchor_right = 1.0 anchor_right = 1.0
@ -15,8 +15,8 @@ margin_left = 20.0
margin_top = 20.0 margin_top = 20.0
margin_right = -20.0 margin_right = -20.0
margin_bottom = -20.0 margin_bottom = -20.0
theme = ExtResource( 3 ) theme = ExtResource( 2 )
script = ExtResource( 1 ) script = ExtResource( 3 )
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
@ -37,7 +37,7 @@ rect_min_size = Vector2( 150, 50 )
hint_tooltip = "Yeah, let's get out of here." hint_tooltip = "Yeah, let's get out of here."
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
theme = ExtResource( 3 ) theme = ExtResource( 2 )
text = "Quit" text = "Quit"
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
@ -51,7 +51,7 @@ rect_min_size = Vector2( 150, 50 )
hint_tooltip = "This is what you came for!" hint_tooltip = "This is what you came for!"
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
theme = ExtResource( 3 ) theme = ExtResource( 2 )
text = "Multiplayer" text = "Multiplayer"
[node name="Singleplayer" type="Button" parent="VBoxContainer/HBoxContainer"] [node name="Singleplayer" type="Button" parent="VBoxContainer/HBoxContainer"]
@ -64,7 +64,7 @@ hint_tooltip = "This is a multiplayer tech demo, you dunce.
And no, you may not ask why the button is here." And no, you may not ask why the button is here."
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
theme = ExtResource( 3 ) theme = ExtResource( 2 )
disabled = true disabled = true
text = "Singleplayer" text = "Singleplayer"
__meta__ = { __meta__ = {

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=3 format=2]
[ext_resource path="res://scripts/screens/lobby.gd" type="Script" id=1] [ext_resource path="res://scripts/screens/multiplayer_lobby.gd" type="Script" id=1]
[ext_resource path="res://assets/theme.tres" type="Theme" id=2] [ext_resource path="res://assets/theme.tres" type="Theme" id=2]
[node name="lobby" type="MarginContainer"] [node name="lobby" type="MarginContainer"]

View file

@ -26,25 +26,25 @@ func _ready():
lobby_browser() lobby_browser()
func goto_scene(scene_resource_name): func goto_scene(scene_resource_name):
var _result = get_tree().change_scene("res://%s.tscn" % scene_resource_name) var _result = get_tree().change_scene("res://screens/%s.tscn" % scene_resource_name)
func main_menu(): func main_menu():
client.close() client.close()
goto_scene("main") goto_scene("main_menu")
func start_singleplayer_game(): func start_singleplayer_game():
client.close() client.close()
goto_scene("game") goto_scene("game")
func _signaller_connected(): func _signaller_connected():
goto_scene("multiplayer") goto_scene("lobby_browser")
func lobby_browser(): func lobby_browser():
client.close() client.close()
Global.client.connect_to_signaller() Global.client.connect_to_signaller()
func lobby(): func lobby():
goto_scene("lobby") goto_scene("multiplayer_lobby")
func quit(): func quit():
client.close() client.close()

View file

@ -3,13 +3,14 @@ extends Node
""" """
This module is responsible for making a WebSocket connection to the signaller This module is responsible for making a WebSocket connection to the signaller
in order to enable establishish WebRTC P2P connections. Another module is in order to enable establishish WebRTC P2P connections. Another module is
expected to fully setup the peer connections. expected to fully setup the peer connections. (./multiplayer_client.gd)
""" """
signal lobby_new(lobbiesList) signal lobby_new(lobbiesList)
signal lobby_delete(id) signal lobby_delete(id)
signal lobby_joined(id, peer_id) signal lobby_joined(id, peer_id)
signal lobby_left(id) signal lobby_left(id)
signal peer_joined(peers) signal peer_joined(peers)
signal peer_left(id) signal peer_left(id)
signal candidate_received(data) signal candidate_received(data)
@ -82,7 +83,6 @@ func _process(_delta: float):
var status: int = ws.get_connection_status() var status: int = ws.get_connection_status()
if status == WebSocketClient.CONNECTION_CONNECTED or status == WebSocketClient.CONNECTION_CONNECTING: if status == WebSocketClient.CONNECTION_CONNECTED or status == WebSocketClient.CONNECTION_CONNECTING:
ws.poll() ws.poll()
func join_lobby(id: String): func join_lobby(id: String):
return _send("lobby_join:%s" % id) return _send("lobby_join:%s" % id)
@ -118,6 +118,10 @@ func set_lobby_max_players(n: int):
if is_host(): if is_host():
_send("json:%s" % JSON.print({"type": "update_lobby", "data": {"maxPlayers": n}})) _send("json:%s" % JSON.print({"type": "update_lobby", "data": {"maxPlayers": n}}))
func set_ready(n: bool):
if !is_host():
_send("set_ready:%s" % JSON.print(n))
func _parse_msg(): func _parse_msg():
var msg: String = ws.get_peer(1).get_packet().get_string_from_utf8() var msg: String = ws.get_peer(1).get_packet().get_string_from_utf8()
if msg.begins_with("json:"): if msg.begins_with("json:"):

25
scripts/objects/lobby.gd Normal file
View file

@ -0,0 +1,25 @@
extends HBoxContainer
export(String) var id = "Some UUID"
export(String) var text = "Lobby" setget set_text
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():
$Label.text = "%s (%d/%d players)" % [text, current_players, max_players]
func set_text(t):
text = t
_update_text()
func set_max_players(n):
max_players = n
_update_text()
func set_current_players(n):
current_players = n
_update_text()

View file

@ -87,9 +87,10 @@ func update_player_count():
peers_list_label.text = "Players: %d" % peers.get_item_count() peers_list_label.text = "Players: %d" % peers.get_item_count()
func _on_Button_pressed(): func _on_Button_pressed():
send_chkkkkkkat_message() send_chat_message()
func _on_ready_up_toggled(button_pressed: bool): func _on_ready_up_toggled(button_pressed: bool):
Global.client.signaller.set_ready(button_pressed)
func _on_lobby_info_text_changed(new_text: String): func _on_lobby_info_text_changed(new_text: String):
Global.client.signaller.set_lobby_name(new_text) Global.client.signaller.set_lobby_name(new_text)