Merge pull request '[Feature]: Matchmaking Part2' (!6) from ticket/TD-18-Matchmaking-pt2 into trunk
All checks were successful
Quality Check / Linting (push) Successful in 6s
All checks were successful
Quality Check / Linting (push) Successful in 6s
Reviewed-on: #6 Reviewed-by: SZUT-Kevin <kevin.schmidt9101@gmail.com>
This commit is contained in:
commit
e509eedffe
26 changed files with 592 additions and 1892 deletions
2
gdlintrc
2
gdlintrc
|
@ -37,7 +37,7 @@ loop-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
|
|||
max-file-lines: 1000
|
||||
max-line-length: 80
|
||||
max-public-methods: 20
|
||||
max-returns: 6
|
||||
max-returns: 20
|
||||
mixed-tabs-and-spaces: null
|
||||
no-elif-return: null
|
||||
no-else-return: null
|
||||
|
|
|
@ -18,6 +18,16 @@ config/icon="res://textures/icon.svg"
|
|||
[autoload]
|
||||
|
||||
ConnectionChannel="*res://scripts/channel/connection/connection_channel.gd"
|
||||
MatchmakingChannel="*res://scripts/channel/matchmaking/matchmaking_channel.gd"
|
||||
MatchChannel="*res://scripts/channel/match/match_channel.gd"
|
||||
CurrentMatch="*res://scripts/match/current_match.gd"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=1920
|
||||
window/size/viewport_height=1080
|
||||
window/stretch/mode="viewport"
|
||||
window/stretch/aspect="expand"
|
||||
|
||||
[editor_plugins]
|
||||
|
||||
|
|
49
scenes/game.tscn
Normal file
49
scenes/game.tscn
Normal file
|
@ -0,0 +1,49 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://co1x3hlc2efr6"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/match/ui/opponent_name.gd" id="1_saby1"]
|
||||
[ext_resource type="Script" path="res://scripts/match/ui/current_game_time.gd" id="2_3jcub"]
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="HUD" type="Control" parent="CanvasLayer"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Opponent Name" type="RichTextLabel" parent="CanvasLayer/HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 5
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
offset_left = -0.5
|
||||
offset_right = 0.5
|
||||
offset_bottom = 45.0
|
||||
grow_horizontal = 2
|
||||
text = "Unknown"
|
||||
fit_content = true
|
||||
scroll_active = false
|
||||
autowrap_mode = 0
|
||||
script = ExtResource("1_saby1")
|
||||
|
||||
[node name="Time" type="RichTextLabel" parent="CanvasLayer/HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -20.0
|
||||
offset_top = -20.0
|
||||
offset_right = 20.0
|
||||
offset_bottom = 20.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
fit_content = true
|
||||
scroll_active = false
|
||||
autowrap_mode = 0
|
||||
script = ExtResource("2_3jcub")
|
|
@ -1,120 +0,0 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://dtaaw31x3n22f"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/ui/login.gd" id="1_12w35"]
|
||||
[ext_resource type="Script" path="res://scripts/ui/show_banner_on_error.gd" id="1_41hxt"]
|
||||
[ext_resource type="Resource" uid="uid://cdixdbu3sqgjn" path="res://config/api_config.tres" id="2_60hb8"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_d0bbp"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_bdovr"]
|
||||
bg_color = Color(0.74463, 0.147328, 0, 1)
|
||||
|
||||
[node name="Login" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_d0bbp")
|
||||
|
||||
[node name="Container" type="VBoxContainer" parent="Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Banner" type="PanelContainer" parent="Panel/Container" node_paths=PackedStringArray("login", "text")]
|
||||
layout_mode = 2
|
||||
script = ExtResource("1_41hxt")
|
||||
login = NodePath("../CenterContainer/VBoxContainer/Button")
|
||||
text = NodePath("CenterContainer/MarginContainer/RichTextLabel")
|
||||
|
||||
[node name="Panel" type="Panel" parent="Panel/Container/Banner"]
|
||||
layout_mode = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_bdovr")
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="Panel/Container/Banner"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Panel/Container/Banner/CenterContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_top = 8
|
||||
theme_override_constants/margin_bottom = 8
|
||||
|
||||
[node name="RichTextLabel" type="RichTextLabel" parent="Panel/Container/Banner/CenterContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
text = "Keine Verbindung"
|
||||
fit_content = true
|
||||
autowrap_mode = 0
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="Panel/Container"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Panel/Container/CenterContainer"]
|
||||
custom_minimum_size = Vector2(500, 0)
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 16
|
||||
|
||||
[node name="Header" type="RichTextLabel" parent="Panel/Container/CenterContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/normal_font_size = 30
|
||||
text = "Login"
|
||||
fit_content = true
|
||||
scroll_active = false
|
||||
autowrap_mode = 0
|
||||
|
||||
[node name="InputContainer" type="VBoxContainer" parent="Panel/Container/CenterContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="UsernameContainer" type="VBoxContainer" parent="Panel/Container/CenterContainer/VBoxContainer/InputContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="UsernameLabel" type="RichTextLabel" parent="Panel/Container/CenterContainer/VBoxContainer/InputContainer/UsernameContainer"]
|
||||
layout_mode = 2
|
||||
text = "Username:
|
||||
"
|
||||
fit_content = true
|
||||
scroll_active = false
|
||||
autowrap_mode = 0
|
||||
|
||||
[node name="UsernameInput" type="LineEdit" parent="Panel/Container/CenterContainer/VBoxContainer/InputContainer/UsernameContainer"]
|
||||
layout_mode = 2
|
||||
placeholder_text = "username"
|
||||
|
||||
[node name="PasswordContainer" type="VBoxContainer" parent="Panel/Container/CenterContainer/VBoxContainer/InputContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="PaswordLabel" type="RichTextLabel" parent="Panel/Container/CenterContainer/VBoxContainer/InputContainer/PasswordContainer"]
|
||||
layout_mode = 2
|
||||
text = "Password:"
|
||||
fit_content = true
|
||||
scroll_active = false
|
||||
autowrap_mode = 0
|
||||
|
||||
[node name="PasswordInput" type="LineEdit" parent="Panel/Container/CenterContainer/VBoxContainer/InputContainer/PasswordContainer"]
|
||||
layout_mode = 2
|
||||
placeholder_text = "password"
|
||||
secret = true
|
||||
|
||||
[node name="Button" type="Button" parent="Panel/Container/CenterContainer/VBoxContainer" node_paths=PackedStringArray("username_field", "password_field")]
|
||||
layout_mode = 2
|
||||
text = "Login"
|
||||
script = ExtResource("1_12w35")
|
||||
username_field = NodePath("../InputContainer/UsernameContainer/UsernameInput")
|
||||
password_field = NodePath("../InputContainer/PasswordContainer/PasswordInput")
|
||||
api_config = ExtResource("2_60hb8")
|
||||
|
||||
[node name="HTTPRequest" type="HTTPRequest" parent="Panel/Container/CenterContainer/VBoxContainer/Button"]
|
|
@ -1,7 +1,24 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://bqfijb7bk2g7j"]
|
||||
[gd_scene load_steps=12 format=3 uid="uid://bqfijb7bk2g7j"]
|
||||
|
||||
[ext_resource type="Theme" uid="uid://bt4hxdwromnxs" path="res://ui/theme.tres" id="1_6qgep"]
|
||||
[ext_resource type="Script" path="res://scripts/ui/switch_to_scene.gd" id="2_c477a"]
|
||||
[ext_resource type="Script" path="res://scripts/ui/login/show_banner_on_error.gd" id="2_1tbi1"]
|
||||
[ext_resource type="Script" path="res://scripts/ui/swap_menu.gd" id="2_c477a"]
|
||||
[ext_resource type="Script" path="res://scripts/ui/login/login.gd" id="3_33cgr"]
|
||||
[ext_resource type="Resource" uid="uid://cdixdbu3sqgjn" path="res://config/api_config.tres" id="4_5vuod"]
|
||||
[ext_resource type="Script" path="res://scripts/ui/quit.gd" id="6_cixwl"]
|
||||
[ext_resource type="Script" path="res://scripts/ui/lobby/search_match.gd" id="7_dmfpl"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_q2pxx"]
|
||||
bg_color = Color(0.52, 0.52, 0.52, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_socr1"]
|
||||
bg_color = Color(0.74463, 0.147328, 0, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_fh0xh"]
|
||||
bg_color = Color(0.135012, 0.135012, 0.135012, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_x4jly"]
|
||||
bg_color = Color(7.89344e-06, 0.65411, 0.87403, 1)
|
||||
|
||||
[node name="Root" type="Panel"]
|
||||
anchors_preset = 15
|
||||
|
@ -12,22 +29,26 @@ offset_right = -1.0
|
|||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme = ExtResource("1_6qgep")
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_q2pxx")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
[node name="Screens" type="TabContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -180.5
|
||||
offset_top = -44.0
|
||||
offset_right = 180.5
|
||||
offset_bottom = 44.0
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
current_tab = 0
|
||||
tabs_visible = false
|
||||
|
||||
[node name="Text" type="RichTextLabel" parent="VBoxContainer"]
|
||||
[node name="Start" type="CenterContainer" parent="Screens"]
|
||||
layout_mode = 2
|
||||
metadata/_tab_index = 0
|
||||
|
||||
[node name="V" type="VBoxContainer" parent="Screens/Start"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Title" type="RichTextLabel" parent="Screens/Start/V"]
|
||||
clip_contents = false
|
||||
layout_mode = 2
|
||||
size_flags_stretch_ratio = 7.45
|
||||
|
@ -37,14 +58,141 @@ fit_content = true
|
|||
scroll_active = false
|
||||
autowrap_mode = 0
|
||||
|
||||
[node name="Button" type="Button" parent="VBoxContainer"]
|
||||
[node name="Login" type="Button" parent="Screens/Start/V" node_paths=PackedStringArray("menu")]
|
||||
layout_mode = 2
|
||||
text = "Login"
|
||||
script = ExtResource("2_c477a")
|
||||
scene_name = "login"
|
||||
menu = NodePath("../../../Login")
|
||||
|
||||
[node name="Button2" type="Button" parent="VBoxContainer"]
|
||||
[node name="Settings" type="Button" parent="Screens/Start/V"]
|
||||
layout_mode = 2
|
||||
text = "Testszene"
|
||||
text = "Settings"
|
||||
script = ExtResource("2_c477a")
|
||||
scene_name = "theme_test"
|
||||
|
||||
[node name="Quit" type="Button" parent="Screens/Start/V"]
|
||||
layout_mode = 2
|
||||
text = "Quit"
|
||||
script = ExtResource("6_cixwl")
|
||||
|
||||
[node name="Login" type="VBoxContainer" parent="Screens"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
metadata/_tab_index = 1
|
||||
|
||||
[node name="Banner" type="PanelContainer" parent="Screens/Login" node_paths=PackedStringArray("login", "text")]
|
||||
layout_mode = 2
|
||||
script = ExtResource("2_1tbi1")
|
||||
login = NodePath("../CenterContainer/VBoxContainer/Actions/Login")
|
||||
text = NodePath("CenterContainer/MarginContainer/RichTextLabel")
|
||||
|
||||
[node name="Panel" type="Panel" parent="Screens/Login/Banner"]
|
||||
layout_mode = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_socr1")
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="Screens/Login/Banner"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Screens/Login/Banner/CenterContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_top = 8
|
||||
theme_override_constants/margin_bottom = 8
|
||||
|
||||
[node name="RichTextLabel" type="RichTextLabel" parent="Screens/Login/Banner/CenterContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
text = "Keine Verbindung"
|
||||
fit_content = true
|
||||
autowrap_mode = 0
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="Screens/Login"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Screens/Login/CenterContainer"]
|
||||
custom_minimum_size = Vector2(500, 0)
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 16
|
||||
|
||||
[node name="UsernameInput" type="LineEdit" parent="Screens/Login/CenterContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
placeholder_text = "username"
|
||||
|
||||
[node name="PasswordInput" type="LineEdit" parent="Screens/Login/CenterContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
placeholder_text = "password"
|
||||
secret = true
|
||||
|
||||
[node name="Actions" type="HBoxContainer" parent="Screens/Login/CenterContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Back" type="Button" parent="Screens/Login/CenterContainer/VBoxContainer/Actions" node_paths=PackedStringArray("menu")]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Back"
|
||||
script = ExtResource("2_c477a")
|
||||
menu = NodePath("../../../../../Start")
|
||||
|
||||
[node name="Login" type="Button" parent="Screens/Login/CenterContainer/VBoxContainer/Actions" node_paths=PackedStringArray("username_field", "password_field", "next_view")]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Login"
|
||||
script = ExtResource("3_33cgr")
|
||||
username_field = NodePath("../../UsernameInput")
|
||||
password_field = NodePath("../../PasswordInput")
|
||||
api_config = ExtResource("4_5vuod")
|
||||
next_view = NodePath("../../../../../Lobby")
|
||||
|
||||
[node name="HTTPRequest" type="HTTPRequest" parent="Screens/Login/CenterContainer/VBoxContainer/Actions/Login"]
|
||||
|
||||
[node name="Lobby" type="CenterContainer" parent="Screens" node_paths=PackedStringArray("popup", "search_button", "abort_button", "accept_button", "decline_button", "time_bar", "login")]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
script = ExtResource("7_dmfpl")
|
||||
popup = NodePath("Popup")
|
||||
search_button = NodePath("Search")
|
||||
abort_button = NodePath("Abort")
|
||||
accept_button = NodePath("Popup/MarginContainer/HBoxContainer/Accept")
|
||||
decline_button = NodePath("Popup/MarginContainer/HBoxContainer/Decline")
|
||||
time_bar = NodePath("Popup/Time Bar")
|
||||
login = NodePath("../Login/CenterContainer/VBoxContainer/Actions/Login")
|
||||
metadata/_tab_index = 2
|
||||
|
||||
[node name="Search" type="Button" parent="Screens/Lobby"]
|
||||
layout_mode = 2
|
||||
text = "Search"
|
||||
|
||||
[node name="Abort" type="Button" parent="Screens/Lobby"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
text = "Abort"
|
||||
|
||||
[node name="Popup" type="PanelContainer" parent="Screens/Lobby"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_fh0xh")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Screens/Lobby/Popup"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 16
|
||||
theme_override_constants/margin_top = 16
|
||||
theme_override_constants/margin_right = 16
|
||||
theme_override_constants/margin_bottom = 16
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Screens/Lobby/Popup/MarginContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 16
|
||||
|
||||
[node name="Accept" type="Button" parent="Screens/Lobby/Popup/MarginContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Accept
|
||||
"
|
||||
|
||||
[node name="Decline" type="Button" parent="Screens/Lobby/Popup/MarginContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Decline"
|
||||
|
||||
[node name="Time Bar" type="ProgressBar" parent="Screens/Lobby/Popup"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 8
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_x4jly")
|
||||
value = 100.0
|
||||
show_percentage = false
|
||||
|
|
File diff suppressed because it is too large
Load diff
12
scripts/channel/match/current_unix_time_message.gd
Normal file
12
scripts/channel/match/current_unix_time_message.gd
Normal file
|
@ -0,0 +1,12 @@
|
|||
class_name CurrentUnixTimeMessage
|
||||
extends Message
|
||||
|
||||
const MESSAGE_ID: String = "CurrentUnixTime"
|
||||
|
||||
@export var time: int
|
||||
# gdlint:ignore = class-variable-name
|
||||
@export var matchId: String
|
||||
|
||||
|
||||
func get_message_id() -> String:
|
||||
return MESSAGE_ID
|
20
scripts/channel/match/match_channel.gd
Normal file
20
scripts/channel/match/match_channel.gd
Normal file
|
@ -0,0 +1,20 @@
|
|||
extends Channel
|
||||
|
||||
signal on_match_update(msg: CurrentUnixTimeMessage)
|
||||
|
||||
|
||||
func get_channel_location() -> String:
|
||||
return "match"
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
self.socket.poll()
|
||||
if self.socket.get_ready_state() != WebSocketPeer.STATE_OPEN:
|
||||
return
|
||||
while self.socket.get_available_packet_count():
|
||||
var msg := CurrentUnixTimeMessage.deserialize(
|
||||
self.socket.get_packet().get_string_from_utf8(), [CurrentUnixTimeMessage]
|
||||
)
|
||||
if msg.get_message_id() != CurrentUnixTimeMessage.MESSAGE_ID:
|
||||
return
|
||||
on_match_update.emit(msg)
|
11
scripts/channel/matchmaking/match_aborted_message.gd
Normal file
11
scripts/channel/matchmaking/match_aborted_message.gd
Normal file
|
@ -0,0 +1,11 @@
|
|||
class_name MatchAbortedMessage
|
||||
extends Message
|
||||
|
||||
const MESSAGE_ID := "MatchAborted"
|
||||
|
||||
# gdlint:ignore = class-variable-name
|
||||
@export var matchId: String
|
||||
|
||||
|
||||
func get_message_id() -> String:
|
||||
return MESSAGE_ID
|
10
scripts/channel/matchmaking/match_accepted_message.gd
Normal file
10
scripts/channel/matchmaking/match_accepted_message.gd
Normal file
|
@ -0,0 +1,10 @@
|
|||
class_name MatchAcceptedMessage
|
||||
extends Message
|
||||
|
||||
# gdlint:ignore = class-variable-name
|
||||
@export var matchId: String
|
||||
@export var accepted: bool
|
||||
|
||||
|
||||
func get_message_id() -> String:
|
||||
return "MatchAccepted"
|
14
scripts/channel/matchmaking/match_established_message.gd
Normal file
14
scripts/channel/matchmaking/match_established_message.gd
Normal file
|
@ -0,0 +1,14 @@
|
|||
class_name MatchEstablishedMessage
|
||||
extends Message
|
||||
|
||||
const MESSAGE_ID := "MatchEstablished"
|
||||
|
||||
# gdlint:ignore = class-variable-name
|
||||
@export var matchId: String
|
||||
# gdlint:ignore = class-variable-name
|
||||
@export var opponentName: String
|
||||
@export var token: String
|
||||
|
||||
|
||||
func get_message_id() -> String:
|
||||
return MESSAGE_ID
|
13
scripts/channel/matchmaking/match_found_message.gd
Normal file
13
scripts/channel/matchmaking/match_found_message.gd
Normal file
|
@ -0,0 +1,13 @@
|
|||
class_name MatchFoundMessage
|
||||
extends Message
|
||||
|
||||
const MESSAGE_ID := "MatchFound"
|
||||
|
||||
# gdlint:ignore = class-variable-name
|
||||
@export var matchId: String
|
||||
@export var created: int
|
||||
@export var ttl: int
|
||||
|
||||
|
||||
func get_message_id() -> String:
|
||||
return MESSAGE_ID
|
|
@ -0,0 +1,10 @@
|
|||
class_name MatchSetSearchStateMessage
|
||||
extends Message
|
||||
|
||||
const MESSAGE_ID := "MatchSetSearchState"
|
||||
|
||||
@export var searching: bool
|
||||
|
||||
|
||||
func get_message_id() -> String:
|
||||
return MESSAGE_ID
|
57
scripts/channel/matchmaking/matchmaking_channel.gd
Normal file
57
scripts/channel/matchmaking/matchmaking_channel.gd
Normal file
|
@ -0,0 +1,57 @@
|
|||
extends Channel
|
||||
|
||||
signal on_match_set_search_state(msg: MatchSetSearchStateMessage)
|
||||
signal on_match_found(msg: MatchFoundMessage)
|
||||
signal on_match_aborted
|
||||
signal on_match_established(msg: MatchEstablishedMessage)
|
||||
|
||||
|
||||
func get_channel_location() -> String:
|
||||
return "matchmaking"
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
self.socket.poll()
|
||||
if self.socket.get_ready_state() != WebSocketPeer.STATE_OPEN:
|
||||
return
|
||||
while self.socket.get_available_packet_count():
|
||||
var msg := (
|
||||
Message
|
||||
. deserialize(
|
||||
self.socket.get_packet().get_string_from_utf8(),
|
||||
[
|
||||
MatchSetSearchStateMessage,
|
||||
MatchFoundMessage,
|
||||
MatchAbortedMessage,
|
||||
MatchEstablishedMessage,
|
||||
]
|
||||
)
|
||||
)
|
||||
match msg.get_message_id():
|
||||
MatchSetSearchStateMessage.MESSAGE_ID:
|
||||
on_match_set_search_state.emit(msg)
|
||||
MatchFoundMessage.MESSAGE_ID:
|
||||
on_match_found.emit(msg)
|
||||
MatchAbortedMessage.MESSAGE_ID:
|
||||
on_match_aborted.emit()
|
||||
MatchEstablishedMessage.MESSAGE_ID:
|
||||
on_match_established.emit(msg)
|
||||
_:
|
||||
continue
|
||||
|
||||
|
||||
func send_search_state(searching: bool) -> void:
|
||||
if self.socket.get_ready_state() != WebSocketPeer.STATE_OPEN:
|
||||
return
|
||||
var msg := MatchSetSearchStateMessage.new()
|
||||
msg.searching = searching
|
||||
self.socket.send_text(Message.serialize(msg))
|
||||
|
||||
|
||||
func send_match_accepted(accepted: bool, match_id: String) -> void:
|
||||
if self.socket.get_ready_state() != WebSocketPeer.STATE_OPEN:
|
||||
return
|
||||
var msg := MatchAcceptedMessage.new()
|
||||
msg.accepted = accepted
|
||||
msg.matchId = match_id
|
||||
self.socket.send_text(Message.serialize(msg))
|
|
@ -1,6 +1,6 @@
|
|||
class_name Message
|
||||
|
||||
enum Channels { CONNECTION, TIME }
|
||||
enum Channels { CONNECTION, MATCHMAKING }
|
||||
|
||||
|
||||
func get_message_id() -> String:
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
class_name CurrentUnixTimeMessage
|
||||
extends Message
|
||||
|
||||
var time: int
|
||||
|
||||
|
||||
func get_message_id() -> String:
|
||||
return "CurrentUnixTime"
|
13
scripts/match/current_match.gd
Normal file
13
scripts/match/current_match.gd
Normal file
|
@ -0,0 +1,13 @@
|
|||
extends Node
|
||||
|
||||
enum State { NONE, RUNNING, WON, LOST }
|
||||
|
||||
var state: State = State.NONE
|
||||
var opponent_name: String = ""
|
||||
|
||||
|
||||
func start_game(msg: MatchEstablishedMessage) -> void:
|
||||
self.opponent_name = msg.opponentName
|
||||
self.state = State.RUNNING
|
||||
MatchChannel.connect_socket(msg.token)
|
||||
get_tree().change_scene_to_file("res://scenes/game.tscn")
|
9
scripts/match/ui/current_game_time.gd
Normal file
9
scripts/match/ui/current_game_time.gd
Normal file
|
@ -0,0 +1,9 @@
|
|||
extends RichTextLabel
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
MatchChannel.connect("on_match_update", on_match_update)
|
||||
|
||||
|
||||
func on_match_update(msg: CurrentUnixTimeMessage) -> void:
|
||||
self.text = str(msg.time)
|
5
scripts/match/ui/opponent_name.gd
Normal file
5
scripts/match/ui/opponent_name.gd
Normal file
|
@ -0,0 +1,5 @@
|
|||
extends RichTextLabel
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
self.text = CurrentMatch.opponent_name
|
162
scripts/ui/lobby/search_match.gd
Normal file
162
scripts/ui/lobby/search_match.gd
Normal file
|
@ -0,0 +1,162 @@
|
|||
extends Control
|
||||
|
||||
@export var popup: PanelContainer
|
||||
@export var search_button: Button
|
||||
@export var abort_button: Button
|
||||
@export var accept_button: Button
|
||||
@export var decline_button: Button
|
||||
@export var time_bar: ProgressBar
|
||||
@export var login: Login
|
||||
|
||||
var searching: bool = false
|
||||
var sent_accept_message: bool = false
|
||||
var found_match: MatchFoundMessage
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if !export_valid():
|
||||
return
|
||||
login.connect("login_successful", on_login)
|
||||
|
||||
# Websockets
|
||||
(
|
||||
ConnectionChannel
|
||||
. connect(
|
||||
"on_channel_token_received",
|
||||
on_channel_token_received,
|
||||
)
|
||||
)
|
||||
(
|
||||
MatchmakingChannel
|
||||
. connect(
|
||||
"on_match_set_search_state",
|
||||
on_match_set_search_state,
|
||||
)
|
||||
)
|
||||
MatchmakingChannel.connect("on_match_found", on_match_found)
|
||||
MatchmakingChannel.connect("on_match_aborted", on_match_aborted)
|
||||
MatchmakingChannel.connect("on_match_established", on_match_established)
|
||||
|
||||
# UI
|
||||
search_button.connect("pressed", on_search_pressed)
|
||||
abort_button.connect("pressed", on_abort_pressed)
|
||||
accept_button.connect("pressed", on_accept_pressed)
|
||||
decline_button.connect("pressed", on_decline_pressed)
|
||||
popup.visible = false
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if found_match:
|
||||
var now := int(Time.get_unix_time_from_system() * 1000)
|
||||
time_bar.max_value = found_match.ttl
|
||||
time_bar.value = found_match.ttl - (now - found_match.created)
|
||||
|
||||
|
||||
# gdlint:ignore = max-public-methods
|
||||
func export_valid() -> bool:
|
||||
if not popup:
|
||||
push_error("Popup not Set")
|
||||
return false
|
||||
if not search_button:
|
||||
push_error("Search Button not Set")
|
||||
return false
|
||||
if not abort_button:
|
||||
push_error("Abort Button not Set")
|
||||
return false
|
||||
if not accept_button:
|
||||
push_error("Accept Button not Set")
|
||||
return false
|
||||
if not decline_button:
|
||||
push_error("Decline Button not Set")
|
||||
return false
|
||||
if not time_bar:
|
||||
push_error("Time Bar not Set")
|
||||
return false
|
||||
if not login:
|
||||
push_error("No login configured")
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func on_login(_session: PlayerLoginSession) -> void:
|
||||
ConnectionChannel.request_channel_token(Message.Channels.MATCHMAKING)
|
||||
|
||||
|
||||
##############################
|
||||
# Websocket Interactions #
|
||||
##############################
|
||||
|
||||
|
||||
func on_channel_token_received(msg: ProvidedConnectionTokenMessage) -> void:
|
||||
if msg.channel != Message.Channels.MATCHMAKING:
|
||||
return
|
||||
MatchmakingChannel.connect_socket(msg.token)
|
||||
|
||||
|
||||
func on_match_set_search_state(msg: MatchSetSearchStateMessage) -> void:
|
||||
set_searching_ui(msg.searching)
|
||||
|
||||
|
||||
func on_match_found(msg: MatchFoundMessage) -> void:
|
||||
set_match_accptance_ui(true)
|
||||
set_accaptence_buttons_enabled(true)
|
||||
found_match = msg
|
||||
|
||||
|
||||
func on_match_aborted() -> void:
|
||||
set_match_accptance_ui(false)
|
||||
set_searching_ui(false)
|
||||
found_match = null
|
||||
|
||||
|
||||
func on_match_established(msg: MatchEstablishedMessage) -> void:
|
||||
CurrentMatch.start_game(msg)
|
||||
|
||||
|
||||
#############################
|
||||
# UI Interactions #
|
||||
#############################
|
||||
|
||||
|
||||
func on_search_pressed() -> void:
|
||||
if searching:
|
||||
return
|
||||
set_searching_ui(true)
|
||||
MatchmakingChannel.send_search_state(true)
|
||||
|
||||
|
||||
func on_abort_pressed() -> void:
|
||||
if not searching:
|
||||
return
|
||||
set_searching_ui(false)
|
||||
MatchmakingChannel.send_search_state(false)
|
||||
|
||||
|
||||
func on_accept_pressed() -> void:
|
||||
set_accaptence_buttons_enabled(false)
|
||||
MatchmakingChannel.send_match_accepted(true, found_match.matchId)
|
||||
|
||||
|
||||
func on_decline_pressed() -> void:
|
||||
set_accaptence_buttons_enabled(false)
|
||||
MatchmakingChannel.send_match_accepted(false, found_match.matchId)
|
||||
|
||||
|
||||
#############################
|
||||
# UI Management #
|
||||
#############################
|
||||
|
||||
|
||||
func set_searching_ui(new_searching: bool) -> void:
|
||||
searching = new_searching
|
||||
search_button.visible = !new_searching
|
||||
abort_button.visible = new_searching
|
||||
|
||||
|
||||
func set_accaptence_buttons_enabled(enabled: bool) -> void:
|
||||
accept_button.disabled = !enabled
|
||||
decline_button.disabled = !enabled
|
||||
|
||||
|
||||
func set_match_accptance_ui(vissible: bool) -> void:
|
||||
popup.visible = vissible
|
|
@ -7,6 +7,7 @@ signal login_error(error: ApiError)
|
|||
@export var username_field: LineEdit
|
||||
@export var password_field: LineEdit
|
||||
@export var api_config: ApiConfig
|
||||
@export var next_view: Control
|
||||
var api: ServerApi
|
||||
|
||||
|
||||
|
@ -20,6 +21,9 @@ func _ready() -> void:
|
|||
if not api_config:
|
||||
push_error("No API Configuration provided")
|
||||
return
|
||||
if not next_view:
|
||||
push_error("No next view configured")
|
||||
return
|
||||
api = ServerApi.new(api_config)
|
||||
connect("pressed", login)
|
||||
username_field.connect("text_submitted", login_wrapper)
|
||||
|
@ -38,6 +42,8 @@ func login() -> void:
|
|||
|
||||
|
||||
func on_success(response: ApiResponse) -> void:
|
||||
ConnectionChannel.connect_to_channel(response.data.token)
|
||||
next_view.visible = true
|
||||
login_successful.emit(response.data)
|
||||
|
||||
|
9
scripts/ui/quit.gd
Normal file
9
scripts/ui/quit.gd
Normal file
|
@ -0,0 +1,9 @@
|
|||
extends Button
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
connect("pressed", on_pressed)
|
||||
|
||||
|
||||
func on_pressed() -> void:
|
||||
get_tree().quit()
|
14
scripts/ui/swap_menu.gd
Normal file
14
scripts/ui/swap_menu.gd
Normal file
|
@ -0,0 +1,14 @@
|
|||
extends Button
|
||||
|
||||
@export var menu: Control
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
connect("pressed", _on_Button_pressed)
|
||||
|
||||
|
||||
func _on_Button_pressed() -> void:
|
||||
if not menu:
|
||||
push_error("Menu to swap to not configgured")
|
||||
return
|
||||
menu.visible = true
|
|
@ -1,14 +0,0 @@
|
|||
extends Button
|
||||
|
||||
@export var scene_name: String
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
connect("pressed", _on_Button_pressed)
|
||||
|
||||
|
||||
func _on_Button_pressed() -> void:
|
||||
if not scene_name:
|
||||
push_error("Scene to switch to is not configured")
|
||||
return
|
||||
get_tree().change_scene_to_file("res://scenes/" + scene_name + ".tscn")
|
|
@ -1,50 +0,0 @@
|
|||
extends RichTextLabel
|
||||
|
||||
@export var login: Login
|
||||
@export var api_config: ApiConfig
|
||||
var api := ServerApi.new(api_config)
|
||||
|
||||
# docs.redotengine.org/en/stable/tutorials/networking/websocket.html
|
||||
var time_channel = WebSocketPeer.new()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
login.connect("login_successful", on_login)
|
||||
(
|
||||
ConnectionChannel
|
||||
. connect(
|
||||
"on_channel_token_received",
|
||||
on_channel_token_received,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
func on_login(session: PlayerLoginSession):
|
||||
ConnectionChannel.connect_to_channel(session.token)
|
||||
ConnectionChannel.request_channel_token(Message.Channels.TIME)
|
||||
|
||||
|
||||
func on_channel_token_received(msg: ProvidedConnectionTokenMessage) -> void:
|
||||
if time_channel.get_ready_state() != WebSocketPeer.STATE_CLOSED:
|
||||
return
|
||||
if msg.channel != Message.Channels.TIME:
|
||||
return
|
||||
time_channel.handshake_headers = PackedStringArray(
|
||||
["Authorization: " + msg.token],
|
||||
)
|
||||
time_channel.connect_to_url("ws://localhost:8080/ws/time")
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
time_channel.poll()
|
||||
var state = time_channel.get_ready_state()
|
||||
|
||||
if state != WebSocketPeer.STATE_OPEN:
|
||||
return
|
||||
while time_channel.get_available_packet_count():
|
||||
var msg: CurrentUnixTimeMessage = Message.deserialize(
|
||||
time_channel.get_packet().get_string_from_utf8(), [CurrentUnixTimeMessage]
|
||||
)
|
||||
if msg == null:
|
||||
continue
|
||||
self.text = str(msg.time)
|
Loading…
Add table
Reference in a new issue