feat: added game sinhronizer

pull/10/head
Евгений Сугоняко 2024-05-15 19:11:10 +03:00
parent 93ada0cce9
commit e05ded74a9
7 changed files with 145 additions and 16 deletions

View File

@ -11,11 +11,13 @@ func _ready():
func send_message(_message):
self.rpc_id(1, "rpc_send_message", GATEWAY.clientId, _message)
if GATEWAY.debug:
print("Send new message")
#---------------------------------------------------------------------------------------------------
# RPC Client
@rpc("any_peer")
@rpc("any_peer", "call_local", "unreliable", 9)
func rpc_add_message(_name, _message):
GlobalChat.append_text("# ")
GlobalChat.push_color(Color.DARK_ORANGE)
@ -24,9 +26,11 @@ func rpc_add_message(_name, _message):
GlobalChat.append_text(" : ")
GlobalChat.append_text(_message)
GlobalChat.newline()
if GATEWAY.debug:
print("Get new message")
#---------------------------------------------------------------------------------------------------
# RPC Server
@rpc("any_peer", "call_local")
@rpc("any_peer", "call_local", "unreliable", 9)
func rpc_send_message(_client_id, _message): pass

View File

@ -0,0 +1,38 @@
extends Label
var gameId : int
var ownerName : String
var gameName : String
var players : Array
var maxPlayers : int
var gamePassword : String
func connect_player(_client_id):
if players.size() < maxPlayers:
players.push_back(_client_id)
func set_game_data(_data:Dictionary):
self.gameId = _data.gameId
self.ownerName = _data.ownerName
self.gameName = _data.gameName
self.maxPlayers = _data.maxPlayers
self.gamePassword = _data.gamePassword
self.name = str(_data.gameId)
self.text = "%s | %s | %s | " % [_data.gameName, _data.ownerName, _data.maxPlayers]
if _data.gamePassword != "":
self.text += "PASSWORD"
else:
self.text += "OPEN"
func get_game_data() -> Dictionary:
return {
gameId = self.gameId,
ownerName = self.ownerName,
gameName = self.gameName,
maxPlayers = self.maxPlayers,
gamePassword = self.gamePassword
}

View File

@ -0,0 +1,21 @@
[gd_scene load_steps=4 format=3 uid="uid://cm70f77uynyoa"]
[ext_resource type="FontFile" uid="uid://dhvfket83gjln" path="res://data/styles/fonts/Roboto-Regular.ttf" id="1_o6j5i"]
[ext_resource type="Script" path="res://data/scenes/lobbies/GameLabel.gd" id="2_uhffe"]
[sub_resource type="Theme" id="Theme_4x7tq"]
default_font = ExtResource("1_o6j5i")
default_font_size = 16
Label/constants/line_spacing = 3
Label/constants/outline_size = 0
Label/constants/shadow_offset_x = 1
Label/constants/shadow_offset_y = 1
Label/constants/shadow_outline_size = 1
Label/font_sizes/font_size = 16
[node name="Label" type="Label"]
mouse_filter = 1
mouse_default_cursor_shape = 2
theme = SubResource("Theme_4x7tq")
text = "Game number 1"
script = ExtResource("2_uhffe")

View File

