diff --git a/packages/automaton-fxs/src/tests/add.test.ts b/packages/automaton-fxs/src/tests/add.test.ts index cd8aa63d..292514d2 100644 --- a/packages/automaton-fxs/src/tests/add.test.ts +++ b/packages/automaton-fxs/src/tests/add.test.ts @@ -8,7 +8,7 @@ import type { SerializedAutomaton } from '@fms-cat/automaton'; const defaultData: SerializedAutomaton = { resolution: 100.0, curves: [ - { nodes: [ { time: 0.0, value: 0.0 }, { time: 1.0, value: 1.0 } ] }, + { nodes: [ [ 0.0, 0.0 ], [ 1.0, 1.0 ] ] }, ], channels: [] }; diff --git a/packages/automaton-fxs/src/tests/repeat.test.ts b/packages/automaton-fxs/src/tests/repeat.test.ts index 41825840..1aab3a17 100644 --- a/packages/automaton-fxs/src/tests/repeat.test.ts +++ b/packages/automaton-fxs/src/tests/repeat.test.ts @@ -8,7 +8,7 @@ import type { SerializedAutomaton } from '@fms-cat/automaton'; const defaultData: SerializedAutomaton = { resolution: 100.0, curves: [ - { nodes: [ { time: 0.0, value: 0.0 }, { time: 1.0, value: 1.0 } ] }, + { nodes: [ [ 0.0, 0.0 ], [ 1.0, 1.0 ] ] }, ], channels: [] }; diff --git a/packages/automaton-with-gui/src/CurveWithGUI.ts b/packages/automaton-with-gui/src/CurveWithGUI.ts index 1b1f5827..2c22a4f3 100644 --- a/packages/automaton-with-gui/src/CurveWithGUI.ts +++ b/packages/automaton-with-gui/src/CurveWithGUI.ts @@ -38,16 +38,8 @@ export class CurveWithGUI extends Curve { */ public static readonly DEFAULT_DATA: SerializedCurve = { nodes: [ - { - time: 0.0, - value: 0.0, - out: { time: CURVE_DEFAULT_HANDLE_LENGTH, value: 0.0 } - }, - { - time: 1.0, - value: 0.0, - in: { time: -CURVE_DEFAULT_HANDLE_LENGTH, value: 0.0 } - } + [ 0.0, 0.0, 0.0, 0.0, CURVE_DEFAULT_HANDLE_LENGTH, 0.0 ], + [ 1.0, 0.0, -CURVE_DEFAULT_HANDLE_LENGTH, 0.0, 0.0, 0.0 ], ], fxs: [] }; @@ -117,12 +109,6 @@ export class CurveWithGUI extends Curve { * @param data Data of curve */ public deserialize( data: SerializedCurve ): void { - data.nodes.forEach( ( node ) => { - // fill missing handles - node.in = node.in ?? { time: 0.0, value: 0.0 }; - node.out = node.out ?? { time: 0.0, value: 0.0 }; - } ); - data.fxs?.forEach( ( fx ) => { // fill missing params const defParams = this.__automaton.getFxDefinitionParams( fx.def ); @@ -274,13 +260,15 @@ export class CurveWithGUI extends Curve { */ public createNode( time: number, value: number ): BezierNode & WithID { const id = genID(); - const data = { - $id: id, + const data: any = { time, value, - in: { time: -CURVE_DEFAULT_HANDLE_LENGTH, value: 0.0 }, - out: { time: CURVE_DEFAULT_HANDLE_LENGTH, value: 0.0 } + inTime: -CURVE_DEFAULT_HANDLE_LENGTH, + inValue: 0.0, + outTime: CURVE_DEFAULT_HANDLE_LENGTH, + outValue: 0.0, }; + data.$id = id; this.__nodes.push( data ); this.__sortNodes(); @@ -435,8 +423,7 @@ export class CurveWithGUI extends Curve { const newTime = ( dir === 'in' ) ? Math.min( 0.0, time ) : Math.max( 0.0, time ); - const handle = node[ dir ]; - handle.time = newTime; + node[ dir === 'in' ? 'inTime' : 'outTime' ] = newTime; this.precalc(); @@ -458,8 +445,7 @@ export class CurveWithGUI extends Curve { const node = this.__nodes[ index ]; - const handle = node[ dir ]; - handle.value = value; + node[ dir === 'in' ? 'inValue' : 'outValue' ] = value; this.precalc(); @@ -479,10 +465,8 @@ export class CurveWithGUI extends Curve { if ( index === 0 && dir === 'in' ) { return; } const node = this.__nodes[ index ]; - node[ dir ] = { - time: ( ( dir === 'in' ) ? -1.0 : 1.0 ) * CURVE_DEFAULT_HANDLE_LENGTH, - value: 0.0 - }; + node[ dir === 'in' ? 'inTime' : 'outTime' ] = ( ( dir === 'in' ) ? -1.0 : 1.0 ) * CURVE_DEFAULT_HANDLE_LENGTH; + node[ dir === 'in' ? 'inValue' : 'outValue' ] = 0.0; this.precalc(); @@ -814,20 +798,23 @@ export class CurveWithGUI extends Curve { */ private __serializeNodes(): SerializedBezierNode[] { return this.__nodes.map( ( node ) => { - const data: SerializedBezierNode = {}; - if ( node.time !== 0.0 ) { - data.time = node.time; - } - if ( node.value !== 0.0 ) { - data.value = node.value; - } - if ( node.in.time !== 0.0 || node.in.value !== 0.0 ) { - data.in = jsonCopy( node.in ); - } - if ( node.out.time !== 0.0 || node.out.value !== 0.0 ) { - data.out = jsonCopy( node.out ); + const { time, value, inTime, inValue, outTime, outValue } = node; + + if ( outValue !== 0.0 ) { + return [ time, value, inTime, inValue, outTime, outValue ]; + } else if ( outTime !== 0.0 ) { + return [ time, value, inTime, inValue, outTime ]; + } else if ( inValue !== 0.0 ) { + return [ time, value, inTime, inValue ]; + } else if ( inTime !== 0.0 ) { + return [ time, value, inTime ]; + } else if ( value !== 0.0 ) { + return [ time, value ]; + } else if ( time !== 0.0 ) { + return [ time ]; + } else { + return []; } - return data; } ); } diff --git a/packages/automaton-with-gui/src/compat/compat.ts b/packages/automaton-with-gui/src/compat/compat.ts index 14d359ca..c916fd69 100644 --- a/packages/automaton-with-gui/src/compat/compat.ts +++ b/packages/automaton-with-gui/src/compat/compat.ts @@ -1,6 +1,5 @@ import { SerializedAutomatonWithGUI, defaultDataWithGUI } from '../types/SerializedAutomatonWithGUI'; import { jsonCopy } from '../utils/jsonCopy'; -import { preversionCompat } from './preversionCompat'; import { v1Compat } from './v1Compat'; import { v2Compat } from './v2Compat'; import { v3Compat } from './v3Compat'; @@ -21,10 +20,8 @@ export function compat( data?: any ): SerializedAutomatonWithGUI { let version = parseFloat( newData.version ) || parseFloat( newData.v ); if ( !version && !newData.rev ) { - newData = preversionCompat( newData ); - if ( newData === null ) { - return jsonCopy( defaultDataWithGUI ); - } + // assuming it's latest + return newData; } if ( newData.rev ) { // fuck diff --git a/packages/automaton-with-gui/src/compat/preversionCompat.ts b/packages/automaton-with-gui/src/compat/preversionCompat.ts deleted file mode 100644 index e7128f0c..00000000 --- a/packages/automaton-with-gui/src/compat/preversionCompat.ts +++ /dev/null @@ -1,9 +0,0 @@ -export function preversionCompat( data: any ): any { - if ( data.gui ) { - delete data.gui; // the gui settings are incompatible - return data; - } else { - console.error( 'Loaded data is not compatible with this revision' ); - return null; - } -} diff --git a/packages/automaton-with-gui/src/compat/v2Compat.ts b/packages/automaton-with-gui/src/compat/v2Compat.ts index 24267b3e..89efdb77 100644 --- a/packages/automaton-with-gui/src/compat/v2Compat.ts +++ b/packages/automaton-with-gui/src/compat/v2Compat.ts @@ -1,17 +1,18 @@ import { defaultGUISettings } from '../types/GUISettings'; import { jsonCopy } from '../utils/jsonCopy'; -import type { FxSection, SerializedCurve } from '@fms-cat/automaton'; +import type { FxSection } from '@fms-cat/automaton'; import type { V2FxSection } from './v2types/V2FxSection'; import type { V2SerializedData } from './v2types/V2SerializedData'; import type { V3SerializedAutomatonWithGUI } from './v3types/V3SerializedAutomatonWithGUI'; import type { V3SerializedChannel } from './v3types/V3SerializedChannel'; +import type { V3SerializedCurve } from './v3types/V3SerializedCurve'; export function v2Compat( data: V2SerializedData ): V3SerializedAutomatonWithGUI { - const curves: SerializedCurve[] = []; + const curves: V3SerializedCurve[] = []; const channels: { [ name: string ]: V3SerializedChannel } = {}; Object.entries( data.params ).forEach( ( [ name, param ] ) => { - const curve: SerializedCurve = { + const curve: V3SerializedCurve = { nodes: param.nodes, fxs: param.fxs.map( ( fx: V2FxSection ) => { const newFx: FxSection = { diff --git a/packages/automaton-with-gui/src/compat/v3Compat.ts b/packages/automaton-with-gui/src/compat/v3Compat.ts index 5a18fd83..fdbef0bf 100644 --- a/packages/automaton-with-gui/src/compat/v3Compat.ts +++ b/packages/automaton-with-gui/src/compat/v3Compat.ts @@ -1,11 +1,27 @@ -import { SerializedChannel } from '@fms-cat/automaton'; import { defaultGUISettings } from '../types/GUISettings'; import type { SerializedAutomatonWithGUI } from '../types/SerializedAutomatonWithGUI'; +import type { SerializedBezierNode, SerializedChannel, SerializedCurve } from '@fms-cat/automaton'; import type { V3SerializedAutomatonWithGUI } from './v3types/V3SerializedAutomatonWithGUI'; export function v3Compat( data: V3SerializedAutomatonWithGUI ): SerializedAutomatonWithGUI { const channels: [ name: string, channel: SerializedChannel ][] = []; + const curves: SerializedCurve[] = data.curves.map( ( curve ) => { + const nodes = curve.nodes.map( ( node ) => [ + node.time, + node.value, + node.in?.time, + node.in?.value, + node.out?.time, + node.out?.value, + ] as SerializedBezierNode ); + + return { + nodes, + fxs: curve.fxs + }; + } ); + Object.entries( data.channels ).forEach( ( [ name, channel ] ) => { channels.push( [ name, channel ] ); } ); @@ -13,7 +29,7 @@ export function v3Compat( data: V3SerializedAutomatonWithGUI ): SerializedAutoma const newData: SerializedAutomatonWithGUI = { version: data.version, resolution: data.resolution, - curves: data.curves, + curves, channels, labels: data.labels, guiSettings: { diff --git a/packages/automaton-with-gui/src/compat/v3types/V3SerializedAutomaton.ts b/packages/automaton-with-gui/src/compat/v3types/V3SerializedAutomaton.ts index e84a9ee4..a84c6e16 100644 --- a/packages/automaton-with-gui/src/compat/v3types/V3SerializedAutomaton.ts +++ b/packages/automaton-with-gui/src/compat/v3types/V3SerializedAutomaton.ts @@ -1,5 +1,5 @@ -import type { SerializedCurve } from '@fms-cat/automaton'; import type { V3SerializedChannel } from './V3SerializedChannel'; +import type { V3SerializedCurve } from './V3SerializedCurve'; /** * Interface of serialized automaton data. @@ -13,7 +13,7 @@ export interface V3SerializedAutomaton { /** * Curves of the automaton. */ - curves: SerializedCurve[]; + curves: V3SerializedCurve[]; /** * Channels of the automaton. diff --git a/packages/automaton/src/types/SerializedBezierControlPoint.ts b/packages/automaton-with-gui/src/compat/v3types/V3SerializedBezierControlPoint.ts similarity index 81% rename from packages/automaton/src/types/SerializedBezierControlPoint.ts rename to packages/automaton-with-gui/src/compat/v3types/V3SerializedBezierControlPoint.ts index 38af145f..774b4dba 100644 --- a/packages/automaton/src/types/SerializedBezierControlPoint.ts +++ b/packages/automaton-with-gui/src/compat/v3types/V3SerializedBezierControlPoint.ts @@ -2,7 +2,7 @@ * Serialized variant of {@link BezierControlPoint}. * Some values are optional. */ -export interface SerializedBezierControlPoint { +export interface V3SerializedBezierControlPoint { /** * Time of the control point. */ diff --git a/packages/automaton-with-gui/src/compat/v3types/V3SerializedBezierNode.ts b/packages/automaton-with-gui/src/compat/v3types/V3SerializedBezierNode.ts new file mode 100644 index 00000000..bbca36b2 --- /dev/null +++ b/packages/automaton-with-gui/src/compat/v3types/V3SerializedBezierNode.ts @@ -0,0 +1,31 @@ +import type { V3SerializedBezierControlPoint } from './V3SerializedBezierControlPoint'; + +/** + * Serialized variant of {@link BezierNode}. + * Some values are optional. + */ +export interface V3SerializedBezierNode { + /** + * Time of the node. + * `0.0` by default. + */ + time?: number; + + /** + * Value of the node. + * `0.0` by default. + */ + value?: number; + + /** + * Bezier control point of inlet. + * `{ time: 0.0, value: 0.0 }` by default. + */ + in?: V3SerializedBezierControlPoint; + + /** + * Bezier control point of outlet. + * `{ time: 0.0, value: 0.0 }` by default. + */ + out?: V3SerializedBezierControlPoint; +} diff --git a/packages/automaton-with-gui/src/compat/v3types/V3SerializedCurve.ts b/packages/automaton-with-gui/src/compat/v3types/V3SerializedCurve.ts new file mode 100644 index 00000000..b638e845 --- /dev/null +++ b/packages/automaton-with-gui/src/compat/v3types/V3SerializedCurve.ts @@ -0,0 +1,17 @@ +import type { SerializedFxSection } from '@fms-cat/automaton'; +import type { V3SerializedBezierNode } from './V3SerializedBezierNode'; + +/** + * Interface of a serialized curve. + */ +export interface V3SerializedCurve { + /** + * Bezier nodes of the curve. + */ + nodes: V3SerializedBezierNode[]; + + /** + * Fx sections of the curve. + */ + fxs?: SerializedFxSection[]; +} diff --git a/packages/automaton-with-gui/src/minimizeData.ts b/packages/automaton-with-gui/src/minimizeData.ts index 10640977..8166b664 100644 --- a/packages/automaton-with-gui/src/minimizeData.ts +++ b/packages/automaton-with-gui/src/minimizeData.ts @@ -51,23 +51,16 @@ function minimizeNode( data: SerializedBezierNode, options: MinimizeOptions ): SerializedBezierNode { - const time = precOrUndefined( data.time, options.precisionTime ); - const value = precOrUndefined( data.value, options.precisionValue ); - const inPoint = data.in ? { - time: prec( data.in.time, options.precisionTime ), - value: prec( data.in.value, options.precisionValue ) - } : undefined; - const outPoint = data.out ? { - time: prec( data.out.time, options.precisionTime ), - value: prec( data.out.value, options.precisionValue ) - } : undefined; - - return { - time, - value, - in: inPoint, - out: outPoint - }; + return [ + precOrUndefined( data[ 0 ], options.precisionTime ), + precOrUndefined( data[ 1 ], options.precisionValue ), + precOrUndefined( data[ 2 ], options.precisionTime ), + precOrUndefined( data[ 3 ], options.precisionValue ), + precOrUndefined( data[ 4 ], options.precisionTime ), + precOrUndefined( data[ 5 ], options.precisionValue ), + ].filter( ( element ) => { + return element != null; + } ) as SerializedBezierNode; } function minimizeFx( diff --git a/packages/automaton-with-gui/src/view/components/CurveEditorNode.tsx b/packages/automaton-with-gui/src/view/components/CurveEditorNode.tsx index 2c05df72..4981a7da 100644 --- a/packages/automaton-with-gui/src/view/components/CurveEditorNode.tsx +++ b/packages/automaton-with-gui/src/view/components/CurveEditorNode.tsx @@ -165,11 +165,11 @@ const CurveEditorNode = ( props: { ( dir: 'in' | 'out' ): void => { if ( !curve ) { return; } - const tPrev = node[ dir ]?.time || 0.0; - const vPrev = node[ dir ]?.value || 0.0; + const tPrev = node[ dir === 'in' ? 'inTime' : 'outTime' ]; + const vPrev = node[ dir === 'in' ? 'inValue' : 'outValue' ]; const dirOp = dir === 'in' ? 'out' : 'in'; - const tOpPrev = node[ dirOp ]?.time || 0.0; - const vOpPrev = node[ dirOp ]?.value || 0.0; + const tOpPrev = node[ dir === 'in' ? 'outTime' : 'inTime' ]; + const vOpPrev = node[ dir === 'in' ? 'outValue' : 'inValue' ]; const xPrev = dt2dx( tPrev, range, size.width ); const yPrev = dv2dy( vPrev, range, size.height ); const slPrev = Math.sqrt( xPrev * xPrev + yPrev * yPrev ); @@ -283,8 +283,8 @@ const CurveEditorNode = ( props: { ( dir: 'in' | 'out' ): void => { if ( !curve ) { return; } - const timePrev = node[ dir ]!.time; - const valuePrev = node[ dir ]!.value; + const timePrev = node[ dir === 'in' ? 'inTime' : 'outTime' ]; + const valuePrev = node[ dir === 'in' ? 'inValue' : 'outValue' ]; curve.moveHandleTime( node.$id, dir, 0.0 ); curve.moveHandleValue( node.$id, dir, 0.0 ); @@ -349,36 +349,32 @@ const CurveEditorNode = ( props: { v2y( node.value, range, size.height ) })` } > - { node.in && <> - - - } - { node.out && <> - - - } + + + + { commands: [ { type: 'automaton/createCurve', - data: newData + data: newData.serializeWithID() } ] } ); diff --git a/packages/automaton-with-gui/src/view/components/InspectorCurveNode.tsx b/packages/automaton-with-gui/src/view/components/InspectorCurveNode.tsx index d9891a60..f6f85865 100644 --- a/packages/automaton-with-gui/src/view/components/InspectorCurveNode.tsx +++ b/packages/automaton-with-gui/src/view/components/InspectorCurveNode.tsx @@ -78,7 +78,7 @@ const InspectorCurveNode = ( props: Props ): JSX.Element | null => { { curve.moveHandleTime( node.$id, 'in', displayToTime( value ) ); } } onSettle={ ( value, valuePrev ) => { dispatch( { @@ -101,7 +101,7 @@ const InspectorCurveNode = ( props: Props ): JSX.Element | null => { { curve.moveHandleValue( node.$id, 'in', value ); } } onSettle={ ( value, valuePrev ) => { dispatch( { @@ -127,7 +127,7 @@ const InspectorCurveNode = ( props: Props ): JSX.Element | null => { { curve.moveHandleTime( node.$id, 'out', displayToTime( value ) ); } } onSettle={ ( value, valuePrev ) => { dispatch( { @@ -150,7 +150,7 @@ const InspectorCurveNode = ( props: Props ): JSX.Element | null => { { curve.moveHandleValue( node.$id, 'out', value ); } } onSettle={ ( value, valuePrev ) => { dispatch( { diff --git a/packages/automaton/src/Curve.ts b/packages/automaton/src/Curve.ts index 49bf2b34..b5470573 100644 --- a/packages/automaton/src/Curve.ts +++ b/packages/automaton/src/Curve.ts @@ -55,10 +55,12 @@ export class Curve { */ public deserialize( data: SerializedCurve ): void { this.__nodes = data.nodes.map( ( node ) => ( { - time: node.time ?? 0.0, - value: node.value ?? 0.0, - in: node.in ?? { time: 0.0, value: 0.0 }, - out: node.out ?? { time: 0.0, value: 0.0 } + time: node[ 0 ] ?? 0.0, + value: node[ 1 ] ?? 0.0, + inTime: node[ 2 ] ?? 0.0, + inValue: node[ 3 ] ?? 0.0, + outTime: node[ 4 ] ?? 0.0, + outValue: node[ 5 ] ?? 0.0, } ) ); this.__fxs = []; diff --git a/packages/automaton/src/index.ts b/packages/automaton/src/index.ts index 915d0914..f47b857f 100644 --- a/packages/automaton/src/index.ts +++ b/packages/automaton/src/index.ts @@ -1,5 +1,4 @@ export type { AutomatonOptions } from './types/AutomatonOptions'; -export type { BezierControlPoint } from './types/BezierControlPoint'; export type { BezierNode } from './types/BezierNode'; export type { ChannelUpdateEvent } from './types/ChannelUpdateEvent'; export type { FxContext } from './types/FxContext'; @@ -7,7 +6,6 @@ export type { FxDefinition } from './types/FxDefinition'; export type { FxParam } from './types/FxParam'; export type { FxSection } from './types/FxSection'; export type { SerializedAutomaton } from './types/SerializedAutomaton'; -export type { SerializedBezierControlPoint } from './types/SerializedBezierControlPoint'; export type { SerializedBezierNode } from './types/SerializedBezierNode'; export type { SerializedChannel } from './types/SerializedChannel'; export type { SerializedChannelItem } from './types/SerializedChannelItem'; diff --git a/packages/automaton/src/tests/Automaton.test.ts b/packages/automaton/src/tests/Automaton.test.ts index cef90834..c9810e42 100644 --- a/packages/automaton/src/tests/Automaton.test.ts +++ b/packages/automaton/src/tests/Automaton.test.ts @@ -7,8 +7,8 @@ import type { SerializedAutomaton } from '../types/SerializedAutomaton'; const data: SerializedAutomaton = { resolution: 100.0, curves: [ - { nodes: [ { time: 0.0, value: 0.0 }, { time: 0.6, value: 1.0 } ] }, - { nodes: [ { time: 0.0, value: 2.0 }, { time: 0.6, value: 2.0 } ] } + { nodes: [ [ 0.0, 0.0 ], [ 0.6, 1.0 ] ] }, + { nodes: [ [ 0.0, 2.0 ], [ 0.6, 2.0 ] ] } ], channels: [ [ 'channelWithALinearCurve', { items: [ { curve: 0, time: 0.1 } ] } ], diff --git a/packages/automaton/src/tests/Channel.test.ts b/packages/automaton/src/tests/Channel.test.ts index 7a2d92b2..b7147e84 100644 --- a/packages/automaton/src/tests/Channel.test.ts +++ b/packages/automaton/src/tests/Channel.test.ts @@ -7,8 +7,8 @@ import type { SerializedAutomaton } from '../types/SerializedAutomaton'; const data: SerializedAutomaton = { resolution: 100.0, curves: [ - { nodes: [ { time: 0.0, value: 0.0 }, { time: 0.6, value: 1.0 } ] }, - { nodes: [ { time: 0.0, value: 2.0 }, { time: 0.6, value: 2.0 } ] } + { nodes: [ [ 0.0, 0.0 ], [ 0.6, 1.0 ] ] }, + { nodes: [ [ 0.0, 2.0 ], [ 0.6, 2.0 ] ] } ], channels: [] }; diff --git a/packages/automaton/src/types/BezierControlPoint.ts b/packages/automaton/src/types/BezierControlPoint.ts deleted file mode 100644 index f5ad9340..00000000 --- a/packages/automaton/src/types/BezierControlPoint.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Represents a bezier control point. - */ -export interface BezierControlPoint { - /** - * Time of the control point. - */ - time: number; - - /** - * Value of the control point. - */ - value: number; -} diff --git a/packages/automaton/src/types/BezierNode.ts b/packages/automaton/src/types/BezierNode.ts index 5c5109c5..e3b797a2 100644 --- a/packages/automaton/src/types/BezierNode.ts +++ b/packages/automaton/src/types/BezierNode.ts @@ -1,5 +1,3 @@ -import type { BezierControlPoint } from './BezierControlPoint'; - /** * Represents a bezier node. */ @@ -15,12 +13,22 @@ export interface BezierNode { value: number; /** - * Bezier control point of inlet. + * Bezier control point of inlet. Time. + */ + inTime: number; + + /** + * Bezier control point of inlet. Value. + */ + inValue: number; + + /** + * Bezier control point of outlet. Time. */ - in: BezierControlPoint; + outTime: number; /** - * Bezier control point of outlet. + * Bezier control point of outlet. Value. */ - out: BezierControlPoint; + outValue: number; } diff --git a/packages/automaton/src/types/SerializedBezierNode.ts b/packages/automaton/src/types/SerializedBezierNode.ts index bf667853..4e1bc07b 100644 --- a/packages/automaton/src/types/SerializedBezierNode.ts +++ b/packages/automaton/src/types/SerializedBezierNode.ts @@ -1,31 +1,41 @@ -import type { SerializedBezierControlPoint } from './SerializedBezierControlPoint'; - /** * Serialized variant of {@link BezierNode}. * Some values are optional. */ -export interface SerializedBezierNode { +export type SerializedBezierNode = [ /** * Time of the node. * `0.0` by default. */ - time?: number; + time?: number, /** * Value of the node. * `0.0` by default. */ - value?: number; + value?: number, + + /** + * Bezier control point of inlet. Time. + * `0.0` by default. + */ + inTime?: number, /** - * Bezier control point of inlet. - * `{ time: 0.0, value: 0.0 }` by default. + * Bezier control point of inlet. Value. + * `0.0` by default. */ - in?: SerializedBezierControlPoint; + inValue?: number, /** - * Bezier control point of outlet. - * `{ time: 0.0, value: 0.0 }` by default. + * Bezier control point of outlet. Time. + * `0.0` by default. + */ + outTime?: number, + + /** + * Bezier control point of outlet. Value. + * `0.0` by default. */ - out?: SerializedBezierControlPoint; -} + outValue?: number, +]; diff --git a/packages/automaton/src/utils/bezierEasing.ts b/packages/automaton/src/utils/bezierEasing.ts index 2614312a..d6912f4e 100644 --- a/packages/automaton/src/utils/bezierEasing.ts +++ b/packages/automaton/src/utils/bezierEasing.ts @@ -117,14 +117,14 @@ export function bezierEasing( node0: BezierNode, node1: BezierNode, time: number return rawBezierEasing( { p0: node0.time, - p1: node0.time + ( node0.out.time ), - p2: node1.time + ( node1.in.time ), + p1: node0.time + node0.outTime, + p2: node1.time + node1.inTime, p3: node1.time }, { p0: node0.value, - p1: node0.value + ( node0.out.value ), - p2: node1.value + ( node1.in.value ), + p1: node0.value + node0.outValue, + p2: node1.value + node1.inValue, p3: node1.value }, time