Add `vibrate` command

main
copygirl 3 weeks ago
parent e484ab331b
commit 61fcf320ff
  1. 36
      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)

Loading…
Cancel
Save