Skip to content

Commit

Permalink
fix: move all references to the root of the tl obj
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-dewit committed Sep 16, 2022
1 parent 9f31b9f commit 130b6c3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/timeline-state-resolver-types/src/atem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Mapping } from './mapping'
import { TSRTimelineObjBase, DeviceType, DatastoreValue } from '.'
import { TSRTimelineObjBase, DeviceType } from '.'

export interface MappingAtem extends Mapping {
device: DeviceType.ATEM
Expand Down Expand Up @@ -134,7 +134,7 @@ export interface TimelineObjAtemME extends TimelineObjAtemBase {
type: TimelineContentTypeAtem.ME
me: XOR<
{
input: DatastoreValue<number>
input: number
transition: AtemTransitionStyle
},
{
Expand Down
8 changes: 6 additions & 2 deletions packages/timeline-state-resolver-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ export enum DeviceType {
OBS = 21,
}

export type DatastoreValue<T> = T | { _datastoreKey: string; default: T }

export interface TSRTimelineKeyframe<T> extends Timeline.TimelineKeyframe {
content: Partial<T>
}

export interface TSRTimelineObjBase extends Omit<Timeline.TimelineObject, 'content'>, TSRTimelineObjProps {
content: {
deviceType: DeviceType
$references?: {
[key: string]: {
path: any
overwrite: boolean
}
}
}
keyframes?: Array<TSRTimelineKeyframe<this['content']>>
}
Expand Down
39 changes: 18 additions & 21 deletions packages/timeline-state-resolver/src/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ResolvedTimelineObjectInstanceExtended,
TSRTimeline,
DeviceOptionsBase,
TSRTimelineObjBase,
} from 'timeline-state-resolver-types'
import { AtemDevice, DeviceOptionsAtemInternal } from './devices/atem'
import { EventEmitter } from 'eventemitter3'
Expand Down Expand Up @@ -1164,30 +1165,26 @@ export class Conductor extends EventEmitter<ConductorEvents> {

for (const s of toBeFilled) {
const filledState: typeof s.state = JSON.parse(JSON.stringify(s.state))
const fillState = (content: Record<string, any>, instance: TimelineObjectInstance) => {
Object.entries(content).forEach(([index, val]) => {
if (typeof val === 'object') {
if ('_datastoreKey' in val) {
const datastoreVal = this._datastore[val._datastoreKey]

if (!datastoreVal) {
content[index] = val.default
} else if (instance.originalStart && instance.originalStart > datastoreVal.modified) {
content[index] = val.default
} else if (!instance.originalStart && instance.start > datastoreVal.modified) {
content[index] = val.default
Object.values(filledState.layers).forEach(({ content, instance }) => {
if ((content as TSRTimelineObjBase['content']).$references) {
Object.entries((content as TSRTimelineObjBase['content']).$references || {}).forEach(([key, ref]) => {
const datastoreVal = this._datastore[key]
const set = (obj: Record<string, any>, path: string, val: any) => {
const p = path.split('.')
p.slice(0, -1).reduce((a, b) => a[b], obj)[p.slice(-1)[0]] = val
}

if (datastoreVal !== undefined) {
if (ref.overwrite) {
if ((instance.originalStart || instance.start || 0) <= datastoreVal.modified) {
set(content, ref.path, datastoreVal.value)
}
} else {
content[index] = datastoreVal.value
set(content, ref.path, datastoreVal.value)
}
} else {
// todo - can we do a tighter check
fillState(val, instance)
}
}
})
}
Object.values(filledState.layers).forEach((layer) => {
fillState(layer.content, layer.instance)
})
}
})

this.getDevice(deviceId)
Expand Down

0 comments on commit 130b6c3

Please sign in to comment.