From ee233c52f027d03f5f9d2311f103e662740a34cd Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Sat, 2 May 2020 16:36:51 -0400 Subject: [PATCH] Added client nameplates --- client/scripts/entities/Player.gd | 6 +++++- client/scripts/network/NetworkManager.gd | 3 ++- client/scripts/systems/WorldManager.gd | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/client/scripts/entities/Player.gd b/client/scripts/entities/Player.gd index 933fede..280df2e 100644 --- a/client/scripts/entities/Player.gd +++ b/client/scripts/entities/Player.gd @@ -3,8 +3,12 @@ extends KinematicBody2D export var user : String = "" func _ready(): + set_username("") + +func set_username(username): + print(username) + user = username $Label.text = user - #$Label.text = $"/root/NetworkManager".username func _process(delta): var movePos : Vector2 = Vector2(0,0) diff --git a/client/scripts/network/NetworkManager.gd b/client/scripts/network/NetworkManager.gd index 8da0127..9853044 100644 --- a/client/scripts/network/NetworkManager.gd +++ b/client/scripts/network/NetworkManager.gd @@ -34,7 +34,8 @@ func _init(): client.bind() func connect_to_server(): - + if peer: + peer.disconnect_now() server_address.set_host(server_host) server_address.set_port(SERVER_PORT) peer = client.host_connect(server_address) diff --git a/client/scripts/systems/WorldManager.gd b/client/scripts/systems/WorldManager.gd index 05569ed..16605a0 100644 --- a/client/scripts/systems/WorldManager.gd +++ b/client/scripts/systems/WorldManager.gd @@ -50,6 +50,8 @@ func update_entity(entity_id : String, pos : Vector2, type : String): display_error("Trying to load entity of type: " + type + ", but failed.") if entity: entity.position = pos + if entity.has_method("set_username"): + entity.set_username(entity_id) func delete_entity(entity_id : String, type : String): var entity : Node2D = get_node_or_null( str(type + "-" + entity_id))