diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2015-12-09 08:38:23 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2015-12-09 08:38:23 +0100 |
commit | 8639cecf4cedd56452b47503be19c44b304cd02f (patch) | |
tree | e2a795da15e40c7d9d5b82e33378f8dbf0eaf67a /demos/misc/udp_chat | |
parent | efbb834936fdc9da9789ad37c9cc61e0b90cda95 (diff) |
Improve code formatting and update to 2.0
The scripts were streamlined using more or less the following conventions:
- space after a comma in lists of arguments
- space around weak operators (+, -), no space around strong operators (*, /)
- space after a comment start (#)
- removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now)
- function blocks separate by two newlines
The scene files were resaved with the (current) 2.0 format, and some scenes that were in XML format were converted to SCN, to be consistent across all demos.
Diffstat (limited to 'demos/misc/udp_chat')
-rw-r--r-- | demos/misc/udp_chat/chat.gd | 45 | ||||
-rw-r--r-- | demos/misc/udp_chat/chat.scn | bin | 3198 -> 3359 bytes |
2 files changed, 20 insertions, 25 deletions
diff --git a/demos/misc/udp_chat/chat.gd b/demos/misc/udp_chat/chat.gd index 3270eebbfe..a2d52bf126 100644 --- a/demos/misc/udp_chat/chat.gd +++ b/demos/misc/udp_chat/chat.gd @@ -1,72 +1,67 @@ extends Panel -# Really simple UDP chat client, not intended as a chat example!! +# Really simple UDP chat client, not intended as a comprehensive chat implementation. # (UDP can lose packets and you won't normally find out, so don't do a chat this way) # This is just a demo that shows how to use the UDP class. +# member variables var udp = PacketPeerUDP.new() -func _process(delta): +func _process(delta): if (not udp.is_listening()): return - - while(udp.get_available_packet_count()>0): + + while(udp.get_available_packet_count() > 0): var packet = udp.get_var() - if (typeof(packet)==TYPE_STRING): + if (typeof(packet) == TYPE_STRING): var host = udp.get_packet_ip() var port = udp.get_packet_port() - get_node("chat/text").add_text("("+host+":"+str(port)+":) "+packet) + get_node("chat/text").add_text("(" + host + ":" + str(port) + ":) " + packet) get_node("chat/text").newline() - - + func _ready(): # Initalization here - get_node("chat").add_style_override("panel",get_stylebox("bg","Tree")) + get_node("chat").add_style_override("panel", get_stylebox("bg", "Tree")) set_process(true) - func send_message(text): if (udp.is_listening()): udp.put_var(text) - - -func _on_connect_toggled( pressed ): +func _on_connect_toggled(pressed): if (pressed): - var err = udp.listen( get_node("listen_port").get_val() ) - if (err!=OK): - get_node("status").set_text("Error:\nCan't Listen.") + var err = udp.listen(get_node("listen_port").get_val()) + if (err != OK): + get_node("status").set_text("Error:\nCan't listen.") get_node("connect").set_pressed(false) else: get_node("status").set_text("Connected.") get_node("connect").set_text("Disconnect") err = udp.set_send_address(get_node("remote_host").get_text(),get_node("remote_port").get_val()) - if (err!=OK): - get_node("status").set_text("Error:\nCan't Resolve.") + if (err != OK): + get_node("status").set_text("Error:\nCan't resolve.") get_node("connect").set_pressed(false) else: - send_message("* "+get_node("user_name").get_text()+" entered chat.") + send_message("* " + get_node("user_name").get_text() + " entered chat.") else: - udp.close() get_node("status").set_text("Disconnected.") get_node("connect").set_text("Connect") - +func _on_entry_line_text_entered(text): + _on_entry_button_pressed() -func _on_entry_line_text_entered( text ): - _on_entry_button_pressed(); func _on_entry_button_pressed(): var msg = get_node("entry_line").get_text() - if (msg==""): + if (msg == ""): return - send_message(get_node("user_name").get_text()+"> "+msg) + send_message(get_node("user_name").get_text() + "> " + msg) get_node("entry_line").set_text("") diff --git a/demos/misc/udp_chat/chat.scn b/demos/misc/udp_chat/chat.scn Binary files differindex efa4b799a0..fe38e9da72 100644 --- a/demos/misc/udp_chat/chat.scn +++ b/demos/misc/udp_chat/chat.scn |