From 8639cecf4cedd56452b47503be19c44b304cd02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 9 Dec 2015 08:38:23 +0100 Subject: 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. --- demos/misc/autoload/global.gd | 20 +- demos/misc/autoload/scene_a.gd | 3 +- demos/misc/autoload/scene_a.scn | Bin 1459 -> 1660 bytes demos/misc/autoload/scene_b.gd | 3 +- demos/misc/autoload/scene_b.scn | Bin 1448 -> 1639 bytes demos/misc/instancing/ball.scn | Bin 1563 -> 1885 bytes demos/misc/instancing/container.scn | Bin 2312 -> 3137 bytes demos/misc/joysticks/joysticks.gd | 31 +- demos/misc/joysticks/joysticks.scn | Bin 3809 -> 4016 bytes demos/misc/pause/spinpause.gd | 2 - demos/misc/pause/spinpause.scn | Bin 3331 -> 5399 bytes demos/misc/regex/regex.gd | 6 +- demos/misc/regex/regex.scn | Bin 1793 -> 1775 bytes demos/misc/scene_changer/scene_a.gd | 3 +- demos/misc/scene_changer/scene_a.scn | Bin 1459 -> 1660 bytes demos/misc/scene_changer/scene_b.gd | 3 +- demos/misc/scene_changer/scene_b.scn | Bin 1448 -> 1639 bytes demos/misc/threads/thread.gd | 26 +- demos/misc/threads/thread.scn | Bin 1638 -> 1586 bytes demos/misc/tween/engine.cfg | 2 +- demos/misc/tween/main.gd | 53 +-- demos/misc/tween/main.scn | Bin 0 -> 5216 bytes demos/misc/tween/main.xml | 367 --------------------- demos/misc/udp_chat/chat.gd | 45 ++- demos/misc/udp_chat/chat.scn | Bin 3198 -> 3359 bytes demos/misc/window_management/control.gd | 85 ++--- demos/misc/window_management/observer/observer.gd | 29 +- demos/misc/window_management/observer/observer.scn | Bin 1786 -> 3824 bytes demos/misc/window_management/window_management.scn | Bin 5132 -> 4384 bytes 29 files changed, 153 insertions(+), 525 deletions(-) create mode 100644 demos/misc/tween/main.scn delete mode 100644 demos/misc/tween/main.xml (limited to 'demos/misc') diff --git a/demos/misc/autoload/global.gd b/demos/misc/autoload/global.gd index d1bd45461f..126cbc0ab7 100644 --- a/demos/misc/autoload/global.gd +++ b/demos/misc/autoload/global.gd @@ -1,35 +1,33 @@ extends Node - +# member variables var current_scene = null func goto_scene(path): - # This function will usually be called from a signal callback, # or some other function from the running scene. # Deleting the current scene at this point might be # a bad idea, because it may be inside of a callback or function of it. # The worst case will be a crash or unexpected behavior. - + # The way around this is deferring the load to a later time, when # it is ensured that no code from the current scene is running: - + call_deferred("_deferred_goto_scene",path) func _deferred_goto_scene(path): - # Immediately free the current scene, - # there is no risk here. + # there is no risk here. current_scene.free() - + # Load new scene var s = ResourceLoader.load(path) - + # Instance the new scene current_scene = s.instance() - + # Add it to the active scene, as child of root get_tree().get_root().add_child(current_scene) @@ -38,6 +36,6 @@ func _ready(): # Get the current scene, the first time. # it is always the last child of root, # after the autoloaded nodes. - + var root = get_tree().get_root() - current_scene = root.get_child( root.get_child_count() -1 ) + current_scene = root.get_child(root.get_child_count() - 1) diff --git a/demos/misc/autoload/scene_a.gd b/demos/misc/autoload/scene_a.gd index 21a6a84eb9..b95ce7dc6e 100644 --- a/demos/misc/autoload/scene_a.gd +++ b/demos/misc/autoload/scene_a.gd @@ -5,13 +5,12 @@ extends Panel # var a=2 # var b="textvar" + func _ready(): # Initalization here pass - - func _on_goto_scene_pressed(): get_node("/root/global").goto_scene("res://scene_b.scn") pass # replace with function body diff --git a/demos/misc/autoload/scene_a.scn b/demos/misc/autoload/scene_a.scn index 61727a57ba..eff314e29d 100644 Binary files a/demos/misc/autoload/scene_a.scn and b/demos/misc/autoload/scene_a.scn differ diff --git a/demos/misc/autoload/scene_b.gd b/demos/misc/autoload/scene_b.gd index 4a88fddda9..599058848b 100644 --- a/demos/misc/autoload/scene_b.gd +++ b/demos/misc/autoload/scene_b.gd @@ -5,13 +5,12 @@ extends Panel # var a=2 # var b="textvar" + func _ready(): # Initalization here pass - - func _on_goto_scene_pressed(): get_node("/root/global").goto_scene("res://scene_a.scn") pass # replace with function body diff --git a/demos/misc/autoload/scene_b.scn b/demos/misc/autoload/scene_b.scn index ae09eeff88..4cdb03e90e 100644 Binary files a/demos/misc/autoload/scene_b.scn and b/demos/misc/autoload/scene_b.scn differ diff --git a/demos/misc/instancing/ball.scn b/demos/misc/instancing/ball.scn index 81c222a306..4d6367885e 100644 Binary files a/demos/misc/instancing/ball.scn and b/demos/misc/instancing/ball.scn differ diff --git a/demos/misc/instancing/container.scn b/demos/misc/instancing/container.scn index 9a365ac494..0f65daa2ca 100644 Binary files a/demos/misc/instancing/container.scn and b/demos/misc/instancing/container.scn differ diff --git a/demos/misc/joysticks/joysticks.gd b/demos/misc/joysticks/joysticks.gd index d359e993e6..dc9166e49e 100644 --- a/demos/misc/joysticks/joysticks.gd +++ b/demos/misc/joysticks/joysticks.gd @@ -8,33 +8,36 @@ extends Node2D # # Licensed under the MIT license +# member variables var joy_num var cur_joy var axis_value var btn_state -func _ready(): - set_process_input(true) -func _input(ev): +func _input(event): # get the joystick device number from the spinbox joy_num = get_node("joy_num").get_value() - + # display the name of the joystick if we haven't already if joy_num != cur_joy: cur_joy = joy_num - get_node("joy_name").set_text( Input.get_joy_name(joy_num) ) - + get_node("joy_name").set_text(Input.get_joy_name(joy_num)) + # loop through the axes and show their current values - for axis in range(0,8): - axis_value = Input.get_joy_axis(joy_num,axis) - get_node("axis_prog"+str(axis)).set_value(100*axis_value) - get_node("axis_val"+str(axis)).set_text(str(axis_value)) - + for axis in range(0, 8): + axis_value = Input.get_joy_axis(joy_num, axis) + get_node("axis_prog" + str(axis)).set_value(100*axis_value) + get_node("axis_val" + str(axis)).set_text(str(axis_value)) + # loop through the buttons and highlight the ones that are pressed - for btn in range(0,17): + for btn in range(0, 17): btn_state = 1 if (Input.is_joy_button_pressed(joy_num, btn)): - get_node("btn"+str(btn)).add_color_override("font_color",Color(1,1,1,1)) + get_node("btn" + str(btn)).add_color_override("font_color", Color(1, 1, 1, 1)) else: - get_node("btn"+str(btn)).add_color_override("font_color",Color(0.2,0.1,0.3,1)) + get_node("btn" + str(btn)).add_color_override("font_color", Color(0.2, 0.1, 0.3, 1)) + + +func _ready(): + set_process_input(true) diff --git a/demos/misc/joysticks/joysticks.scn b/demos/misc/joysticks/joysticks.scn index 5dbd7f49bf..b78bccbf33 100644 Binary files a/demos/misc/joysticks/joysticks.scn and b/demos/misc/joysticks/joysticks.scn differ diff --git a/demos/misc/pause/spinpause.gd b/demos/misc/pause/spinpause.gd index 1b8f8388f0..ea5617c06f 100644 --- a/demos/misc/pause/spinpause.gd +++ b/demos/misc/pause/spinpause.gd @@ -11,5 +11,3 @@ func _on_pause_pressed(): func _on_unpause_pressed(): get_node("pause_popup").hide() get_tree().set_pause(false) - - diff --git a/demos/misc/pause/spinpause.scn b/demos/misc/pause/spinpause.scn index a3835c4374..2cbe85ec9a 100644 Binary files a/demos/misc/pause/spinpause.scn and b/demos/misc/pause/spinpause.scn differ diff --git a/demos/misc/regex/regex.gd b/demos/misc/regex/regex.gd index 409b4cab05..4921f4ff2e 100644 --- a/demos/misc/regex/regex.gd +++ b/demos/misc/regex/regex.gd @@ -1,11 +1,15 @@ + extends VBoxContainer +# member variables var regex = RegEx.new() + func update_expression(text): regex.compile(text) update_text() + func update_text(): var text = get_node("Text").get_text() var list = get_node("List") @@ -18,7 +22,7 @@ func update_text(): label.set_text(res) list.add_child(label) + func _ready(): get_node("Text").set_text("They asked me \"What's going on \\\"in the manor\\\"?\"") update_expression(get_node("Expression").get_text()) - diff --git a/demos/misc/regex/regex.scn b/demos/misc/regex/regex.scn index 1f46521d0d..debd55504f 100644 Binary files a/demos/misc/regex/regex.scn and b/demos/misc/regex/regex.scn differ diff --git a/demos/misc/scene_changer/scene_a.gd b/demos/misc/scene_changer/scene_a.gd index 956878b0f7..e27c48cf11 100644 --- a/demos/misc/scene_changer/scene_a.gd +++ b/demos/misc/scene_changer/scene_a.gd @@ -5,13 +5,12 @@ extends Panel # var a=2 # var b="textvar" + func _ready(): # Initalization here pass - - func _on_goto_scene_pressed(): get_tree().change_scene("res://scene_b.scn") pass # replace with function body diff --git a/demos/misc/scene_changer/scene_a.scn b/demos/misc/scene_changer/scene_a.scn index 61727a57ba..9a4b6434be 100644 Binary files a/demos/misc/scene_changer/scene_a.scn and b/demos/misc/scene_changer/scene_a.scn differ diff --git a/demos/misc/scene_changer/scene_b.gd b/demos/misc/scene_changer/scene_b.gd index 4f94d6bb8f..b785ada45c 100644 --- a/demos/misc/scene_changer/scene_b.gd +++ b/demos/misc/scene_changer/scene_b.gd @@ -5,13 +5,12 @@ extends Panel # var a=2 # var b="textvar" + func _ready(): # Initalization here pass - - func _on_goto_scene_pressed(): get_tree().change_scene("res://scene_a.scn") pass # replace with function body diff --git a/demos/misc/scene_changer/scene_b.scn b/demos/misc/scene_changer/scene_b.scn index ae09eeff88..4cdb03e90e 100644 Binary files a/demos/misc/scene_changer/scene_b.scn and b/demos/misc/scene_changer/scene_b.scn differ diff --git a/demos/misc/threads/thread.gd b/demos/misc/threads/thread.gd index 7d8aabd1b7..fbfd68af2b 100644 --- a/demos/misc/threads/thread.gd +++ b/demos/misc/threads/thread.gd @@ -1,31 +1,31 @@ extends Node2D -# member variables here, example: -# var a=2 -# var b="textvar" - +# member variables var thread = Thread.new() -#this function runs in a thread! -#threads always take one userdata argument + +# this function runs in a thread! +# threads always take one userdata argument func _bg_load(path): print("THREAD FUNC!") - #load the resource + # load the resource var tex = ResourceLoader.load(path) - #call _bg_load_done on main thread + # call _bg_load_done on main thread call_deferred("_bg_load_done") - return tex #return it + return tex # return it + func _bg_load_done(): - #wait for the thread to complete, get the returned value + # wait for the thread to complete, get the returned value var tex = thread.wait_to_finish() - #set to the sprite + # set to the sprite get_node("sprite").set_texture(tex) + func _on_load_pressed(): if (thread.is_active()): - #already working + # already working return print("START THREAD!") - thread.start(self,"_bg_load","res://mona.png") + thread.start(self, "_bg_load", "res://mona.png") diff --git a/demos/misc/threads/thread.scn b/demos/misc/threads/thread.scn index 349127529a..eea93615c7 100644 Binary files a/demos/misc/threads/thread.scn and b/demos/misc/threads/thread.scn differ diff --git a/demos/misc/tween/engine.cfg b/demos/misc/tween/engine.cfg index 3d3d639964..1d87303015 100644 --- a/demos/misc/tween/engine.cfg +++ b/demos/misc/tween/engine.cfg @@ -1,7 +1,7 @@ [application] name="Tween Demo" -main_scene="res://main.xml" +main_scene="res://main.scn" icon="res://icon.png" target_fps=60 diff --git a/demos/misc/tween/main.gd b/demos/misc/tween/main.gd index a0106a7682..4d37c18ba9 100644 --- a/demos/misc/tween/main.gd +++ b/demos/misc/tween/main.gd @@ -1,10 +1,7 @@ extends Control -# member variables here, example: -# var a=2 -# var b="textvar" - +# member variables var trans = ["linear", "sine", "quint", "quart", "quad", "expo", "elastic", "cubic", "circ", "bounce", "back"] var eases = ["in", "out", "in_out", "out_in"] var modes = ["move", "color", "scale", "rotate", "callback", "follow", "repeat", "pause"] @@ -14,6 +11,7 @@ var state = { eases = Tween.EASE_IN, } + func _ready(): for index in range(trans.size()): var name = trans[index] @@ -39,9 +37,7 @@ func _ready(): get_node("modes/repeat").set_pressed(true) reset_tween() - - # Initalization here - pass + func on_trans_changed(name, index): for index in range(trans.size()): @@ -53,7 +49,8 @@ func on_trans_changed(name, index): state.trans = index reset_tween() - + + func on_eases_changed(name, index): for index in range(eases.size()): var pressed = eases[index] == name @@ -64,7 +61,8 @@ func on_eases_changed(name, index): state.eases = index reset_tween() - + + func on_modes_changed(name): var tween = get_node("tween") if name == "pause": @@ -76,10 +74,12 @@ func on_modes_changed(name): get_node("timeline").set_ignore_mouse(true) else: reset_tween() - + + func on_color_changed(color): reset_tween() - + + func reset_tween(): var tween = get_node("tween") var pos = tween.tell() @@ -92,20 +92,20 @@ func reset_tween(): var size = get_node("tween/area").get_size() if get_node("modes/move").is_pressed(): - tween.interpolate_method(sprite, "set_pos", Vector2(0,0), Vector2(size.width, size.height), 2, state.trans, state.eases) - tween.interpolate_property(sprite, "transform/pos", Vector2(size.width,size.height), Vector2(0, 0), 2, state.trans, state.eases, 2) + tween.interpolate_method(sprite, "set_pos", Vector2(0, 0), Vector2(size.width, size.height), 2, state.trans, state.eases) + tween.interpolate_property(sprite, "transform/pos", Vector2(size.width, size.height), Vector2(0, 0), 2, state.trans, state.eases, 2) if get_node("modes/color").is_pressed(): tween.interpolate_method(sprite, "set_modulate", get_node("color/color_from").get_color(), get_node("color/color_to").get_color(), 2, state.trans, state.eases) tween.interpolate_property(sprite, "modulate", get_node("color/color_to").get_color(), get_node("color/color_from").get_color(), 2, state.trans, state.eases, 2) else: - sprite.set_modulate(Color(1, 1, 1, 1)) + sprite.set_modulate(Color(1,1,1,1)) if get_node("modes/scale").is_pressed(): - tween.interpolate_method(sprite, "set_scale", Vector2(0.5,0.5), Vector2(1.5, 1.5), 2, state.trans, state.eases) - tween.interpolate_property(sprite, "transform/scale", Vector2(1.5,1.5), Vector2(0.5, 0.5), 2, state.trans, state.eases, 2) + tween.interpolate_method(sprite, "set_scale", Vector2(0.5, 0.5), Vector2(1.5, 1.5), 2, state.trans, state.eases) + tween.interpolate_property(sprite, "transform/scale", Vector2(1.5, 1.5), Vector2(0.5, 0.5), 2, state.trans, state.eases, 2) else: - sprite.set_scale(Vector2(1, 1)) + sprite.set_scale(Vector2(1,1)) if get_node("modes/rotate").is_pressed(): tween.interpolate_method(sprite, "_set_rotd", 0, 360, 2, state.trans, state.eases) @@ -139,26 +139,27 @@ func reset_tween(): else: tween.resume_all() get_node("timeline").set_ignore_mouse(true) - -func _on_tween_step( object, key, elapsed, value ): - var timeline = get_node("timeline") +func _on_tween_step(object, key, elapsed, value): + var timeline = get_node("timeline") + var tween = get_node("tween") var runtime = tween.get_runtime() - - var ratio = 100 * (elapsed / runtime) - timeline.set_value(ratio) + var ratio = 100*(elapsed/runtime) + timeline.set_value(ratio) + -func _on_timeline_value_changed( value ): +func _on_timeline_value_changed(value): if !get_node("modes/pause").is_pressed(): return var tween = get_node("tween") var runtime = tween.get_runtime() - tween.seek(runtime * value / 100) - + tween.seek(runtime*value/100) + + func on_callback(arg): var label = get_node("tween/area/label") label.add_text("on_callback -> " + arg + "\n") diff --git a/demos/misc/tween/main.scn b/demos/misc/tween/main.scn new file mode 100644 index 0000000000..3f25bfd75c Binary files /dev/null and b/demos/misc/tween/main.scn differ diff --git a/demos/misc/tween/main.xml b/demos/misc/tween/main.xml deleted file mode 100644 index 6580ba04da..0000000000 --- a/demos/misc/tween/main.xml +++ /dev/null @@ -1,367 +0,0 @@ - - - - - - - "names" - - "main" - "Control" - "_import_path" - "visibility/visible" - "visibility/opacity" - "visibility/self_opacity" - "visibility/behind_parent" - "margin/right" - "margin/bottom" - "transform/rot" - "transform/scale" - "focus_neighbour/left" - "focus_neighbour/top" - "focus_neighbour/right" - "focus_neighbour/bottom" - "focus/ignore_mouse" - "focus/stop_mouse" - "size_flags/horizontal" - "size_flags/vertical" - "size_flags/stretch_ratio" - "script/script" - "__meta__" - "trans" - "VBoxContainer" - "margin/left" - "margin/top" - "linear" - "Button" - "disabled" - "pressed" - "toggle_mode" - "click_on_press" - "text" - "icon" - "flat" - "clip_text" - "align" - "sine" - "quint" - "quart" - "quad" - "expo" - "elastic" - "cubic" - "circ" - "bounce" - "back" - "eases" - "in" - "out" - "in_out" - "out_in" - "modes" - "move" - "color" - "scale" - "rotate" - "callback" - "follow" - "repeat" - "pause" - "label_1" - "Label" - "range/min" - "range/max" - "range/step" - "range/page" - "range/value" - "range/exp_edit" - "rounded_values" - "valign" - "autowrap" - "uppercase" - "percent_visible" - "color_from" - "ColorPicker" - "label_2" - "color_to" - "tween" - "Tween" - "playback/process_mode" - "playback/active" - "playback/repeat" - "playback/speed" - "area" - "Panel" - "label" - "RichTextLabel" - "scroll_active" - "scroll_follow" - "tab_size" - "selection_enabled" - "sprite" - "Sprite" - "transform/pos" - "texture" - "centered" - "offset" - "flip_h" - "flip_v" - "vframes" - "hframes" - "frame" - "modulate" - "region" - "region_rect" - "follow_2" - "timeline" - "HSlider" - "tick_count" - "ticks_on_borders" - "_on_tween_step" - "tween_step" - "_on_timeline_value_changed" - "value_changed" - - "version" - 1 - "conn_count" - 2 - "node_count" - 39 - "variants" - - "" - True - 1 - False - 800 - 600 - 0 - 1, 1 - 2 - - - "__editor_plugin_states__" - - "Script" - - "current" - 0 - "sources" - - "res://main.gd" - - - "2D" - - "pixel_snap" - False - "zoom" - 1.360374 - "use_snap" - True - "ofs" - -215.073, -20.8125 - "snap" - 8 - - "3D" - - "zfar" - 500 - "fov" - 45 - "viewports" - - - "distance" - 4 - "x_rot" - 0 - "y_rot" - 0 - "use_orthogonal" - False - "use_environment" - False - "pos" - 0, 0, 0 - - - "distance" - 4 - "x_rot" - 0 - "y_rot" - 0 - "use_orthogonal" - False - "use_environment" - False - "pos" - 0, 0, 0 - - - "distance" - 4 - "x_rot" - 0 - "y_rot" - 0 - "use_orthogonal" - False - "use_environment" - False - "pos" - 0, 0, 0 - - - "distance" - 4 - "x_rot" - 0 - "y_rot" - 0 - "use_orthogonal" - False - "use_environment" - False - "pos" - 0, 0, 0 - - - "viewport_mode" - 1 - "default_light" - True - "show_grid" - True - "show_origin" - True - "znear" - 0.1 - - - "__editor_run_settings__" - - "custom_args" - "-l $scene" - "run_mode" - 0 - - "__editor_plugin_screen__" - "Script" - - 56 - 256 - 129 - 582 - - "_editor_collapsed" - True - - 73 - 26 - "linear" - 1 - 30 - "sine" - 60 - 86 - "quint" - 90 - 116 - "quart" - 120 - 146 - "quad" - 150 - 176 - "expo" - 180 - 206 - "elastic" - 210 - 236 - "cubic" - 240 - 266 - "circ" - 270 - 296 - "bounce" - 300 - 326 - "back" - 152 - 215 - 372 - - "_editor_collapsed" - True - - 63 - "in" - "out" - "in_out" - "out_in" - 317 - 492 - - "_editor_collapsed" - True - - 77 - "move" - "color" - "scale" - "rotate" - "callback" - "follow" - "repeat" - "pause" - 384 - 760 - 592 - - "_editor_collapsed" - True - - 376 - 19 - "Color From:" - 0 - -1 - 23 - 174 - 178 - 197 - "Color To:" - 201 - 352 - 32 - 768 - 216 - 24 - 552 - 160 - "" - 4 - 0, 0 - - 1, 1, 1, 1 - 0, 0, 0, 0 - 0, 184 - 736, 0 - 40 - 224 - 100 - - "nodes" - -1, -1, 1, 0, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 20, 9, 21, 10, 0, 0, 0, 23, 22, -1, 21, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 11, 25, 12, 7, 13, 8, 14, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 21, 15, 0, 1, 0, 27, 26, -1, 27, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 16, 8, 17, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 18, 33, 19, 34, 3, 35, 3, 36, 20, 0, 1, 0, 27, 37, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 21, 7, 16, 8, 11, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 22, 33, 19, 34, 3, 35, 3, 36, 20, 0, 1, 0, 27, 38, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 23, 7, 16, 8, 24, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 25, 33, 19, 34, 3, 35, 3, 36, 20, 0, 1, 0, 27, 39, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 26, 7, 16, 8, 27, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 28, 33, 19, 34, 3, 35, 3, 36, 20, 0, 1, 0, 27, 40, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 29, 7, 16, 8, 30, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 31, 33, 19, 34, 3, 35, 3, 36, 20, 0, 1, 0, 27, 41, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 32, 7, 16, 8, 33, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 34, 33, 19, 34, 3, 35, 3, 36, 20, 0, 1, 0, 27, 42, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 35, 7, 16, 8, 36, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 37, 33, 19, 34, 3, 35, 3, 36, 20, 0, 1, 0, 27, 43, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 38, 7, 16, 8, 39, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 40, 33, 19, 34, 3, 35, 3, 36, 20, 0, 1, 0, 27, 44, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 41, 7, 16, 8, 42, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 43, 33, 19, 34, 3, 35, 3, 36, 20, 0, 1, 0, 27, 45, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 44, 7, 16, 8, 45, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 46, 33, 19, 34, 3, 35, 3, 36, 20, 0, 1, 0, 27, 46, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 47, 7, 16, 8, 48, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 49, 33, 19, 34, 3, 35, 3, 36, 20, 0, 0, 0, 23, 47, -1, 21, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 50, 25, 12, 7, 51, 8, 52, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 21, 53, 0, 13, 0, 27, 48, -1, 27, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 54, 8, 17, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 55, 33, 19, 34, 3, 35, 3, 36, 20, 0, 13, 0, 27, 49, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 21, 7, 54, 8, 11, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 56, 33, 19, 34, 3, 35, 3, 36, 20, 0, 13, 0, 27, 50, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 23, 7, 54, 8, 24, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 57, 33, 19, 34, 3, 35, 3, 36, 20, 0, 13, 0, 27, 51, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 26, 7, 54, 8, 27, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 58, 33, 19, 34, 3, 35, 3, 36, 20, 0, 0, 0, 23, 52, -1, 21, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 41, 25, 12, 7, 59, 8, 60, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 21, 61, 0, 18, 0, 27, 53, -1, 27, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 62, 8, 17, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 63, 33, 19, 34, 3, 35, 3, 36, 20, 0, 18, 0, 27, 54, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 21, 7, 62, 8, 11, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 64, 33, 19, 34, 3, 35, 3, 36, 20, 0, 18, 0, 27, 55, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 23, 7, 62, 8, 24, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 65, 33, 19, 34, 3, 35, 3, 36, 20, 0, 18, 0, 27, 56, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 26, 7, 62, 8, 27, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 66, 33, 19, 34, 3, 35, 3, 36, 20, 0, 18, 0, 27, 57, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 29, 7, 62, 8, 30, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 67, 33, 19, 34, 3, 35, 3, 36, 20, 0, 18, 0, 27, 58, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 32, 7, 62, 8, 33, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 68, 33, 19, 34, 3, 35, 3, 36, 20, 0, 18, 0, 27, 59, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 35, 7, 62, 8, 36, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 69, 33, 19, 34, 3, 35, 3, 36, 20, 0, 18, 0, 27, 60, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 38, 7, 62, 8, 39, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 70, 33, 19, 34, 3, 35, 3, 36, 20, 0, 0, 0, 23, 54, -1, 21, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 71, 25, 41, 7, 72, 8, 73, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 21, 74, 0, 27, 0, 62, 61, -1, 30, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 75, 8, 76, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 1, 16, 1, 17, 8, 19, 2, 63, 6, 64, 2, 65, 2, 66, 2, 67, 6, 68, 3, 69, 3, 32, 77, 36, 78, 70, 78, 71, 3, 72, 3, 73, 79, 0, 27, 0, 75, 74, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 80, 7, 75, 8, 81, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 27, 0, 62, 76, -1, 31, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 82, 7, 75, 8, 83, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 1, 16, 1, 17, 8, 19, 2, 63, 6, 64, 2, 65, 2, 66, 2, 67, 6, 68, 3, 69, 3, 32, 84, 36, 78, 70, 78, 71, 3, 72, 3, 73, 79, 0, 27, 0, 75, 77, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 85, 7, 75, 8, 86, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 0, 0, 79, 78, -1, 5, 2, 0, 80, 20, 81, 1, 82, 1, 83, 2, 0, 32, 0, 85, 84, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 87, 25, 87, 7, 88, 8, 89, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 0, 33, 0, 87, 86, -1, 24, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 33, 25, 90, 7, 91, 8, 92, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 19, 2, 32, 93, 88, 1, 89, 1, 90, 94, 91, 3, 0, 33, 0, 93, 92, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 94, 95, 9, 6, 10, 7, 95, 96, 96, 1, 97, 95, 98, 3, 99, 3, 100, 20, 101, 20, 102, 78, 103, 97, 104, 3, 105, 98, 0, 33, 0, 93, 58, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 94, 99, 9, 6, 10, 7, 95, 96, 96, 1, 97, 95, 98, 3, 99, 3, 100, 20, 101, 20, 102, 78, 103, 97, 104, 3, 105, 98, 0, 33, 0, 93, 106, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 94, 100, 9, 6, 10, 7, 95, 96, 96, 1, 97, 95, 98, 3, 99, 3, 100, 20, 101, 20, 102, 78, 103, 97, 104, 3, 105, 98, 0, 0, 0, 108, 107, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 101, 25, 102, 7, 72, 8, 41, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 19, 2, 63, 6, 64, 103, 65, 2, 66, 6, 67, 2, 68, 3, 69, 3, 109, 78, 110, 3, 0 - "conns" - 32, 0, 112, 111, 2, 0, 38, 0, 114, 113, 2, 0 - - - - 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 index efa4b799a0..fe38e9da72 100644 Binary files a/demos/misc/udp_chat/chat.scn and b/demos/misc/udp_chat/chat.scn differ diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 1609dda699..881dbdc798 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -1,17 +1,18 @@ extends Control +# member variables var mousepos -func _fixed_process(delta): +func _fixed_process(delta): var modetext = "Mode:\n" if(OS.is_window_fullscreen()): modetext += "Fullscreen\n" else: modetext += "Windowed\n" - + if(!OS.is_window_resizable()): modetext += "FixedSize\n" @@ -29,119 +30,119 @@ func _fixed_process(delta): get_node("Label_Mode").set_text(modetext) - get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) ) + get_node("Label_Position").set_text(str("Position:\n", OS.get_window_position())) - get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) + get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size())) - get_node("Label_MousePosition").set_text(str("Mouse Position:\n", mousepos ) ) + get_node("Label_MousePosition").set_text(str("Mouse Position:\n", mousepos)) - get_node("Label_Screen_Count").set_text( str("Screen_Count:\n", OS.get_screen_count() ) ) + get_node("Label_Screen_Count").set_text(str("Screen_Count:\n", OS.get_screen_count())) - get_node("Label_Screen_Current").set_text( str("Screen:\n", OS.get_current_screen() ) ) + get_node("Label_Screen_Current").set_text(str("Screen:\n", OS.get_current_screen())) - get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) + get_node("Label_Screen0_Resolution").set_text(str("Screen0 Resolution:\n", OS.get_screen_size())) - get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position() ) ) + get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n", OS.get_screen_position())) if(OS.get_screen_count() > 1): get_node("Button_Screen0").show() get_node("Button_Screen1").show() get_node("Label_Screen1_Resolution").show() get_node("Label_Screen1_Position").show() - get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) - get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_position(1) ) ) + get_node("Label_Screen1_Resolution").set_text(str("Screen1 Resolution:\n", OS.get_screen_size(1))) + get_node("Label_Screen1_Position").set_text(str("Screen1 Position:\n", OS.get_screen_position(1))) else: get_node("Button_Screen0").hide() get_node("Button_Screen1").hide() get_node("Label_Screen1_Resolution").hide() get_node("Label_Screen1_Position").hide() - - get_node("Button_Fullscreen").set_pressed( OS.is_window_fullscreen() ) - get_node("Button_FixedSize").set_pressed( !OS.is_window_resizable() ) - get_node("Button_Minimized").set_pressed( OS.is_window_minimized() ) - get_node("Button_Maximized").set_pressed( OS.is_window_maximized() ) - get_node("Button_Mouse_Grab").set_pressed( Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED ) + + get_node("Button_Fullscreen").set_pressed(OS.is_window_fullscreen()) + get_node("Button_FixedSize").set_pressed(!OS.is_window_resizable()) + get_node("Button_Minimized").set_pressed(OS.is_window_minimized()) + get_node("Button_Maximized").set_pressed(OS.is_window_maximized()) + get_node("Button_Mouse_Grab").set_pressed(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED) func check_wm_api(): var s = "" - if( !OS.has_method("get_screen_count") ): + if(!OS.has_method("get_screen_count")): s += " - get_screen_count()\n" - if( !OS.has_method("get_current_screen") ): + if(!OS.has_method("get_current_screen")): s += " - get_current_screen()\n" - if( !OS.has_method("set_current_screen") ): + if(!OS.has_method("set_current_screen")): s += " - set_current_screen()\n" - if( !OS.has_method("get_screen_position") ): + if(!OS.has_method("get_screen_position")): s += " - get_screen_position()\n" - if( !OS.has_method("get_screen_size") ): + if(!OS.has_method("get_screen_size")): s += " - get_screen_size()\n" - if( !OS.has_method("get_window_position") ): + if(!OS.has_method("get_window_position")): s += " - get_window_position()\n" - if( !OS.has_method("set_window_position") ): + if(!OS.has_method("set_window_position")): s += " - set_window_position()\n" - if( !OS.has_method("get_window_size") ): + if(!OS.has_method("get_window_size")): s += " - get_window_size()\n" - if( !OS.has_method("set_window_size") ): + if(!OS.has_method("set_window_size")): s += " - set_window_size()\n" - if( !OS.has_method("set_window_fullscreen") ): + if(!OS.has_method("set_window_fullscreen")): s += " - set_window_fullscreen()\n" - if( !OS.has_method("is_window_fullscreen") ): + if(!OS.has_method("is_window_fullscreen")): s += " - is_window_fullscreen()\n" - if( !OS.has_method("set_window_resizable") ): + if(!OS.has_method("set_window_resizable")): s += " - set_window_resizable()\n" - if( !OS.has_method("is_window_resizable") ): + if(!OS.has_method("is_window_resizable")): s += " - is_window_resizable()\n" - if( !OS.has_method("set_window_minimized") ): + if(!OS.has_method("set_window_minimized")): s += " - set_window_minimized()\n" - if( !OS.has_method("is_window_minimized") ): + if(!OS.has_method("is_window_minimized")): s += " - is_window_minimized()\n" - if( !OS.has_method("set_window_maximized") ): + if(!OS.has_method("set_window_maximized")): s += " - set_window_maximized()\n" - if( !OS.has_method("is_window_maximized") ): + if(!OS.has_method("is_window_maximized")): s += " - is_window_maximized()\n" - if( s.length() == 0 ): + if(s.length() == 0): return true else: var text = get_node("ImplementationDialog/Text").get_text() - get_node("ImplementationDialog/Text").set_text( text + s ) + get_node("ImplementationDialog/Text").set_text(text + s) get_node("ImplementationDialog").show() return false func _ready(): - if( check_wm_api() ): + if(check_wm_api()): set_fixed_process(true) set_process_input(true) -func _input(ev): - if (ev.type==InputEvent.MOUSE_MOTION): - mousepos = ev.pos +func _input(event): + if (event.type == InputEvent.MOUSE_MOTION): + mousepos = event.pos func _on_Button_MoveTo_pressed(): - OS.set_window_position( Vector2(100,100) ) + OS.set_window_position(Vector2(100, 100)) func _on_Button_Resize_pressed(): - OS.set_window_size( Vector2(1024,768) ) + OS.set_window_size(Vector2(1024, 768)) func _on_Button_Screen0_pressed(): diff --git a/demos/misc/window_management/observer/observer.gd b/demos/misc/window_management/observer/observer.gd index d27912a670..c1878bca43 100644 --- a/demos/misc/window_management/observer/observer.gd +++ b/demos/misc/window_management/observer/observer.gd @@ -1,16 +1,17 @@ extends Spatial +# member variables var r_pos = Vector2() var state -const STATE_MENU=0 -const STATE_GRAB=1 +const STATE_MENU = 0 +const STATE_GRAB = 1 + func direction(vector): - var v = get_node("Camera").get_global_transform().basis * vector + var v = get_node("Camera").get_global_transform().basis*vector v = v.normalized() - return v @@ -22,7 +23,6 @@ func impulse(event, action): func _fixed_process(delta): - if(state != STATE_GRAB): return @@ -34,31 +34,31 @@ func _fixed_process(delta): var org = get_translation() if (Input.is_action_pressed("move_forward")): - dir += direction(Vector3(0,0,-1)) + dir += direction(Vector3(0, 0, -1)) if (Input.is_action_pressed("move_backwards")): - dir += direction(Vector3(0,0,1)) + dir += direction(Vector3(0, 0, 1)) if (Input.is_action_pressed("move_left")): - dir += direction(Vector3(-1,0,0)) + dir += direction(Vector3(-1, 0, 0)) if (Input.is_action_pressed("move_right")): - dir += direction(Vector3(1,0,0)) + dir += direction(Vector3(1, 0, 0)) dir = dir.normalized() - move(dir * 10 * delta) - var d = delta * 0.1 + move(dir*10*delta) + var d = delta*0.1 - var yaw = get_transform().rotated(Vector3(0,1,0), d * r_pos.x) + var yaw = get_transform().rotated(Vector3(0, 1, 0), d*r_pos.x) set_transform(yaw) var cam = get_node("Camera") - var pitch = cam.get_transform().rotated(Vector3(1,0,0), d * r_pos.y) + var pitch = cam.get_transform().rotated(Vector3(1, 0, 0), d*r_pos.y) cam.set_transform(pitch) r_pos.x = 0.0 r_pos.y = 0.0 -func _input( event ): +func _input(event): if(event.type == InputEvent.MOUSE_MOTION): r_pos = event.relative_pos @@ -76,4 +76,3 @@ func _ready(): set_process_input(true) state = STATE_MENU - diff --git a/demos/misc/window_management/observer/observer.scn b/demos/misc/window_management/observer/observer.scn index da29ad62b8..813d7d4587 100644 Binary files a/demos/misc/window_management/observer/observer.scn and b/demos/misc/window_management/observer/observer.scn differ diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 8db43b6638..35662871f1 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3