From fad3fa7d061d10f7a5939ce8587385415f7307f6 Mon Sep 17 00:00:00 2001 From: copygirl Date: Sun, 23 Feb 2025 19:37:27 +0100 Subject: [PATCH] Support copyMultiplayer headpatting --- copyPat.gd | 54 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/copyPat.gd b/copyPat.gd index e520e18..8ffb7e2 100644 --- a/copyPat.gd +++ b/copyPat.gd @@ -1,23 +1,49 @@ extends Mod_Base @export var headpats_scene: PackedScene -@export var triggers: Array[String] = ["copyPat", "pats copygirl"] @export var countdown: float = 12.0 +var triggers = { + "": ["\\bcopyPat\\b", "pats copygirl\\b"], + "Kuerb1": ["\\bkuerb1Pats\\b", "\\bkuerb1PatPat\\b", "pats [kK]uerb[1y]\\b"], +} + +func _ready() -> void: + add_tracked_setting("countdown", "Seconds active", { "min": 0.0, "max": 3600.0 }) + func handle_channel_chat_message(_cheerer_username: String, _cheerer_display_name: String, message: String, _bits_count: int) -> void: - for trigger in triggers: - if message.contains(trigger): - var skel = get_skeleton() - if not skel: return + for nickname in triggers: + for regex in triggers[nickname]: + if RegEx.create_from_string(regex).search(message): + var skeleton = find_skeleton(nickname) + if not skeleton: return + play_headpat_anim(skeleton) - var node = skel.get_node("copyPat_BoneAttachment"); - if not node: - node = headpats_scene.instantiate() - skel.add_child(node) - add_autodelete_object(node) - node.lifetime = countdown +# Returns the skeleton of the avatar with the specified nickname. An empty +# string will refer to the current user. Otherwise will try to find a player +# with that nickname, assuming the copyMultiplayer mod is active. +func find_skeleton(nickname: String) -> Skeleton3D: + if nickname: + var copyMP = $"../copyMultiplayer" + if not copyMP: return null -func _ready() -> void: - add_tracked_setting("triggers", "Trigger phrases", { }) - add_tracked_setting("countdown", "Seconds active", { "min": 0.0, "max": 3600.0 }) + for controller in copyMP.get_all_sync_controllers(): + if controller.nickname == nickname: + return controller.skeleton + return null + + else: + return get_skeleton() + +func play_headpat_anim(skeleton: Skeleton3D) -> void: + var existing = skeleton.get_node_or_null("copyPat_BoneAttachment"); + if existing: + existing.queue_free() + skeleton.remove_child(existing) + + var node = headpats_scene.instantiate() + skeleton.add_child(node) + add_autodelete_object(node) + + node.lifetime = countdown