import { findAssetOf } from '../../core/model/Project'; import { centreOf, type HookContext } from './hookHelpers'; /** The Curve tab (#247). */ export function curveHooks({ state, editor }: HookContext) { const { curveEditor } = editor; return { curve: { current: () => curveEditor.currentAssetId, info: () => curveEditor.shownInfo, rect: () => curveEditor.canvasRect(), /** Where a place on the graph (`t` right, `v` up) sits on screen. */ at: (t: number, v: number) => curveEditor.canvas.graphToScreen(t, v), /** The points as the model holds them, handles as offsets in `t` and `v`. */ points: (assetId: string) => { const asset = findAssetOf(state.project, assetId, 'curve'); return asset ? (JSON.parse(JSON.stringify(asset.points)) as unknown) : null; }, picked: () => curveEditor.canvas.pickedIndex, pointButton: () => ({ ...centreOf(curveEditor.pointButton), text: curveEditor.pointButton.text, enabled: curveEditor.pointButton.enabled, }), presetButton: () => centreOf(curveEditor.presetButton), fitAt: () => centreOf(curveEditor.fitButton), previewButton: () => ({ ...centreOf(curveEditor.previewButton), toggled: curveEditor.previewButton.toggled, }), /** The preview as drawn: the share of time, the value, and where its two dots are. */ preview: () => curveEditor.canvas.previewState(), setPreviewTime: (seconds: number) => curveEditor.canvas.setPreviewTime(seconds), }, }; }