From 30cb5069d1f74947ab4bf71c5b0656d05e426152 Mon Sep 17 00:00:00 2001 From: copygirl Date: Sun, 8 Dec 2024 15:14:39 +0100 Subject: [PATCH] Rename callback functions to use on_xyz naming --- copyMultiplayer.gd | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/copyMultiplayer.gd b/copyMultiplayer.gd index 4a416ba..d4f2bde 100644 --- a/copyMultiplayer.gd +++ b/copyMultiplayer.gd @@ -38,7 +38,7 @@ func _ready() -> void: # FIXME: Hardcoded way to get the main model controller. main_controller = $"/root/SnekStudio_Main/ModelController" - main_controller.child_entered_tree.connect(model_changed) + main_controller.child_entered_tree.connect(on_model_controller_child_added) setup_setting_widget("cache" , "Cache/LineEdit") setup_setting_widget("nickname", "Name/LineEdit" ) @@ -46,11 +46,11 @@ func _ready() -> void: setup_setting_widget("port" , "Host/Port" ) setup_button_connections() - multiplayer.peer_connected .connect(peer_connected) - multiplayer.peer_disconnected .connect(peer_disconnected) - multiplayer.connected_to_server.connect(connected_to_server) - multiplayer.connection_failed .connect(connection_failed) - multiplayer.server_disconnected.connect(server_disconnected) + multiplayer.peer_connected .connect(on_peer_connected) + multiplayer.peer_disconnected .connect(on_peer_disconnected) + multiplayer.connected_to_server.connect(on_connected_to_server) + multiplayer.connection_failed .connect(on_connection_failed) + multiplayer.server_disconnected.connect(on_server_disconnected) func _exit_tree() -> void: multiplayer.multiplayer_peer.close() @@ -65,19 +65,19 @@ func setup_setting_widget(setting_name: String, path: NodePath) -> void: _settings_properties.append({ name = setting_name, args = { } }) _settings_widgets_by_setting_name[setting_name] = widget - if widget is LineEdit: - widget.text_changed.connect(func(text): modify_setting(setting_name, text)) - if widget is SpinBox: - widget.value_changed.connect(func(number): modify_setting(setting_name, roundi(number))) + if widget is LineEdit: widget.text_changed.connect( + func(text): modify_setting(setting_name, text)) + if widget is SpinBox: widget.value_changed.connect( + func(number): modify_setting(setting_name, roundi(number))) func setup_button_connections() -> void: var window = get_settings_window() - window.get_node("Buttons/Join").pressed.connect(join_pressed) - window.get_node("Buttons/Host").pressed.connect(host_pressed) - window.get_node("Buttons/Disconnect").pressed.connect(disconnect_pressed) + window.get_node("Buttons/Join").pressed.connect(on_join_pressed) + window.get_node("Buttons/Host").pressed.connect(on_host_pressed) + window.get_node("Buttons/Disconnect").pressed.connect(on_disconnect_pressed) -func join_pressed() -> void: +func on_join_pressed() -> void: var address_widget: LineEdit = get_settings_window().get_node("Host/Address") var default_address: String = address_widget.placeholder_text var actual_address := default_address if address.is_empty() else address @@ -91,7 +91,7 @@ func join_pressed() -> void: else: print_log("Unable to connect!") -func host_pressed() -> void: +func on_host_pressed() -> void: var peer := ENetMultiplayerPeer.new() if peer.create_server(port) == OK: multiplayer.multiplayer_peer = peer @@ -101,7 +101,7 @@ func host_pressed() -> void: else: print_log("Unable to open server!") -func disconnect_pressed() -> void: +func on_disconnect_pressed() -> void: assert(multiplayer.multiplayer_peer) if multiplayer.is_server(): set_status("") @@ -111,7 +111,7 @@ func disconnect_pressed() -> void: multiplayer.multiplayer_peer.close() -func peer_connected(id: int) -> void: +func on_peer_connected(id: int) -> void: update_status() print_log(["Player ", id, " connected"]) @@ -128,7 +128,7 @@ func peer_connected(id: int) -> void: var filename = main_controller._last_loaded_vrm.get_file() if filename.is_valid_filename(): change_model.rpc_id(id, filename) -func peer_disconnected(id: int) -> void: +func on_peer_disconnected(id: int) -> void: update_status() print_log(["Player ", id, " disconnected"]) @@ -139,15 +139,15 @@ func peer_disconnected(id: int) -> void: player_order.remove_at(player_order.find(id)) update_model_transforms() -func connected_to_server() -> void: +func on_connected_to_server() -> void: print_log("Connected to server") -func connection_failed() -> void: +func on_connection_failed() -> void: set_status("") print_log("Connection failed!") update_enabled_state(false) -func server_disconnected() -> void: +func on_server_disconnected() -> void: set_status("") print_log("Disconnected from server") update_enabled_state(false) @@ -199,8 +199,7 @@ func clear_player_models() -> void: func _process(_delta: float) -> void: SyncController.send_model_animation(self) -# Called when a node is added to the main ModelController. -func model_changed(child: Node) -> void: +func on_model_controller_child_added(child: Node) -> void: if child.name != "Model": return # Wait for one frame, then "_last_loaded_vrm" is updated. await get_tree().process_frame