WIP: Make it possible to change server address

This commit is contained in:
Nikolai Rodionov 2025-01-26 19:19:36 +01:00
parent e28845b688
commit d2b89c9d5c
Signed by: allanger
GPG Key ID: 09F8B434D0FDD99B
3 changed files with 11 additions and 3 deletions

View File

@ -35,6 +35,12 @@ offset_right = 224.0
offset_bottom = 220.0
text = "Join"
[node name="TextEdit" type="TextEdit" parent="."]
layout_mode = 0
offset_right = 8.0
offset_bottom = 8.0
text = "127.0.0.1"
[connection signal="player_connected" from="." to="." method="_on_player_connected"]
[connection signal="player_disconnected" from="." to="." method="_on_player_disconnected"]
[connection signal="server_disconnected" from="." to="." method="_on_server_disconnected"]

View File

@ -10,7 +10,7 @@ signal server_disconnected
const PORT = 7000
const DEFAULT_SERVER_IP = "127.0.0.1" # IPv4 localhost
const MAX_CONNECTIONS = 20
@onready var address_input: TextEdit = $TextEdit
var players = {}
var my_random_number = RandomNumberGenerator.new().randf_range(-2.0, 2.0)
var player_info = {"name": str(my_random_number)}
@ -25,8 +25,7 @@ func _ready() -> void:
multiplayer.server_disconnected.connect(_on_server_disconnected)
func join_game(address = ""):
if address.is_empty():
address = DEFAULT_SERVER_IP
address = address_input.text
var peer = ENetMultiplayerPeer.new()
var error = peer.create_client(address, PORT)
if error:

View File

@ -37,6 +37,9 @@ properties/0/replication_mode = 1
properties/1/path = NodePath(".:rotation")
properties/1/spawn = true
properties/1/replication_mode = 1
properties/2/path = NodePath(".:rotation_order")
properties/2/spawn = true
properties/2/replication_mode = 1
[node name="Bullet" type="Node3D"]
transform = Transform3D(20, 0, 0, 0, 20, 0, 0, 0, 20, 0, 0, 0)