# test_emotion_action_parity.gd —— 验证方向 3:角色情绪动作与表情快捷键 40250 1:1 对齐 extends SceneTree const EmotionActionSystem = preload("res://emotion_action_system.gd") var _passed := 0 var _failed := 0 func _assert(cond: bool, msg: String) -> void: if cond: _passed += 1 print(" [PASS] %s" % msg) else: _failed += 1 printerr(" [FAIL] %s" % msg) func _init() -> void: print("\n=== Running test_emotion_action_parity (Direction 3: Emotions & Hotkeys 1:1) ===") test_emotion_definitions() test_command_resolution() test_ctrl_hotkeys() test_action_prerequisites() print("\n=== SUMMARY: %d passed, %d failed ===" % [_passed, _failed]) if _failed > 0: printerr("TEST FAILED!") quit(1) else: print("ALL TESTS PASSED!") quit(0) func test_emotion_definitions() -> void: print("\n--- Test 1: 18 Official Emotions Definitions (emotion.py) ---") _assert(EmotionActionSystem.is_valid_emotion(EmotionActionSystem.EMOTION_CLAP), "Clap (1) is valid") _assert(EmotionActionSystem.is_valid_emotion(EmotionActionSystem.EMOTION_ANGRY), "Angry (4) is valid") _assert(EmotionActionSystem.is_valid_emotion(EmotionActionSystem.EMOTION_DANCE_1), "Dance 1 (13) is valid") _assert(EmotionActionSystem.is_valid_emotion(EmotionActionSystem.EMOTION_DANCE_6), "Dance 6 (18) is valid") _assert(not EmotionActionSystem.is_valid_emotion(999), "Invalid emotion 999 rejected") func test_command_resolution() -> void: print("\n--- Test 2: Chat Command Resolution (/clap, /dance1..) ---") _assert(EmotionActionSystem.get_emotion_from_command("/clap") == EmotionActionSystem.EMOTION_CLAP, "/clap resolves to EMOTION_CLAP (1)") _assert(EmotionActionSystem.get_emotion_from_command("/dance1") == EmotionActionSystem.EMOTION_DANCE_1, "/dance1 resolves to EMOTION_DANCE_1 (13)") _assert(EmotionActionSystem.get_emotion_from_command("/angry") == EmotionActionSystem.EMOTION_ANGRY, "/angry resolves to EMOTION_ANGRY (4)") _assert(EmotionActionSystem.get_emotion_from_command("/unknown") == 0, "/unknown resolves to 0") func test_ctrl_hotkeys() -> void: print("\n--- Test 3: Ctrl + 1..9 Hotkey Mapping ---") # Ctrl+1 (idx 0) -> Clap _assert(EmotionActionSystem.get_hotkey_emotion(0) == EmotionActionSystem.EMOTION_CLAP, "Ctrl+1 triggers Clap") # Ctrl+2 (idx 1) -> Congratulation _assert(EmotionActionSystem.get_hotkey_emotion(1) == EmotionActionSystem.EMOTION_CONGRATULATION, "Ctrl+2 triggers Congratulation") # Ctrl+4 (idx 3) -> Angry _assert(EmotionActionSystem.get_hotkey_emotion(3) == EmotionActionSystem.EMOTION_ANGRY, "Ctrl+4 triggers Angry") # Ctrl+9 (idx 8) -> Banter _assert(EmotionActionSystem.get_hotkey_emotion(8) == EmotionActionSystem.EMOTION_BANTER, "Ctrl+9 triggers Banter") func test_action_prerequisites() -> void: print("\n--- Test 4: Action Execution Prerequisites (Combat & Mounted Restrictions) ---") # Successful execution var res_ok := EmotionActionSystem.perform_emotion(EmotionActionSystem.EMOTION_CLAP, false, false) _assert(res_ok.ok and res_ok.code == "SUCCESS", "Emotion performed successfully") _assert(res_ok.motion == "clap", "Motion is clap") # Rejected while in combat var res_combat := EmotionActionSystem.perform_emotion(EmotionActionSystem.EMOTION_CLAP, true, false) _assert(not res_combat.ok and res_combat.code == "CANNOT_IN_BATTLE", "Emotion rejected during combat") # Rejected while mounted var res_mount := EmotionActionSystem.perform_emotion(EmotionActionSystem.EMOTION_CLAP, false, true) _assert(not res_mount.ok and res_mount.code == "CANNOT_ON_MOUNT", "Emotion rejected while mounted")