- 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.
41 lines
1.0 KiB
TypeScript
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
|
|
}
|