From 61fcf320ff6bdfa3ad7c79558ce64a3ab3d0de4c Mon Sep 17 00:00:00 2001 From: copygirl Date: Tue, 11 Nov 2025 13:02:32 +0100 Subject: [PATCH] Add `vibrate` command --- copySocket.gd | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/copySocket.gd b/copySocket.gd index 9105e99..bcc7870 100644 --- a/copySocket.gd +++ b/copySocket.gd @@ -1,7 +1,5 @@ extends Mod_Base -static var NUMBER_REGEX := RegEx.create_from_string("^\\d+$") - var server: TCPServer var peers: Dictionary[WebSocketPeer, int] @@ -54,18 +52,26 @@ func _process(_delta: float) -> void: peers.erase(peer) func _on_websocket_message(peer: WebSocketPeer, message: String) -> void: - if message.begins_with("camera "): - var index := message.substr("camera ".length()) - if NUMBER_REGEX.search(index) and int(index): - var camera_mod := get_node("../CameraPositions") - if camera_mod: - camera_mod._load_camera_position("Camera " + index); - else: - print_log("mod with index 'CameraPositions' not found") - else: - print_log("invalid camera index: " + index) - else: - print_log("unknown command: " + message) - # Process only one message, then disconnect. peer.close() + + var split := message.split(" ", false, 1) + var command := split[0] + var rest := split[1] + + match command: + "camera": + if not rest.is_valid_int(): print_log("expected integer, got '%s'" % rest); return + var index := int(rest) + if not (index >= 1 and index <= 9): print_log("invalid camera '%s'" % rest); return + var camera_mod := get_node("../CameraPositions") + if not camera_mod: print_log("mod 'CameraPositions' not found"); return + camera_mod._load_camera_position("Camera %d" % index) + "vibrate": + if not rest.is_valid_float(): print_log("expected float, got '%s'" % rest); return + var amount := float(rest) + var copy_thrower_mod := get_node("../copyThrower") + if not copy_thrower_mod: print_log("mod 'copyThrower' not found"); return + copy_thrower_mod.vibrate(get_skeleton(), amount) + _: + print_log("unknown command: '%s'" % command)