-
Notifications
You must be signed in to change notification settings - Fork 11
/
v3Compat.ts
50 lines (44 loc) · 1.71 KB
/
v3Compat.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { defaultGUISettings } from '../types/GUISettings';
import type { SerializedAutomatonWithGUI } from '../types/SerializedAutomatonWithGUI';
import type { SerializedBezierNode, SerializedChannel, SerializedCurve } from '@0b5vr/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 ] );
} );
const newData: SerializedAutomatonWithGUI = {
version: data.version,
resolution: data.resolution,
curves,
channels,
labels: data.labels,
guiSettings: {
snapTimeActive: data.guiSettings?.snapTimeActive,
snapTimeInterval: data.guiSettings?.snapTimeInterval,
snapValueActive: data.guiSettings?.snapValueActive,
snapValueInterval: data.guiSettings?.snapValueInterval,
snapBeatActive: data.guiSettings?.snapBeatActive,
bpm: data.guiSettings?.snapBeatBPM,
beatOffset: defaultGUISettings.beatOffset,
useBeatInGUI: data.guiSettings?.useBeatInGUI,
minimizedPrecisionTime: data.guiSettings?.minimizedPrecisionTime,
minimizedPrecisionValue: data.guiSettings?.minimizedPrecisionValue,
}
};
return newData;
}