|
|
@ -38,7 +38,7 @@ func _ready() -> void: |
|
|
|
|
|
|
|
|
|
|
|
# FIXME: Hardcoded way to get the main model controller. |
|
|
|
# FIXME: Hardcoded way to get the main model controller. |
|
|
|
main_controller = $"/root/SnekStudio_Main/ModelController" |
|
|
|
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("cache" , "Cache/LineEdit") |
|
|
|
setup_setting_widget("nickname", "Name/LineEdit" ) |
|
|
|
setup_setting_widget("nickname", "Name/LineEdit" ) |
|
|
@ -46,11 +46,11 @@ func _ready() -> void: |
|
|
|
setup_setting_widget("port" , "Host/Port" ) |
|
|
|
setup_setting_widget("port" , "Host/Port" ) |
|
|
|
setup_button_connections() |
|
|
|
setup_button_connections() |
|
|
|
|
|
|
|
|
|
|
|
multiplayer.peer_connected .connect(peer_connected) |
|
|
|
multiplayer.peer_connected .connect(on_peer_connected) |
|
|
|
multiplayer.peer_disconnected .connect(peer_disconnected) |
|
|
|
multiplayer.peer_disconnected .connect(on_peer_disconnected) |
|
|
|
multiplayer.connected_to_server.connect(connected_to_server) |
|
|
|
multiplayer.connected_to_server.connect(on_connected_to_server) |
|
|
|
multiplayer.connection_failed .connect(connection_failed) |
|
|
|
multiplayer.connection_failed .connect(on_connection_failed) |
|
|
|
multiplayer.server_disconnected.connect(server_disconnected) |
|
|
|
multiplayer.server_disconnected.connect(on_server_disconnected) |
|
|
|
|
|
|
|
|
|
|
|
func _exit_tree() -> void: |
|
|
|
func _exit_tree() -> void: |
|
|
|
multiplayer.multiplayer_peer.close() |
|
|
|
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_properties.append({ name = setting_name, args = { } }) |
|
|
|
_settings_widgets_by_setting_name[setting_name] = widget |
|
|
|
_settings_widgets_by_setting_name[setting_name] = widget |
|
|
|
|
|
|
|
|
|
|
|
if widget is LineEdit: |
|
|
|
if widget is LineEdit: widget.text_changed.connect( |
|
|
|
widget.text_changed.connect(func(text): modify_setting(setting_name, text)) |
|
|
|
func(text): modify_setting(setting_name, text)) |
|
|
|
if widget is SpinBox: |
|
|
|
if widget is SpinBox: widget.value_changed.connect( |
|
|
|
widget.value_changed.connect(func(number): modify_setting(setting_name, roundi(number))) |
|
|
|
func(number): modify_setting(setting_name, roundi(number))) |
|
|
|
|
|
|
|
|
|
|
|
func setup_button_connections() -> void: |
|
|
|
func setup_button_connections() -> void: |
|
|
|
var window = get_settings_window() |
|
|
|
var window = get_settings_window() |
|
|
|
window.get_node("Buttons/Join").pressed.connect(join_pressed) |
|
|
|
window.get_node("Buttons/Join").pressed.connect(on_join_pressed) |
|
|
|
window.get_node("Buttons/Host").pressed.connect(host_pressed) |
|
|
|
window.get_node("Buttons/Host").pressed.connect(on_host_pressed) |
|
|
|
window.get_node("Buttons/Disconnect").pressed.connect(disconnect_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 address_widget: LineEdit = get_settings_window().get_node("Host/Address") |
|
|
|
var default_address: String = address_widget.placeholder_text |
|
|
|
var default_address: String = address_widget.placeholder_text |
|
|
|
var actual_address := default_address if address.is_empty() else address |
|
|
|
var actual_address := default_address if address.is_empty() else address |
|
|
@ -91,7 +91,7 @@ func join_pressed() -> void: |
|
|
|
else: |
|
|
|
else: |
|
|
|
print_log("Unable to connect!") |
|
|
|
print_log("Unable to connect!") |
|
|
|
|
|
|
|
|
|
|
|
func host_pressed() -> void: |
|
|
|
func on_host_pressed() -> void: |
|
|
|
var peer := ENetMultiplayerPeer.new() |
|
|
|
var peer := ENetMultiplayerPeer.new() |
|
|
|
if peer.create_server(port) == OK: |
|
|
|
if peer.create_server(port) == OK: |
|
|
|
multiplayer.multiplayer_peer = peer |
|
|
|
multiplayer.multiplayer_peer = peer |
|
|
@ -101,7 +101,7 @@ func host_pressed() -> void: |
|
|
|
else: |
|
|
|
else: |
|
|
|
print_log("Unable to open server!") |
|
|
|
print_log("Unable to open server!") |
|
|
|
|
|
|
|
|
|
|
|
func disconnect_pressed() -> void: |
|
|
|
func on_disconnect_pressed() -> void: |
|
|
|
assert(multiplayer.multiplayer_peer) |
|
|
|
assert(multiplayer.multiplayer_peer) |
|
|
|
if multiplayer.is_server(): |
|
|
|
if multiplayer.is_server(): |
|
|
|
set_status("") |
|
|
|
set_status("") |
|
|
@ -111,7 +111,7 @@ func disconnect_pressed() -> void: |
|
|
|
multiplayer.multiplayer_peer.close() |
|
|
|
multiplayer.multiplayer_peer.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func peer_connected(id: int) -> void: |
|
|
|
func on_peer_connected(id: int) -> void: |
|
|
|
update_status() |
|
|
|
update_status() |
|
|
|
print_log(["Player ", id, " connected"]) |
|
|
|
print_log(["Player ", id, " connected"]) |
|
|
|
|
|
|
|
|
|
|
@ -128,7 +128,7 @@ func peer_connected(id: int) -> void: |
|
|
|
var filename = main_controller._last_loaded_vrm.get_file() |
|
|
|
var filename = main_controller._last_loaded_vrm.get_file() |
|
|
|
if filename.is_valid_filename(): change_model.rpc_id(id, filename) |
|
|
|
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() |
|
|
|
update_status() |
|
|
|
print_log(["Player ", id, " disconnected"]) |
|
|
|
print_log(["Player ", id, " disconnected"]) |
|
|
|
|
|
|
|
|
|
|
@ -139,15 +139,15 @@ func peer_disconnected(id: int) -> void: |
|
|
|
player_order.remove_at(player_order.find(id)) |
|
|
|
player_order.remove_at(player_order.find(id)) |
|
|
|
update_model_transforms() |
|
|
|
update_model_transforms() |
|
|
|
|
|
|
|
|
|
|
|
func connected_to_server() -> void: |
|
|
|
func on_connected_to_server() -> void: |
|
|
|
print_log("Connected to server") |
|
|
|
print_log("Connected to server") |
|
|
|
|
|
|
|
|
|
|
|
func connection_failed() -> void: |
|
|
|
func on_connection_failed() -> void: |
|
|
|
set_status("") |
|
|
|
set_status("") |
|
|
|
print_log("Connection failed!") |
|
|
|
print_log("Connection failed!") |
|
|
|
update_enabled_state(false) |
|
|
|
update_enabled_state(false) |
|
|
|
|
|
|
|
|
|
|
|
func server_disconnected() -> void: |
|
|
|
func on_server_disconnected() -> void: |
|
|
|
set_status("") |
|
|
|
set_status("") |
|
|
|
print_log("Disconnected from server") |
|
|
|
print_log("Disconnected from server") |
|
|
|
update_enabled_state(false) |
|
|
|
update_enabled_state(false) |
|
|
@ -199,8 +199,7 @@ func clear_player_models() -> void: |
|
|
|
func _process(_delta: float) -> void: |
|
|
|
func _process(_delta: float) -> void: |
|
|
|
SyncController.send_model_animation(self) |
|
|
|
SyncController.send_model_animation(self) |
|
|
|
|
|
|
|
|
|
|
|
# Called when a node is added to the main ModelController. |
|
|
|
func on_model_controller_child_added(child: Node) -> void: |
|
|
|
func model_changed(child: Node) -> void: |
|
|
|
|
|
|
|
if child.name != "Model": return |
|
|
|
if child.name != "Model": return |
|
|
|
# Wait for one frame, then "_last_loaded_vrm" is updated. |
|
|
|
# Wait for one frame, then "_last_loaded_vrm" is updated. |
|
|
|
await get_tree().process_frame |
|
|
|
await get_tree().process_frame |
|
|
|