Development Syncup: Working on the map testing.
This commit is contained in:
parent
c07c04e8f9
commit
1351ce3178
4 changed files with 45 additions and 0 deletions
3
scenes/maps/testmap.tscn
Normal file
3
scenes/maps/testmap.tscn
Normal file
|
@ -0,0 +1,3 @@
|
|||
[gd_scene format=3 uid="uid://cbyee7drds7qu"]
|
||||
|
||||
[node name="Testmap" type="Node3D"]
|
|
@ -18,3 +18,18 @@ anchor_right = 1.0
|
|||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="StartButton" type="Button" parent="."]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -96.0
|
||||
offset_top = -31.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
disabled = true
|
||||
text = "Start Game"
|
||||
|
|
|
@ -5,12 +5,23 @@ var label: PackedScene = preload("res://scenes/ui/elements/name_label.tscn")
|
|||
func _ready() -> void:
|
||||
if Networking.playerlist_changed.connect(_on_playerlist_changed) != OK:
|
||||
Log.error("FAILED to connect the playerlist_changed signal to _on_playerlist_changed!", "Internal Error: Failed to connect signal.")
|
||||
var start_button: Button = $StartButton
|
||||
if start_button.pressed.connect(_on_start_button_pressed) != OK:
|
||||
Log.error("FAILED to connect the pressed signal to _on_start_button_pressed!", "Internal Error: Failed to connect signal.")
|
||||
_on_playerlist_changed()
|
||||
|
||||
func _on_playerlist_changed() -> void:
|
||||
if Networking.isManager:
|
||||
var start_button: Button = $StartButton
|
||||
start_button.show()
|
||||
start_button.disabled = false
|
||||
for child: Label in $NameContainer.get_children():
|
||||
child.free()
|
||||
for peer: String in Networking.peers:
|
||||
var instance: Label = label.instantiate()
|
||||
instance.text = peer
|
||||
$NameContainer.add_child(instance)
|
||||
|
||||
|
||||
func _on_start_button_pressed() -> void:
|
||||
Networking.send_rpcs("start_game", ["hello", " world"])
|
||||
|
|
|
@ -236,3 +236,19 @@ func send_playerlist(status: int, newPeers: Dictionary) -> void:
|
|||
Log.warning("Name %s is already taken in the room!" % Game.username)
|
||||
3:
|
||||
Log.warning("Sent a playerlist request to a regular peer, not the host!")
|
||||
|
||||
## General Game RPCs
|
||||
|
||||
# Does RPCs to all clients.
|
||||
func send_rpcs(method: String, args: Array) -> void:
|
||||
for peer: String in peers:
|
||||
var id: int = peers[peer]
|
||||
if rpc_id(id, method, args) != OK:
|
||||
Log.warning("Failed to send the rpc %s to %d." % [method, id])
|
||||
|
||||
# Starts the game.
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func start_game() -> void:
|
||||
if multiplayer.get_remote_sender_id() == managerID:
|
||||
if !get_tree().change_scene_to_file("res://scenes/maps/testmap.tscn"):
|
||||
Log.warning("Couldn't load the map!")
|
||||
|
|
Loading…
Reference in a new issue