diff --git a/src/tv2-common/content/dve.ts b/src/tv2-common/content/dve.ts index 493e3cd7..447fda0f 100644 --- a/src/tv2-common/content/dve.ts +++ b/src/tv2-common/content/dve.ts @@ -114,6 +114,8 @@ export interface DVEOptions { type BoxConfig = DVEConfigBox & { source: number } type BoxSources = Array<(VTContent | CameraContent | RemoteContent | GraphicsContent) & SplitsContentBoxProperties> +const DEFAULT_LOCATOR_TYPE = 'locators' + export function MakeContentDVEBase< StudioConfig extends TV2StudioConfigBase, ShowStyleConfig extends TV2BlueprintConfigBase @@ -275,14 +277,9 @@ export function MakeContentDVE2< } }) - let graphicsTemplateStyle: any = '' - try { - if (dveConfig.DVEGraphicsTemplateJSON) { - graphicsTemplateStyle = JSON.parse(dveConfig.DVEGraphicsTemplateJSON.toString()) - } - } catch { - context.core.notifyUserWarning(`DVE Graphics Template JSON is not valid for ${dveConfig.DVEName}`) - } + const graphicsTemplate = getDveGraphicsTemplate(dveConfig, context.core.notifyUserWarning) + const graphicsTemplateStyle = getDveGraphicsTemplateStyle(graphicsTemplate) + const locatorType = getDveLocatorType(graphicsTemplate) let keyFile = dveConfig.DVEGraphicsKey ? dveConfig.DVEGraphicsKey.toString() : undefined let frameFile = dveConfig.DVEGraphicsFrame ? dveConfig.DVEGraphicsFrame.toString() : undefined @@ -331,9 +328,9 @@ export function MakeContentDVE2< enable: { start: 0 }, priority: 1, layer: SharedGraphicLLayer.GraphicLLayerLocators, - content: CreateHTMLRendererContent(context.config, 'locators', { + content: CreateHTMLRendererContent(context.config, locatorType, { ...graphicsTemplateContent, - style: graphicsTemplateStyle ?? {} + style: graphicsTemplateStyle }) }), ...(keyFile @@ -378,6 +375,34 @@ export function MakeContentDVE2< } } +function getDveGraphicsTemplate(dveConfigInput: DVEConfigInput, notifyUserWarning: (message: string) => void): object { + try { + const dveGraphicsTemplate = JSON.parse(dveConfigInput.DVEGraphicsTemplateJSON) + if (!isValidDveGraphicsTemplate(dveGraphicsTemplate)) { + notifyUserWarning(`DVE Graphics Template for ${dveConfigInput.DVEName} is invalid.`) + return {} + } + return dveGraphicsTemplate + } catch { + notifyUserWarning(`DVE Graphics Template JSON for ${dveConfigInput.DVEName} is ill-formed.`) + return {} + } +} + +function isValidDveGraphicsTemplate(dveGraphicsTemplate: unknown): dveGraphicsTemplate is object { + return typeof dveGraphicsTemplate === 'object' && dveGraphicsTemplate !== null +} + +function getDveGraphicsTemplateStyle(dveGraphicsTemplate: { locatorType?: string }): object { + const { locatorType, ...dveGraphicsTemplateStyle } = dveGraphicsTemplate + return dveGraphicsTemplateStyle +} + +function getDveLocatorType(dveGraphicsTemplate: { locatorType?: string }): string { + const { locatorType } = dveGraphicsTemplate + return locatorType ?? DEFAULT_LOCATOR_TYPE +} + const setBoxSource = ( boxConfig: BoxConfig, boxSources: BoxSources, diff --git a/src/tv2-common/helpers/graphics/caspar/util.ts b/src/tv2-common/helpers/graphics/caspar/util.ts index 00223d0e..29e64662 100644 --- a/src/tv2-common/helpers/graphics/caspar/util.ts +++ b/src/tv2-common/helpers/graphics/caspar/util.ts @@ -12,7 +12,7 @@ import { SharedGraphicLLayer } from 'tv2-constants' export function CreateHTMLRendererContent( config: TV2ShowStyleConfig, - mappedTemplate: string, + graphicTemplateName: string, data: object ): TSR.TimelineObjCCGTemplate['content'] { return { @@ -22,7 +22,7 @@ export function CreateHTMLRendererContent( name: getHtmlTemplateName(config), data: { display: 'program', - slots: getHtmlTemplateContent(config, mappedTemplate, data), + slots: getHtmlTemplateContent(config, graphicTemplateName, data), partialUpdate: true }, useStopCommand: false, @@ -32,12 +32,22 @@ export function CreateHTMLRendererContent( } } +function getMappedGraphicsTemplateName(templateName: string): string { + switch (templateName) { + case 'locators-afvb': + return 'locators' + default: + return templateName + } +} + export function getHtmlTemplateContent( config: TV2ShowStyleConfig, - graphicTemplate: string, + graphicTemplateName: string, data: object ): Partial { - const layer = getTimelineLayerForGraphic(config, graphicTemplate) + const mappedGraphicTemplateName = getMappedGraphicsTemplateName(graphicTemplateName) + const layer = getTimelineLayerForGraphic(config, mappedGraphicTemplateName) const slot = layerToHTMLGraphicSlot[layer] @@ -49,7 +59,7 @@ export function getHtmlTemplateContent( [slot]: { display: 'program', payload: { - type: graphicTemplate, + type: graphicTemplateName, ...data } }