finally add player name displaying
This commit is contained in:
parent
25a3b67cd2
commit
9aa67cf490
@ -1,5 +1,6 @@
|
||||
extends Node
|
||||
|
||||
signal player_registered(peer_id: int, player_info: Dictionary)
|
||||
signal network_error(message: String)
|
||||
|
||||
const DEFAULT_PORT: int = 10567
|
||||
@ -55,7 +56,8 @@ func host_game(dedicated: bool = false) -> void:
|
||||
|
||||
if not dedicated:
|
||||
players[1] = _local_player_info
|
||||
_add_player(multiplayer.get_unique_id())
|
||||
print("Registered player ", 1, " ", _local_player_info)
|
||||
_add_player(multiplayer.get_unique_id(), _local_player_info)
|
||||
|
||||
|
||||
func join_game(address: String) -> void:
|
||||
@ -101,7 +103,7 @@ func _load_main() -> void:
|
||||
_switch_scene($/root/Title, _main_scene)
|
||||
|
||||
|
||||
func _add_player(peer_id: int) -> void:
|
||||
func _add_player(peer_id: int, player_info: Dictionary) -> void:
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
|
||||
@ -110,6 +112,7 @@ func _add_player(peer_id: int) -> void:
|
||||
player.name = str(peer_id)
|
||||
|
||||
Referencer.main.player_holder.add_child(player, true)
|
||||
player.set_info(player_info)
|
||||
|
||||
|
||||
func _remove_player(peer_id: int) -> void:
|
||||
@ -130,12 +133,13 @@ func _register_player(player_info: Dictionary) -> void:
|
||||
print("Skipping registering the host")
|
||||
return
|
||||
players[peer_id] = player_info
|
||||
player_registered.emit(peer_id, player_info)
|
||||
|
||||
|
||||
func _on_multiplayer_peer_connected(peer_id: int) -> void:
|
||||
print("Peer connected ", peer_id)
|
||||
_register_player.rpc_id(peer_id, _local_player_info)
|
||||
_add_player(peer_id)
|
||||
_add_player(peer_id, _local_player_info)
|
||||
|
||||
|
||||
func _on_multiplayer_peer_disconnected(peer_id: int) -> void:
|
||||
@ -148,6 +152,7 @@ func _on_multiplayer_connected_to_server() -> void:
|
||||
var peer_id := multiplayer.get_unique_id()
|
||||
print("Connected to server as ", peer_id)
|
||||
players[peer_id] = _local_player_info
|
||||
print("Registered player ", peer_id, " ", _local_player_info)
|
||||
|
||||
|
||||
func _on_multiplayer_connection_failed() -> void:
|
||||
|
||||
@ -33,7 +33,7 @@ func _enter_tree() -> void:
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_name_label.text = str(name)
|
||||
Networker.player_registered.connect(_on_networker_player_registered)
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
@ -90,6 +90,10 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
_handle_mouse_rotating(event as InputEventMouseMotion)
|
||||
|
||||
|
||||
func set_info(player_info: Dictionary) -> void:
|
||||
_name_label.text = player_info["name"]
|
||||
|
||||
|
||||
func _process_respawning() -> void:
|
||||
if global_position.y < _respawn_height:
|
||||
global_position = _respawn_point
|
||||
@ -204,3 +208,9 @@ func _handle_mouse_rotating(event: InputEventMouseMotion) -> void:
|
||||
)
|
||||
)
|
||||
_camera.rotation.x = clamp(_camera.rotation.x, -PI / 2, PI / 2)
|
||||
|
||||
|
||||
func _on_networker_player_registered(peer_id: int, player_info: Dictionary) -> void:
|
||||
if peer_id != _peer_id:
|
||||
return
|
||||
set_info(player_info)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user