import type { VideoClip } from '../../core/model/Asset'; import { findAssetOf } from '../../core/model/Project'; import { clipsOf } from '../../core/model/sound'; import { videoLibrary } from '../../viewport/VideoLibrary'; import { currentVideoPicker } from '../video/VideoPicker'; import { centreOf, type HookContext } from './hookHelpers'; /** The Video tab, its picker and the players behind the sprites (#402). */ export function videoHooks({ state, editor }: HookContext) { const { videoEditor } = editor; return { videoTab: { current: () => videoEditor.currentAssetId, info: () => videoEditor.shownInfo, rect: () => videoEditor.canvasRect(), span: () => videoEditor.canvas.shownSpan(), playhead: () => videoEditor.canvas.playhead, playing: () => videoEditor.isPlaying, playButton: () => ({ ...centreOf(videoEditor.playButton), text: videoEditor.playButton.text }), preview: () => videoEditor.canvas.previewInfo(), clips: () => { const asset = findAssetOf(state.project, videoEditor.currentAssetId, 'video'); return asset ? clipsOf(asset).map((c) => ({ id: c.id, name: c.name, props: { ...c.props } })) : []; }, pickedClip: () => videoEditor.canvas.pickedClip()?.id ?? null, /** The middle of the clip strip, and of the track under it, at a second of the video. */ stripAt: (seconds: number) => videoEditor.canvas.stripAt(seconds), trackAt: (seconds: number) => videoEditor.canvas.trackAt(seconds), }, videoPicker: () => { const picker = currentVideoPicker(); return picker ? { ...picker.debugInfo(), waiting: picker.waitingFor } : null; }, videoPickerRow: (file: string) => currentVideoPicker()?.rowGlobal(file) ?? null, /** What each player behind a sprite is doing: its time, whether it runs and is heard. */ videos: () => videoLibrary.debugInfo(), }; }