Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | 6x 205x 4013x 112x 105x 103x 207x 206x 204x 203x 2x 1x 200x 197x | /**
* Utility functions for Player3D component integration
*
* Converts PlayerState from combat system to Player3DUnifiedProps for rendering
* with SkeletalPlayer3D (28-bone articulated body model).
*
* @module utils/player3DHelpers
* @category Utilities
* @korean 플레이어3D도우미
*/
import type { PlayerState } from "../systems";
import type { AnimationState } from "../systems/animation/core/types";
import type {
BalanceState,
Player3DUnifiedProps,
PlayerAnimation,
} from "../types/player-visual";
/**
* Static mapping from AnimationState to PlayerAnimation
*
* Stance guard animations map to "idle" since SkeletalPlayer3D
* will handle the stance-specific guard rendering.
* Tactical steps now use dedicated step animations with guard maintenance.
*
* @korean 애니메이션상태맵
*/
const ANIMATION_STATE_MAP: Record<AnimationState, PlayerAnimation> = {
idle: "idle",
walk: "walk",
run: "run", // Now uses dedicated RUN_ANIMATION from BasicAnimations
attack: "attack",
defend: "defend",
// Defensive animations (방어 애니메이션) - map to defend with variations handled by skeletal system
defend_block_success: "defend",
defend_parry: "defend",
defend_guard_break: "defend",
defend_recovery: "defend",
hit: "hit",
stance_change: "stance_change",
stance_side_switch: "stance_change", // Map to stance_change animation (mirroring guard)
ko: "death", // Map ko to death
// Stance guard animations map to stance-specific idle animations with proper biomechanics
stance_guard_geon: "stance_geon",
stance_guard_tae: "stance_tae",
stance_guard_li: "stance_li",
stance_guard_jin: "stance_jin",
stance_guard_son: "stance_son",
stance_guard_gam: "stance_gam",
stance_guard_gan: "stance_gan",
stance_guard_gon: "stance_gon",
// Tactical step animations now map to dedicated step animations
step_forward: "step_forward",
step_back: "step_back",
step_left: "step_left",
step_right: "step_right",
step_forward_left: "step_forward_left",
step_forward_right: "step_forward_right",
step_back_left: "step_back_left",
step_back_right: "step_back_right",
// Fall animations: Now using dedicated FALL_*_ANIMATION from BasicAnimations
fall_forward: "fall_forward",
fall_backward: "fall_backward",
fall_side_left: "fall_side_left",
fall_side_right: "fall_side_right",
// Ground states map to idle with minimal movement
ground_prone: "idle",
ground_supine: "idle",
ground_side_left: "idle",
ground_side_right: "idle",
// 180-degree turn animations map to stance_change (body pivot animation)
turn_left: "stance_change",
turn_right: "stance_change",
// Footwork patterns (보법) - Korean martial arts specialized footwork
footwork_circular_left: "walk", // Lateral movement
footwork_circular_right: "walk",
footwork_pivot_left: "walk", // Rotation movement
footwork_pivot_right: "walk",
footwork_slide_forward: "walk", // Sliding movement
footwork_slide_back: "walk",
footwork_slide_left: "walk",
footwork_slide_right: "walk",
footwork_shuffle: "walk", // Quick adjustment
// Recovery animations (기상 애니메이션) - Getting up from ground states
// Map to idle for now, custom 3D recovery animations will be added in future
recovery_prone_standup: "idle",
recovery_supine_standup: "idle",
recovery_roll: "walk", // Rolling motion approximated by walk
recovery_defensive: "defend", // Guarded getup approximated by defend
// Grappling animations (잡기 애니메이션) - map to attack/defend based on action
grapple_entry: "attack", // Initiating grab uses attack animation
grapple_control: "defend", // Maintaining control uses defensive stance
grapple_struggle: "hit", // Struggling escape uses hit reaction
grapple_escape: "attack", // Successful escape uses attack burst
};
/**
* Convert AnimationState to PlayerAnimation
*
* Maps the animation system's state types to SkeletalPlayer3D's animation types.
*
* @param animState - Animation state from the animation system
* @returns Corresponding PlayerAnimation type
* @korean 애니메이션상태변환
*/
export function animationStateToPlayerAnimation(
animState: AnimationState
): PlayerAnimation {
return ANIMATION_STATE_MAP[animState];
}
/**
* Convert balance number (0-100) to BalanceState enum
*
* @param balance - Balance value from PlayerState (0-100)
* @returns BalanceState enum value
* @korean 균형상태변환
*/
export function getBalanceState(balance: number): BalanceState {
if (balance >= 80) return "READY";
if (balance >= 50) return "SHAKEN";
if (balance >= 20) return "VULNERABLE";
return "HELPLESS";
}
/**
* Get current animation state from PlayerState
*
* Returns stance-specific idle animations when player is in idle/recovering state.
* This ensures each trigram stance displays the correct guard pose with proper
* leg positioning and breathing animation.
*
* @param player - Current player state
* @returns PlayerAnimation enum value (stance-specific for idle states)
* @korean 애니메이션상태가져오기
*/
export function getPlayerAnimation(player: PlayerState): PlayerAnimation {
if (player.isStunned) return "hit";
if (player.isBlocking) return "defend";
if (player.isCountering) return "counter";
// Check combat state (CombatState enum values are lowercase strings)
switch (player.combatState) {
case "attacking":
return "attack";
case "defending":
return "defend";
case "stunned":
return "hit";
case "recovering":
case "idle":
default:
// Use stance-specific idle animation for proper guard pose
// This ensures correct leg positioning for each trigram stance
return `stance_${player.currentStance}` as PlayerAnimation;
}
}
/**
* Converts PlayerState to Player3DUnifiedProps for visual rendering.
*
* Note: This function converts base PlayerState properties used in combat.
* Training-specific stats (misses, accuracy, comboCount) are optional in PlayerState
* and handled separately in training contexts.
*
* @param player - The player state to convert
* @param position - 3D position [x, y, z]
* @param rotation - Rotation in radians
* @param options - Display and behavior options
* @returns Props for SkeletalPlayer3D component (28-bone articulated body model)
* @korean 플레이어상태변환
*
* @example
* ```tsx
* const playerProps = convertPlayerStateToProps(
* playerState,
* [-3, 0, 0],
* 0,
* { isMobile: false, showVitalPoints: false }
* );
*
* <SkeletalPlayer3D {...playerProps} />
* ```
*/
export function convertPlayerStateToProps(
player: PlayerState,
position: [number, number, number],
rotation: number,
options: {
readonly isMobile?: boolean;
readonly facing?: "left" | "right";
readonly scale?: number;
readonly showDetails?: boolean;
readonly showHealthBar?: boolean;
readonly showStanceIndicator?: boolean;
readonly onAnimationComplete?: () => void;
// Facial expression options - 얼굴 표정 옵션
readonly enableFacialExpressions?: boolean;
readonly enableEyeTracking?: boolean;
readonly opponentPosition?: [number, number, number];
} = {}
): Player3DUnifiedProps {
return {
playerId: player.id,
archetype: player.archetype,
stance: player.currentStance,
position,
rotation,
// Health and resources
health: player.health,
maxHealth: player.maxHealth,
stamina: player.stamina,
ki: player.ki,
// Combat states
pain: player.pain,
balance: getBalanceState(player.balance),
consciousness: player.consciousness,
// Combat flags
isBlocking: player.isBlocking,
isStunned: player.isStunned,
isCountering: player.isCountering,
// Animation (derived from combat state)
currentAnimation: getPlayerAnimation(player),
// Display options
name: player.name,
isMobile: options.isMobile ?? false,
facing: options.facing ?? "right",
scale: options.scale ?? 1,
showDetails: options.showDetails,
showHealthBar: options.showHealthBar,
showStanceIndicator: options.showStanceIndicator,
onAnimationComplete: options.onAnimationComplete,
// Facial expression options - 얼굴 표정 옵션
enableFacialExpressions: options.enableFacialExpressions ?? false,
enableEyeTracking: options.enableEyeTracking ?? true,
opponentPosition: options.opponentPosition,
};
}
|