Files
shanghai-residences/src/contexts/PuzzleAnimationContext.tsx
T
zhongyidian f5f36f75b5 feat: add puzzle residence configuration and reflection progress logic
- Introduced `puzzleResidences.ts` to define puzzle residence configurations including properties like display name, position, and puzzle availability.
- Added `reflectionProgress.ts` to manage badge unlocking logic based on place completion, including functions to determine unlocked badges and video sources for scenes.
2026-04-27 11:49:30 +08:00

41 lines
1.0 KiB
TypeScript

import { createContext, useContext, ReactNode } from 'react'
interface TriggerPuzzleAnimationOptions {
onComplete?: () => void
}
interface PuzzleAnimationContextType {
/** 触发碎片动画,传递碎片ID,并在动画结束后 resolve */
triggerPuzzleAnimation: (
pieceId: number,
options?: TriggerPuzzleAnimationOptions
) => Promise<void>
}
const PuzzleAnimationContext = createContext<PuzzleAnimationContextType | null>(null)
export const PuzzleAnimationProvider = ({
children,
triggerPuzzleAnimation,
}: {
children: ReactNode
triggerPuzzleAnimation: (
pieceId: number,
options?: TriggerPuzzleAnimationOptions
) => Promise<void>
}) => {
return (
<PuzzleAnimationContext.Provider value={{ triggerPuzzleAnimation }}>
{children}
</PuzzleAnimationContext.Provider>
)
}
export const usePuzzleAnimation = () => {
const context = useContext(PuzzleAnimationContext)
if (!context) {
throw new Error('usePuzzleAnimation must be used within PuzzleAnimationProvider')
}
return context
}