Skip to content

Commit

Permalink
fix: mixer tween parameters #199
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Feb 1, 2024
1 parent 16b7dfa commit 3934941
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
46 changes: 45 additions & 1 deletion src/__tests__/serializers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
InfoCommand,
InfoLayerCommand,
LoadbgDecklinkCommand,
MixerFillCommand,
PlayCommand,
PlayHtmlCommand,
} from '../commands'
import { TransitionType } from '../enums'
import { TransitionTween, TransitionType } from '../enums'

describe('serializers', () => {
it('should have serializers for every command', () => {
Expand Down Expand Up @@ -207,4 +208,47 @@ describe('serializers', () => {

expect(result).toBe(`INFO 1-10`)
})

it('should serialize a MIXER FILL with tweening properties', () => {
const command: MixerFillCommand = {
command: Commands.MixerFill,
params: {
channel: 1,
layer: 10,
x: 0.1,
y: 0.2,
xScale: 0.7,
yScale: 0.8,

duration: 20,
tween: TransitionTween.IN_CIRC,
},
}
const serialized = serializers[Commands.MixerFill].map((fn) => fn(command.command, command.params))
expect(serialized).toHaveLength(serializers[Commands.MixerFill].length)
const result = serialized.filter((l) => l !== '').join(' ')

expect(result).toBe(`MIXER 1-10 FILL 0.1 0.2 0.7 0.8 20 EASEINCIRC`)
})

it('should serialize a MIXER FILL with duration', () => {
const command: MixerFillCommand = {
command: Commands.MixerFill,
params: {
channel: 1,
layer: 10,
x: 0.1,
y: 0.2,
xScale: 0.7,
yScale: 0.8,

duration: 20,
},
}
const serialized = serializers[Commands.MixerFill].map((fn) => fn(command.command, command.params))
expect(serialized).toHaveLength(serializers[Commands.MixerFill].length)
const result = serialized.filter((l) => l !== '').join(' ')

expect(result).toBe(`MIXER 1-10 FILL 0.1 0.2 0.7 0.8 20`)
})
})
3 changes: 2 additions & 1 deletion src/serializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ const cgDataSerializer = (_: Commands, { data }: CgUpdateParameters | CgAddParam
}
}

const mixerTweenSerializer = (_: Commands, { tween, duration }: MixerTween) => (tween ? tween + ' ' + duration : '')
const mixerTweenSerializer = (_: Commands, { tween, duration }: MixerTween) =>
(duration || '') + (tween ? ' ' + tween : '')
const mixerSimpleValueSerializer = (_: Commands, { value }: { value: number | boolean | string }) =>
value !== undefined ? (typeof value === 'boolean' ? (value ? '1' : '0') : value + '') : ''

Expand Down

0 comments on commit 3934941

Please sign in to comment.