|
|
@ -2,7 +2,7 @@ class_name copyMultiplayer |
|
|
|
extends Mod_Base |
|
|
|
extends Mod_Base |
|
|
|
|
|
|
|
|
|
|
|
@export var cache := "" |
|
|
|
@export var cache := "" |
|
|
|
@export var nickname := "" |
|
|
|
@export var nickname := "" # FIXME: Not used for anything yet. |
|
|
|
@export var address := "" |
|
|
|
@export var address := "" |
|
|
|
@export var port := 52410 |
|
|
|
@export var port := 52410 |
|
|
|
|
|
|
|
|
|
|
@ -18,10 +18,6 @@ var player_order: Array[int] = [] |
|
|
|
var starting_offset := Vector3(-1.25, 0.0, 0.0) |
|
|
|
var starting_offset := Vector3(-1.25, 0.0, 0.0) |
|
|
|
var accumulative_offset := Vector3( 0.35, 0.0, 0.0) |
|
|
|
var accumulative_offset := Vector3( 0.35, 0.0, 0.0) |
|
|
|
|
|
|
|
|
|
|
|
# FIXME: There is an edge case where you can load the settings while connected, |
|
|
|
|
|
|
|
# resulting in out-of-sync information with connected players, but so far |
|
|
|
|
|
|
|
# I don't believe this should be a source of issues. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void: |
|
|
|
func _ready() -> void: |
|
|
|
# FIXME: This is just thrown together. Dunno if this is an accurate list. |
|
|
|
# FIXME: This is just thrown together. Dunno if this is an accurate list. |
|
|
|
# TODO: Allow specifying additional bones, with the help of a hierachical list of existing bones in the model. |
|
|
|
# TODO: Allow specifying additional bones, with the help of a hierachical list of existing bones in the model. |
|
|
@ -44,18 +40,12 @@ func _ready() -> void: |
|
|
|
main_controller = $"/root/SnekStudio_Main/ModelController" |
|
|
|
main_controller = $"/root/SnekStudio_Main/ModelController" |
|
|
|
main_controller.child_entered_tree.connect(on_model_controller_child_added) |
|
|
|
main_controller.child_entered_tree.connect(on_model_controller_child_added) |
|
|
|
|
|
|
|
|
|
|
|
setup_setting_widget("cache" , "Cache/LineEdit", true ) |
|
|
|
setup_setting_widget("cache" , "Cache/LineEdit") |
|
|
|
setup_setting_widget("nickname", "Name/LineEdit" , false) |
|
|
|
setup_setting_widget("nickname", "Name/LineEdit" ) |
|
|
|
setup_setting_widget("address" , "Host/Address" , true ) |
|
|
|
setup_setting_widget("address" , "Host/Address" ) |
|
|
|
setup_setting_widget("port" , "Host/Port" , true ) |
|
|
|
setup_setting_widget("port" , "Host/Port" ) |
|
|
|
setup_button_connections() |
|
|
|
setup_button_connections() |
|
|
|
|
|
|
|
|
|
|
|
# Filter whitespace characters from nickname before saving it to "nickname" field. |
|
|
|
|
|
|
|
var nickname_widget: LineEdit = get_settings_window().get_node("Name/LineEdit") |
|
|
|
|
|
|
|
nickname_widget.text_changed.connect(func(new_text): modify_setting("nickname", new_text.strip_edges())) |
|
|
|
|
|
|
|
nickname_widget.text_submitted.connect(func(_new_text): nickname_widget.text = nickname) |
|
|
|
|
|
|
|
nickname_widget.focus_exited.connect(func(): nickname_widget.text = nickname) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
multiplayer.peer_connected .connect(on_peer_connected) |
|
|
|
multiplayer.peer_connected .connect(on_peer_connected) |
|
|
|
multiplayer.peer_disconnected .connect(on_peer_disconnected) |
|
|
|
multiplayer.peer_disconnected .connect(on_peer_disconnected) |
|
|
|
multiplayer.connected_to_server.connect(on_connected_to_server) |
|
|
|
multiplayer.connected_to_server.connect(on_connected_to_server) |
|
|
@ -68,14 +58,13 @@ func _exit_tree() -> void: |
|
|
|
func _create_settings_window() -> Control: |
|
|
|
func _create_settings_window() -> Control: |
|
|
|
return load("res://Mods/copyMultiplayer/Resources/copy_multiplayer_settings.tscn").instantiate() |
|
|
|
return load("res://Mods/copyMultiplayer/Resources/copy_multiplayer_settings.tscn").instantiate() |
|
|
|
|
|
|
|
|
|
|
|
func setup_setting_widget(setting_name: String, path: NodePath, setup_events: bool) -> void: |
|
|
|
func setup_setting_widget(setting_name: String, path: NodePath) -> void: |
|
|
|
var settings = get_settings_window() |
|
|
|
var settings = get_settings_window() |
|
|
|
var widget: Control = settings.get_node(path) |
|
|
|
var widget: Control = settings.get_node(path) |
|
|
|
|
|
|
|
|
|
|
|
_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 setup_events: |
|
|
|
|
|
|
|
if widget is LineEdit: widget.text_changed.connect( |
|
|
|
if widget is LineEdit: widget.text_changed.connect( |
|
|
|
func(text): modify_setting(setting_name, text)) |
|
|
|
func(text): modify_setting(setting_name, text)) |
|
|
|
if widget is SpinBox: widget.value_changed.connect( |
|
|
|
if widget is SpinBox: widget.value_changed.connect( |
|
|
@ -123,6 +112,9 @@ func on_disconnect_pressed() -> void: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func on_peer_connected(id: int) -> void: |
|
|
|
func on_peer_connected(id: int) -> void: |
|
|
|
|
|
|
|
update_status() |
|
|
|
|
|
|
|
print_log(["Player ", id, " connected"]) |
|
|
|
|
|
|
|
|
|
|
|
var model_controller := ModelController.new() |
|
|
|
var model_controller := ModelController.new() |
|
|
|
model_controller.name = str(id) |
|
|
|
model_controller.name = str(id) |
|
|
|
var sync_controller := SyncController.new() |
|
|
|
var sync_controller := SyncController.new() |
|
|
@ -133,28 +125,20 @@ func on_peer_connected(id: int) -> void: |
|
|
|
player_order.append(id) |
|
|
|
player_order.append(id) |
|
|
|
update_model_transforms() |
|
|
|
update_model_transforms() |
|
|
|
|
|
|
|
|
|
|
|
# Send information to the newly connected player about ourselves. |
|
|
|
|
|
|
|
# (Technically this doesn't need to be relayed through the server, but oh well.) |
|
|
|
|
|
|
|
if nickname: change_nickname.rpc_id(id, nickname) |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
update_status() |
|
|
|
|
|
|
|
print_log("%s connected" % sync_controller.get_display_name()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func on_peer_disconnected(id: int) -> void: |
|
|
|
func on_peer_disconnected(id: int) -> void: |
|
|
|
var controller = get_sync_controller(id) |
|
|
|
update_status() |
|
|
|
if not controller: return |
|
|
|
print_log(["Player ", id, " disconnected"]) |
|
|
|
|
|
|
|
|
|
|
|
remove_child(controller.model_controller) |
|
|
|
var controller: ModelController = get_node(str(id)) |
|
|
|
controller.model_controller.queue_free() |
|
|
|
remove_child(controller) |
|
|
|
|
|
|
|
controller.queue_free() |
|
|
|
|
|
|
|
|
|
|
|
player_order.remove_at(player_order.find(id)) |
|
|
|
player_order.remove_at(player_order.find(id)) |
|
|
|
update_model_transforms() |
|
|
|
update_model_transforms() |
|
|
|
|
|
|
|
|
|
|
|
update_status() |
|
|
|
|
|
|
|
print_log("Player %s disconnected" % id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func on_connected_to_server() -> void: |
|
|
|
func on_connected_to_server() -> void: |
|
|
|
print_log("Connected to server") |
|
|
|
print_log("Connected to server") |
|
|
|
|
|
|
|
|
|
|
@ -183,7 +167,7 @@ func update_status() -> void: |
|
|
|
var num_players := 1 + multiplayer.get_peers().size() |
|
|
|
var num_players := 1 + multiplayer.get_peers().size() |
|
|
|
var side := "Hosting" if multiplayer.is_server() else "Connected" |
|
|
|
var side := "Hosting" if multiplayer.is_server() else "Connected" |
|
|
|
var s := "s" if num_players != 1 else "" |
|
|
|
var s := "s" if num_players != 1 else "" |
|
|
|
set_status("%s: %d player%s" % [side, num_players, s]) |
|
|
|
set_status([side, ": ", num_players, " player", s]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# FIXME: Temporary hardcoded way to assign some offset to other players. |
|
|
|
# FIXME: Temporary hardcoded way to assign some offset to other players. |
|
|
@ -229,12 +213,6 @@ func get_sync_controller(peer_id: int) -> SyncController: |
|
|
|
if not model_controller: return null |
|
|
|
if not model_controller: return null |
|
|
|
return model_controller.get_node_or_null("SyncController") as SyncController |
|
|
|
return model_controller.get_node_or_null("SyncController") as SyncController |
|
|
|
|
|
|
|
|
|
|
|
@rpc("any_peer", "reliable") |
|
|
|
|
|
|
|
func change_nickname(new_nickname: String) -> void: |
|
|
|
|
|
|
|
var peer_id := multiplayer.get_remote_sender_id() |
|
|
|
|
|
|
|
var controller := get_sync_controller(peer_id) |
|
|
|
|
|
|
|
if controller: controller.change_nickname(new_nickname) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@rpc("any_peer", "reliable") |
|
|
|
@rpc("any_peer", "reliable") |
|
|
|
func change_model(filename: String) -> void: |
|
|
|
func change_model(filename: String) -> void: |
|
|
|
var peer_id := multiplayer.get_remote_sender_id() |
|
|
|
var peer_id := multiplayer.get_remote_sender_id() |
|
|
|