Align patterns better around what UI components are. Move script related controllers to scripts folder
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://dy51wny4x53f4"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dbnl4tjahkoun" path="res://scenes/data/game_data.gd" id="1_l6w8l"]
|
||||
[ext_resource type="Script" uid="uid://65x4bq2wsh8k" path="res://scenes/data/game_state.gd" id="2_6ash1"]
|
||||
[ext_resource type="Script" uid="uid://dyq4p5e06ib14" path="res://scenes/data/lobby_data.gd" id="3_l6w8l"]
|
||||
[ext_resource type="Script" uid="uid://uyimqfjmuc34" path="res://scenes/data/multiplayer_data.gd" id="4_gcm58"]
|
||||
|
||||
[node name="data_bridge" type="Node"]
|
||||
|
||||
[node name="game_data" type="Node" parent="."]
|
||||
script = ExtResource("1_l6w8l")
|
||||
|
||||
[node name="game_state" type="Node" parent="."]
|
||||
script = ExtResource("2_6ash1")
|
||||
|
||||
[node name="lobby_data" type="Node" parent="."]
|
||||
script = ExtResource("3_l6w8l")
|
||||
|
||||
[node name="multiplayer_data" type="Node" parent="."]
|
||||
script = ExtResource("4_gcm58")
|
||||
@@ -1,18 +0,0 @@
|
||||
class_name GameData extends Node
|
||||
|
||||
|
||||
var game_address: String = "0.0.0.0"
|
||||
var game_port: int = 8080
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
Globals.game_data = self
|
||||
|
||||
|
||||
@rpc("authority", "reliable")
|
||||
func set_game_address(_address: String) -> void:
|
||||
pass
|
||||
|
||||
@rpc("authority", "reliable")
|
||||
func set_game_port(_port: String) -> void:
|
||||
pass
|
||||
@@ -1 +0,0 @@
|
||||
uid://dbnl4tjahkoun
|
||||
@@ -1,24 +0,0 @@
|
||||
class_name GameState extends Node
|
||||
|
||||
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
Globals.game_state = self
|
||||
|
||||
|
||||
func set_game_scene(scene_str: String) -> void:
|
||||
var scene = load(scene_str).instantiate()
|
||||
var target = get_tree().root.find_child("scene", true, false)
|
||||
|
||||
scene.name = "lobby_screen"
|
||||
|
||||
clear_game_scene(target)
|
||||
|
||||
target.add_child(scene)
|
||||
|
||||
func clear_game_scene(container: Node) -> void:
|
||||
for child in container.get_children():
|
||||
child.queue_free()
|
||||
|
||||
await get_tree().process_frame
|
||||
@@ -1 +0,0 @@
|
||||
uid://65x4bq2wsh8k
|
||||
@@ -1,165 +0,0 @@
|
||||
class_name LobbyData extends Node
|
||||
|
||||
|
||||
var uuid = null
|
||||
var IS_VALID_CHARS_REGEX: RegEx = RegEx.create_from_string("^[a-zA-Z0-9]+$")
|
||||
|
||||
const MATCH_TYPES: Array = ["8ball", "9ball", "snooker", "freeball"]
|
||||
const CLIENT_DICT: Dictionary = {
|
||||
"id": "",
|
||||
"partner_id": "",
|
||||
"in_match": false,
|
||||
"match_id": ""
|
||||
}
|
||||
const MATCH_POOL_ENTRY: Dictionary = {
|
||||
"player1": "",
|
||||
"player2": "",
|
||||
"data": {}
|
||||
}
|
||||
|
||||
var active_match_pool: Dictionary = {}
|
||||
var match_pool: Dictionary = {}
|
||||
var client_pool: Dictionary = {}
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
Globals.lobby_data = self
|
||||
|
||||
uuid = load('res://addons/uuid/uuid.gd')
|
||||
|
||||
|
||||
func _delete_from_match_pool(match_id: String) -> Dictionary:
|
||||
if not match_pool.has(match_id): return {}
|
||||
|
||||
var to_delete: Dictionary = match_pool[match_id].data
|
||||
match_pool.erase(match_id)
|
||||
|
||||
return to_delete
|
||||
|
||||
func _launch_game_server(
|
||||
match_entry: Dictionary,
|
||||
client1: Dictionary,
|
||||
client2: Dictionary
|
||||
) -> void:
|
||||
var port: String = InstanceLauncher.launch_game_server(match_entry.data)
|
||||
if port == "-1":
|
||||
# TODO: Alert clients that the game wont be created due to
|
||||
# server reaching number of allowed instances.
|
||||
return
|
||||
|
||||
# TODO: Set address dynamically; I.E. if game on different server than lobby.
|
||||
# As is, clients use the lobby address since games launch on new ports.
|
||||
# Will have to change how we watch game server death if on diff server.
|
||||
#Globals.game_data.rpc_id(client1.id, "set_game_address", "51.222.85.126")
|
||||
#Globals.game_data.rpc_id(client2.id, "set_game_address", "51.222.85.126")
|
||||
|
||||
Globals.game_data.rpc_id(client1.id, "set_game_port", port)
|
||||
Globals.game_data.rpc_id(client2.id, "set_game_port", port)
|
||||
|
||||
rpc_id(client1.id, "connect_to_game")
|
||||
rpc_id(client2.id, "connect_to_game")
|
||||
|
||||
func match_list_add_entry(match_entry: Dictionary) -> void:
|
||||
var client1 = client_pool.get( multiplayer.get_remote_sender_id() )
|
||||
if not client1: return
|
||||
|
||||
if not client1.match_id.is_empty(): return
|
||||
if match_entry.name.length() < 1 or match_entry.name.length() > 12: return
|
||||
if not IS_VALID_CHARS_REGEX.search(match_entry.name): return
|
||||
if not match_entry.type in MATCH_TYPES: return
|
||||
|
||||
match_entry["match_id"] = uuid.v4()
|
||||
match_pool[match_entry.match_id] = MATCH_POOL_ENTRY.duplicate_deep()
|
||||
match_pool[match_entry.match_id].player1 = client1.id
|
||||
match_pool[match_entry.match_id].data = match_entry
|
||||
client1.match_id = match_entry.match_id
|
||||
|
||||
func match_list_remove_entry(match_id: String) -> void:
|
||||
var client1 = client_pool.get( multiplayer.get_remote_sender_id() )
|
||||
if not client1: return
|
||||
if not client1.match_id == match_id: return
|
||||
|
||||
client1.match_id = ""
|
||||
|
||||
_delete_from_match_pool(match_id)
|
||||
|
||||
func match_list_join_entry(match_id: String) -> void:
|
||||
if active_match_pool.has(match_id):
|
||||
push_error("Client Joining Match List Entry Failed. Already consumed. ", match_id)
|
||||
|
||||
# TODO: Need to signal to prospective client that match has been taken.
|
||||
# Server is in the midst of cleanup for it once clients disconnect
|
||||
# to join generated game server...
|
||||
return
|
||||
|
||||
var match_entry = match_pool.get(match_id)
|
||||
if not match_entry: return
|
||||
|
||||
var client1 = client_pool.get( match_entry.player1 )
|
||||
var client2 = client_pool.get( multiplayer.get_remote_sender_id() )
|
||||
|
||||
if not client1: return
|
||||
if not client2: return
|
||||
|
||||
match_entry.player2 = client2.id
|
||||
|
||||
client1.in_match = true
|
||||
client1.partner_id = client2.id
|
||||
|
||||
client2.match_id = match_id
|
||||
client2.in_match = true
|
||||
client2.partner_id = client1.id
|
||||
|
||||
active_match_pool[match_id] = match_entry
|
||||
# NOTE: Cleanup of match info and client info
|
||||
# will/should happen on their disconnect...
|
||||
|
||||
# TODO: Need to look into moving this out of here.
|
||||
# Maybe just have clients drop and internally call on their own?
|
||||
# Maybe just check here if we can even launch the game server?
|
||||
_launch_game_server(match_entry, client1, client2)
|
||||
|
||||
func server_client_connected(id: int) -> void:
|
||||
push_warning("Client Connected... ID: ", id)
|
||||
|
||||
client_pool[id] = CLIENT_DICT.duplicate_deep()
|
||||
client_pool[id].id = id
|
||||
|
||||
var matches: Array = []
|
||||
for match_entry in match_pool.values():
|
||||
matches.append(match_entry.data)
|
||||
|
||||
MessageBus.emit_propagation_clients_only.rpc_id(
|
||||
id, "receive_match_list", matches
|
||||
)
|
||||
|
||||
func server_client_disconnected(id: int) -> void:
|
||||
push_warning("Client Disconnected... ID: ", id)
|
||||
|
||||
var client1 = client_pool.get(id)
|
||||
if not client1: return
|
||||
|
||||
var match_entry = _delete_from_match_pool(client1.match_id)
|
||||
if not match_entry: return
|
||||
|
||||
push_warning("Removing Match... Match: ", match_entry)
|
||||
|
||||
MessageBus.emit_local(
|
||||
"match_list_remove_entry", match_entry.match_id
|
||||
)
|
||||
|
||||
MessageBus.emit_propagation_clients_only.rpc(
|
||||
"match_list_remove_entry", match_entry.match_id
|
||||
)
|
||||
|
||||
client_pool.erase(client1.id)
|
||||
|
||||
|
||||
# NOTE: Needed for hash check to pass between client and server but isn't used by server...
|
||||
@rpc("authority", "reliable")
|
||||
func connect_to_game() -> void:
|
||||
pass
|
||||
|
||||
@rpc("authority", "reliable")
|
||||
func go_back_to_match_screen() -> void:
|
||||
pass
|
||||
@@ -1 +0,0 @@
|
||||
uid://dyq4p5e06ib14
|
||||
@@ -1,10 +0,0 @@
|
||||
class_name MultiplayerData extends Node
|
||||
|
||||
|
||||
@rpc("authority", "reliable")
|
||||
func set_multiplayer_active() -> void:
|
||||
pass
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func set_active_player_id(_id: int) -> void:
|
||||
pass
|
||||
@@ -1 +0,0 @@
|
||||
uid://uyimqfjmuc34
|
||||
@@ -1,13 +1,13 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dkes5cdu45q6e"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dk7afnf7ol7dy" path="res://scenes/screens/lobby_screen/lobby.gd" id="1_hhiik"]
|
||||
[ext_resource type="PackedScene" uid="uid://rb6av5eg4u0" path="res://scenes/ui_controls/lobby/ui.tscn" id="2_lqt48"]
|
||||
[ext_resource type="PackedScene" uid="uid://rb6av5eg4u0" path="res://scenes/ui/lobby/lobby_ui.tscn" id="2_lqt48"]
|
||||
[ext_resource type="Script" uid="uid://crbm3v4td6du6" path="res://scenes/screens/lobby_screen/lobby_server.gd" id="4_glu7g"]
|
||||
|
||||
[node name="lobby" type="Node"]
|
||||
script = ExtResource("1_hhiik")
|
||||
|
||||
[node name="ui" parent="." instance=ExtResource("2_lqt48")]
|
||||
[node name="lobby_ui" parent="." instance=ExtResource("2_lqt48")]
|
||||
theme_override_constants/margin_left = 10
|
||||
theme_override_constants/margin_top = 10
|
||||
theme_override_constants/margin_right = 10
|
||||
@@ -16,8 +16,8 @@ theme_override_constants/margin_bottom = 10
|
||||
[node name="server" type="Node" parent="."]
|
||||
script = ExtResource("4_glu7g")
|
||||
|
||||
[connection signal="pressed" from="ui/body/left_body/server_host_hbox/host_start_bttn" to="." method="_on_host_start_bttn_pressed"]
|
||||
[connection signal="pressed" from="ui/body/left_body/server_host_hbox/host_stop_bttn" to="." method="_on_host_stop_bttn_pressed"]
|
||||
[connection signal="pressed" from="ui/body/left_body/search_vbox/search_hbox/match_search_bttn" to="." method="_on_match_search_bttn_pressed"]
|
||||
[connection signal="pressed" from="lobby_ui/body/left_body/server_host_hbox/host_start_bttn" to="." method="_on_host_start_bttn_pressed"]
|
||||
[connection signal="pressed" from="lobby_ui/body/left_body/server_host_hbox/host_stop_bttn" to="." method="_on_host_stop_bttn_pressed"]
|
||||
[connection signal="pressed" from="lobby_ui/body/left_body/search_vbox/search_hbox/match_search_bttn" to="." method="_on_match_search_bttn_pressed"]
|
||||
|
||||
[editable path="ui"]
|
||||
[editable path="lobby_ui"]
|
||||
|
||||
@@ -3,14 +3,14 @@ class_name LobbyBase extends Node
|
||||
|
||||
const MATCH_ENTRY = preload("res://scenes/screens/lobby_screen/match_entry.tscn")
|
||||
|
||||
@onready var host_start_bttn: Button = $ui/body/left_body/server_host_hbox/host_start_bttn
|
||||
@onready var host_stop_bttn: Button = $ui/body/left_body/server_host_hbox/host_stop_bttn
|
||||
@onready var host_address_input: LineEdit = $ui/body/left_body/server_host_hbox/host_address_input
|
||||
@onready var host_port_range: SpinBox = $ui/body/left_body/server_host_hbox/host_port_range
|
||||
@onready var host_start_bttn: Button = $lobby_ui/body/left_body/server_host_hbox/host_start_bttn
|
||||
@onready var host_stop_bttn: Button = $lobby_ui/body/left_body/server_host_hbox/host_stop_bttn
|
||||
@onready var host_address_input: LineEdit = $lobby_ui/body/left_body/server_host_hbox/host_address_input
|
||||
@onready var host_port_range: SpinBox = $lobby_ui/body/left_body/server_host_hbox/host_port_range
|
||||
|
||||
@onready var search_vbox: VBoxContainer = $ui/body/left_body/search_vbox
|
||||
@onready var match_search_input: LineEdit = $ui/body/left_body/search_vbox/search_hbox/match_search_input
|
||||
@onready var match_list: VBoxContainer = $ui/body/left_body/search_vbox/scroll_container/match_list
|
||||
@onready var search_vbox: VBoxContainer = $lobby_ui/body/left_body/search_vbox
|
||||
@onready var match_search_input: LineEdit = $lobby_ui/body/left_body/search_vbox/search_hbox/match_search_input
|
||||
@onready var match_list: VBoxContainer = $lobby_ui/body/left_body/search_vbox/scroll_container/match_list
|
||||
|
||||
@onready var server: Node = $server
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ corner_radius_top_right = 3
|
||||
corner_radius_bottom_right = 3
|
||||
corner_radius_bottom_left = 3
|
||||
|
||||
[node name="margin" type="MarginContainer"]
|
||||
[node name="lobby_ui" type="MarginContainer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
Reference in New Issue
Block a user