@ -0,0 +1,53 @@
extends Node
@export var GameBox : VBoxContainer
func _ready():
rpc_id(1, "rpc_get_games_list")
func create_game(_gameData:Dictionary):
rpc_id(1, "rpc_create_game", _gameData)
#---------------------------------------------------------------------------------------------------
# RPC Client
@rpc("authority", "call_local", "unreliable", 2)
func rpc_set_games_list(_games:Array):
for game in _games:
var gameLabel = preload("res://data/scenes/lobbies/GameLabel.tscn").instantiate()
gameLabel.set_game_data(game)
GameBox.add_child(gameLabel)
if GATEWAY.debug:
print("Get games list")
@rpc("authority", "call_local", "unreliable", 2)
func rpc_add_game_to_games_list(_game:Dictionary):
var gameLabel = preload("res://data/scenes/lobbies/GameLabel.tscn").instantiate()
gameLabel.set_game_data(_game)
GameBox.add_child(gameLabel)
if GATEWAY.debug:
print("Added game to games list")
@rpc("authority", "call_local", "unreliable", 2)
func rpc_cant_create_game():
if GATEWAY.debug:
print("Can`t create game")
#---------------------------------------------------------------------------------------------------
# RPC Server
@rpc("any_peer", "call_local", "unreliable", 2)
func rpc_create_game(_client_id:int, _gameData:Dictionary): pass
@rpc("any_peer", "call_local", "unreliable", 2)
func rpc_get_games_list(): pass
@rpc("any_peer", "call_local", "unreliable", 2)
func rpc_get_game(_name): pass

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=5 format=3 uid="uid://d4nhi3k0agm2q"]
[gd_scene load_steps=6 format=3 uid="uid://d4nhi3k0agm2q"]
[ext_resource type="FontFile" uid="uid://dhvfket83gjln" path="res://data/styles/fonts/Roboto-Regular.ttf" id="1_qbt18"]
[ext_resource type="Script" path="res://data/scenes/ChatSinhronizer.gd" id="2_cc8va"]
[ext_resource type="Script" path="res://data/scenes/lobbies/GamesSinhronizer.gd" id="2_a6k32"]
[ext_resource type="Script" path="res://data/scenes/lobbies/ChatSinhronizer.gd" id="2_cc8va"]
[sub_resource type="GDScript" id="GDScript_2o8xy"]
script/source = "extends LineEdit
@ -39,6 +40,10 @@ func _server_disconnect():
script = ExtResource("2_cc8va")
GlobalChat = NodePath("../LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer/Panel/GlobalChat")
[node name="GamesSinhronizer" type="Node" parent="." node_paths=PackedStringArray("GameBox")]
script = ExtResource("2_a6k32")
GameBox = NodePath("../LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/GamesScroll/GamesBox")
[node name="LobbieUI" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
@ -107,23 +112,21 @@ text = "$Games"
horizontal_alignment = 1
vertical_alignment = 1
[node name="GameSearch" type="LineEdit" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer"]
layout_mode = 2
placeholder_text = "$search_game"
[node name="GamesScroll" type="ScrollContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer"]
layout_mode = 2
size_flags_vertical = 3
horizontal_scroll_mode = 0
vertical_scroll_mode = 2
[node name="Games" type="VBoxContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/GamesScroll"]
[node name="GamesBox" type="VBoxContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/GamesScroll"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_constants/separation = 10
[node name="Label" type="Label" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/GamesScroll/Games"]
layout_mode = 2
theme_override_fonts/font = ExtResource("1_qbt18")
theme_override_font_sizes/font_size = 15
text = "Game number 1"
[node name="GlobalChatBackground" type="ColorRect" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer"]
layout_mode = 2
size_flags_horizontal = 3
@ -183,13 +186,21 @@ caret_blink = true
script = SubResource("GDScript_2o8xy")
ChatSinhronizer = NodePath("../../../../../../../../ChatSinhronizer")
[node name="Back" type="Button" parent="LobbieUI/MainMarginContainer/MainUIContainer"]
[node name="ButtonsContainer" type="HBoxContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer"]
layout_mode = 2
size_flags_horizontal = 8
[node name="CreateGame" type="Button" parent="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer"]
layout_mode = 2
size_flags_horizontal = 2
text = "$CreateGame"
[node name="Back" type="Button" parent="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer"]
layout_mode = 2
size_flags_horizontal = 10
size_flags_vertical = 8
theme_override_fonts/font = ExtResource("1_qbt18")
theme_override_font_sizes/font_size = 15
text = "$Back"
script = SubResource("GDScript_4mwjp")
[connection signal="button_up" from="LobbieUI/MainMarginContainer/MainUIContainer/Back" to="LobbieUI/MainMarginContainer/MainUIContainer/Back" method="_on_button_up"]
[connection signal="button_up" from="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer/Back" to="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer/Back" method="_on_button_up"]

View File

@ -131,4 +131,4 @@ func _on_registration_ok():
#--------------------------------------------------------------------------------------------------#
# Functions
func start_lobbies():
get_tree().change_scene_to_packed(load("res://data/scenes/Lobbies.tscn"))
get_tree().change_scene_to_packed(load("res://data/scenes/lobbies/Lobbies.tscn"))

View File

@ -22,3 +22,5 @@ $Registrate_on_Cashflow_World,Registrate on Cashflow World,Реєстрація
$Games,Games,Ігри,Игры
$GlobalChat,Global chat,Глобальний чат,Общий чат
$your_message,Your message here (Enter),Ваше повідомлення (Enter),Ваше сообщение (Enter)
$CreateGame,Create game,Створити гру,Создать игру
$search_game,Searched game name (Enter),Ім`я гри для пошуку (Enter),Название игры для поиска (Enter)

1 KEYS en uk ru
22 $Games Games Ігри Игры
23 $GlobalChat Global chat Глобальний чат Общий чат
24 $your_message Your message here (Enter) Ваше повідомлення (Enter) Ваше сообщение (Enter) Ваше сообщение (Enter)
25 $CreateGame Create game Створити гру Создать игру
26 $search_game Searched game name (Enter) Ім`я гри для пошуку (Enter) Название игры для поиска (Enter)