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 | 7x 99x 9x 1159x 90x 11x 79x 79x 4x 136x 17x 17x 5x 5x 138x 138x 30x 138x 5x | /**
* Animation transition rules for Black Trigram
*
* Defines valid transitions between animation states.
* Based on game-design.md specifications and combat flow.
*
* Transition rules:
* - idle ↔ walk ↔ run (movement states)
* - attack → idle (after completion)
* - defend → idle (after completion)
* - hit → idle (after completion)
* - stance_change → idle (after completion)
* - ko is terminal (no transitions out)
* - hit can interrupt any non-ko state (high priority)
*
* @module systems/animation/AnimationTransitions
* @category Animation
* @korean 애니메이션전환
*/
import { AnimationState, TransitionRule } from "./types";
/**
* Default transition rules for animation states
*
* @korean 기본전환규칙
*/
export const DEFAULT_TRANSITIONS: readonly TransitionRule[] = [
// Idle transitions
{ from: "idle", to: "walk", allowed: true },
{ from: "idle", to: "run", allowed: true },
{ from: "idle", to: "attack", allowed: true },
{ from: "idle", to: "defend", allowed: true },
{ from: "idle", to: "stance_change", allowed: true },
{ from: "idle", to: "hit", allowed: true },
{ from: "idle", to: "ko", allowed: true },
// Walk transitions
{ from: "walk", to: "idle", allowed: true },
{ from: "walk", to: "run", allowed: true },
{ from: "walk", to: "attack", allowed: true },
{ from: "walk", to: "defend", allowed: true },
{ from: "walk", to: "stance_change", allowed: true },
{ from: "walk", to: "hit", allowed: true },
{ from: "walk", to: "ko", allowed: true },
// Run transitions
{ from: "run", to: "idle", allowed: true },
{ from: "run", to: "walk", allowed: true },
{ from: "run", to: "attack", allowed: true },
{ from: "run", to: "defend", allowed: true },
{ from: "run", to: "stance_change", allowed: true },
{ from: "run", to: "hit", allowed: true },
{ from: "run", to: "ko", allowed: true },
// Attack transitions (typically returns to idle after completion)
{ from: "attack", to: "idle", allowed: true },
{ from: "attack", to: "hit", allowed: true }, // Can be interrupted by hit
{ from: "attack", to: "ko", allowed: true },
// Defend transitions (typically returns to idle after completion)
{ from: "defend", to: "idle", allowed: true },
{ from: "defend", to: "walk", allowed: true },
{ from: "defend", to: "hit", allowed: true }, // Can be interrupted by hit
{ from: "defend", to: "ko", allowed: true },
// Hit transitions (returns to idle after completion)
{ from: "hit", to: "idle", allowed: true },
{ from: "hit", to: "hit", allowed: true }, // Can take multiple hits
{ from: "hit", to: "ko", allowed: true },
// Stance change transitions (returns to idle after completion)
{ from: "stance_change", to: "idle", allowed: true },
{ from: "stance_change", to: "hit", allowed: true }, // Can be interrupted by hit
{ from: "stance_change", to: "ko", allowed: true },
// KO is terminal - no transitions out
// (Player must be revived/reset to leave KO state)
] as const;
/**
* Check if a transition from one animation state to another is allowed
*
* @param from - Source animation state
* @param to - Target animation state
* @param transitions - Optional custom transition rules (defaults to DEFAULT_TRANSITIONS)
* @returns Whether the transition is allowed
*
* @example
* ```typescript
* // Valid transitions
* isTransitionAllowed("idle", "walk"); // true
* isTransitionAllowed("attack", "idle"); // true
* isTransitionAllowed("hit", "idle"); // true
*
* // Invalid transitions
* isTransitionAllowed("ko", "idle"); // false (KO is terminal)
* isTransitionAllowed("attack", "walk"); // false (must return to idle first)
* ```
*
* @korean 전환허용여부확인
*/
export function isTransitionAllowed(
from: AnimationState,
to: AnimationState,
transitions: readonly TransitionRule[] = DEFAULT_TRANSITIONS
): boolean {
// Same state is always allowed
if (from === to) {
return true;
}
// Find matching transition rule
const rule = transitions.find((t) => t.from === from && t.to === to);
if (!rule) {
return false;
}
// Check condition if provided
Iif (rule.condition) {
return rule.condition();
}
return rule.allowed;
}
/**
* Get all valid transitions from a given animation state
*
* @param from - Source animation state
* @param transitions - Optional custom transition rules (defaults to DEFAULT_TRANSITIONS)
* @returns Array of allowed target animation states
*
* @example
* ```typescript
* getValidTransitions("idle");
* // Returns: ["walk", "run", "attack", "defend", "stance_change", "hit", "ko"]
*
* getValidTransitions("ko");
* // Returns: [] (KO is terminal)
* ```
*
* @korean 유효전환목록가져오기
*/
export function getValidTransitions(
from: AnimationState,
transitions: readonly TransitionRule[] = DEFAULT_TRANSITIONS
): AnimationState[] {
return transitions
.filter((t) => t.from === from && t.allowed)
.map((t) => t.to)
.filter((to) => isTransitionAllowed(from, to, transitions));
}
/**
* Build a transition map for fast lookups
*
* @param transitions - Transition rules to build map from
* @returns Map of from->to->allowed
*
* @korean 전환맵생성
*/
export function buildTransitionMap(
transitions: readonly TransitionRule[] = DEFAULT_TRANSITIONS
): Map<AnimationState, Set<AnimationState>> {
const map = new Map<AnimationState, Set<AnimationState>>();
for (const rule of transitions) {
Iif (!rule.allowed) continue;
if (!map.has(rule.from)) {
map.set(rule.from, new Set());
}
map.get(rule.from)?.add(rule.to);
}
return map;
}
|