Client changes and tweaks
This commit is contained in:
@ -17,28 +17,19 @@ func _on_world_update():
|
||||
var tile_data = tileUpdate.split(',')
|
||||
if ':' in tile_data[2]:
|
||||
var pos : Vector2 = $Tiles.map_to_world(Vector2(int(tile_data[0]), int(tile_data[1])))
|
||||
if 'player:' in tile_data[2]:
|
||||
print(tile_data)
|
||||
var player_name = tile_data[2].substr(len('player:'))
|
||||
print(player_name)
|
||||
if $"/root/NetworkManager".username == player_name:
|
||||
$Player.position = pos
|
||||
else:
|
||||
update_entity(player_name, pos, "player")
|
||||
else:
|
||||
var entity_data = tile_data[2].split(':')
|
||||
update_entity(entity_data[1], pos, entity_data[0])
|
||||
var entity_data = tile_data[2].split(':')
|
||||
update_entity(entity_data[1], pos, entity_data[0])
|
||||
|
||||
else:
|
||||
$Tiles.set_cell(int(tile_data[0]), int(tile_data[1]), int(tile_data[2]))
|
||||
if $Loading != null:
|
||||
if get_node_or_null("Loading") != null:
|
||||
$Loading.queue_free()
|
||||
|
||||
func display_error(error):
|
||||
print("Error " + error)
|
||||
|
||||
func update_entity(entity_id : String, pos : Vector2, type : String):
|
||||
var entity : Node2D = get_node_or_null( str(type + "-" + entity_id))
|
||||
var entity : Node2D = get_node_or_null( str(type + "-" + entity_id))
|
||||
if not entity:
|
||||
var entity_location = "res://nodes/entities/" + type + ".tscn"
|
||||
if File.new().file_exists(entity_location):
|
||||
@ -46,6 +37,9 @@ func update_entity(entity_id : String, pos : Vector2, type : String):
|
||||
entity = gobj.instance()
|
||||
add_child(entity, true)
|
||||
entity.set_name(str(type + "-" + entity_id))
|
||||
if type == "player":
|
||||
if entity_id == $"/root/NetworkManager".username:
|
||||
entity.set_main()
|
||||
else:
|
||||
display_error("Trying to load entity of type: " + type + ", but failed.")
|
||||
if entity:
|
||||
|
37
client/scripts/systems/chatbox.gd
Normal file
37
client/scripts/systems/chatbox.gd
Normal file
@ -0,0 +1,37 @@
|
||||
extends Control
|
||||
|
||||
const MESSAGE_TIMEOUT : int = 17
|
||||
|
||||
var locking = false
|
||||
|
||||
func _ready():
|
||||
$"/root/NetworkManager".connect("chat_message_recieved", self, "_on_new_message")
|
||||
|
||||
func _on_new_message(message):
|
||||
print(message)
|
||||
var message_block : Label = Label.new()
|
||||
message_block.text = message
|
||||
var timer = Timer.new()
|
||||
timer.connect("timeout", message_block, "queue_free")
|
||||
message_block.add_child(timer)
|
||||
$Messages.add_child(message_block)
|
||||
timer.start(MESSAGE_TIMEOUT)
|
||||
|
||||
func _process(delta):
|
||||
|
||||
if $LineEdit.has_focus() != locking:
|
||||
locking = $LineEdit.has_focus()
|
||||
if locking:
|
||||
$"/root/ImportantEntities".main_player.lock_input()
|
||||
else:
|
||||
$"/root/ImportantEntities".main_player.unlock_input()
|
||||
|
||||
|
||||
if(Input.is_action_just_pressed("send_chat_message")):
|
||||
if $LineEdit.has_focus():
|
||||
if len($LineEdit.text) > 0:
|
||||
$"/root/NetworkManager".send_chat_message($LineEdit.text)
|
||||
$LineEdit.text = ""
|
||||
$LineEdit.release_focus()
|
||||
else:
|
||||
$LineEdit.grab_focus()
|
Reference in New Issue
Block a user