3333import { _SubManagerBase } from '../_SubManagerBase.js' ;
3434import { Show } from '../../rpc/messages/Show.js' ;
3535import { MetadataTags } from '../../rpc/structs/MetadataTags.js' ;
36+ import { ImageFieldName } from '../../rpc/enums/ImageFieldName.js' ;
3637import { TextFieldName } from '../../rpc/enums/TextFieldName.js' ;
38+ import { _ManagerUtility } from '../_ManagerUtility.js' ;
3739
3840class _TextAndGraphicManagerBase extends _SubManagerBase {
3941 /**
@@ -239,11 +241,11 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
239241 _assembleShowText ( show ) {
240242 show = this . _setBlankTextFields ( show ) ;
241243
242- if ( this . _mediaTrackTextField !== null ) {
244+ if ( this . _mediaTrackTextField !== null && this . _shouldUpdateMediaTrackField ( ) ) {
243245 show . setMediaTrack ( this . _mediaTrackTextField ) ;
244246 }
245247
246- if ( this . _title !== null ) {
248+ if ( this . _title !== null && this . _shouldUpdateTitleField ( ) ) {
247249 show . setTemplateTitle ( this . _title ) ;
248250 }
249251
@@ -252,7 +254,7 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
252254 return show ;
253255 }
254256
255- const numberOfLines = this . _getNumberOfLines ( ) ;
257+ const numberOfLines = this . _defaultMainWindowCapability !== null ? _ManagerUtility . getMaxNumberOfMainFieldLines ( this . _defaultMainWindowCapability ) : 4 ;
256258
257259 switch ( numberOfLines ) {
258260 case 1 : show = this . _assembleOneLineShowText ( show , nonNullFields ) ;
@@ -643,21 +645,14 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
643645 * @returns {Boolean } - Whether or not the primary image needs to be uploaded.
644646 */
645647 _shouldUpdatePrimaryImage ( ) {
646- if ( this . _defaultMainWindowCapability === null || ! Array . isArray ( this . _defaultMainWindowCapability . getImageTypeSupported ( ) )
647- || this . _defaultMainWindowCapability . getImageTypeSupported ( ) . length > 0 ) {
648- // Cannot detect if there is a secondary image, so we'll just try to detect if there's a primary image and allow it if there is.
649- if ( this . _currentScreenData . getGraphic ( ) === null || this . _currentScreenData . getGraphic ( ) === undefined ) {
650- return this . _primaryGraphic !== null ;
651- } else {
652- if ( this . _primaryGraphic === null ) {
653- return false ;
654- }
655- const screenDataValue = this . _currentScreenData . getGraphic ( ) . getValueParam ( ) ;
656- const secondaryGraphicValue = this . _primaryGraphic . getName ( ) ;
657- return ( `${ screenDataValue } ` ) . toLowerCase ( ) === ( `${ secondaryGraphicValue } ` ) . toLowerCase ( ) ;
658- }
659- }
660- return false ;
648+ const templateSupportsPrimaryArtwork = this . _templateSupportsImageField ( ImageFieldName . graphic ) ;
649+
650+ const currentScreenDataPrimaryGraphicName = ( this . _currentScreenData !== null && this . _currentScreenData . getGraphic ( ) !== null ) ? this . _currentScreenData . getGraphic ( ) . getValueParam ( ) : null ;
651+ const primaryGraphicName = this . _primaryGraphic !== null ? this . _primaryGraphic . getName ( ) : null ;
652+
653+ return templateSupportsPrimaryArtwork
654+ && ( `${ currentScreenDataPrimaryGraphicName } ` ) . toLowerCase ( ) !== ( `${ primaryGraphicName } ` ) . toLowerCase ( )
655+ && this . _primaryGraphic !== null ;
661656 }
662657
663658 /**
@@ -666,46 +661,52 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
666661 * @returns {Boolean } - Whether or not the secondary image needs to be uploaded.
667662 */
668663 _shouldUpdateSecondaryImage ( ) {
669- if ( this . _defaultMainWindowCapability === null || ! Array . isArray ( this . _defaultMainWindowCapability . getImageTypeSupported ( ) )
670- || this . _defaultMainWindowCapability . getImageTypeSupported ( ) . length > 0 ) {
671- // Cannot detect if there is a secondary image, so we'll just try to detect if there's a primary image and allow it if there is.
672- if ( this . _currentScreenData . getGraphic ( ) === null || this . _currentScreenData . getGraphic ( ) === undefined ) {
673- return this . _secondaryGraphic !== null ;
674- } else {
675- if ( this . _secondaryGraphic === null ) {
676- return false ;
677- }
678- const screenDataValue = this . _currentScreenData . getGraphic ( ) . getValueParam ( ) ;
679- const secondaryGraphicValue = this . _secondaryGraphic . getName ( ) ;
680- return ( `${ screenDataValue } ` ) . toLowerCase ( ) === ( `${ secondaryGraphicValue } ` ) . toLowerCase ( ) ;
681- }
682- }
683- return false ;
664+ const templateSupportsSecondaryArtwork = this . _templateSupportsImageField ( ImageFieldName . graphic ) || this . _templateSupportsImageField ( ImageFieldName . secondaryGraphic ) ;
665+
666+ const currentScreenDataSecondaryGraphicName = ( this . _currentScreenData !== null && this . _currentScreenData . getSecondaryGraphic ( ) !== null ) ? this . _currentScreenData . getSecondaryGraphic ( ) . getValueParam ( ) : null ;
667+ const secondaryGraphicName = this . _secondaryGraphic !== null ? this . _secondaryGraphic . getName ( ) : null ;
668+
669+ return templateSupportsSecondaryArtwork
670+ && ( `${ currentScreenDataSecondaryGraphicName } ` ) . toLowerCase ( ) !== ( `${ secondaryGraphicName } ` ) . toLowerCase ( )
671+ && this . _secondaryGraphic !== null ;
684672 }
685673
686674 /**
687- * Gets the number of show lines available on the head unit
675+ * Check to see if mediaTrackTextField should be updated
688676 * @private
689- * @returns { Number } - The number of lines.
677+ * @return { Boolean } - True if mediaTrackTextField should be updated, false if not
690678 */
691- _getNumberOfLines ( ) {
692- if ( this . _defaultMainWindowCapability === null ) {
693- return 4 ;
694- }
679+ _shouldUpdateMediaTrackField ( ) {
680+ return this . _templateSupportsTextField ( TextFieldName . mediaTrack ) ;
681+ }
695682
696- let linesFound = 0 ;
697- const textFields = this . _defaultMainWindowCapability . getTextFields ( ) ;
683+ /**
684+ * Check to see if title should be updated
685+ * @private
686+ * @return {Boolean } - True if title should be updated, false if not
687+ */
688+ _shouldUpdateTitleField ( ) {
689+ return this . _templateSupportsTextField ( TextFieldName . templateTitle ) ;
690+ }
698691
699- if ( Array . isArray ( textFields ) ) {
700- for ( const field of textFields ) {
701- const name = field . getNameParam ( ) ;
702- if ( name === TextFieldName . mainField1 || name === TextFieldName . mainField2 || name === TextFieldName . mainField3 || name === TextFieldName . mainField4 ) {
703- linesFound += 1 ;
704- }
705- }
706- }
692+ /**
693+ * Check to see if template supports the specified text field
694+ * @private
695+ * @param {TextFieldName } name - The text field name to check
696+ * @return {Boolean } - True if text field is supported, false if not
697+ */
698+ _templateSupportsTextField ( name ) {
699+ return this . _defaultMainWindowCapability === null || _ManagerUtility . hasTextFieldOfName ( this . _defaultMainWindowCapability , name ) ;
700+ }
707701
708- return linesFound ;
702+ /**
703+ * Check to see if template supports the specified image field
704+ * @private
705+ * @param {ImageFieldName } name - The image field name to check
706+ * @return {Boolean } - True if image field is supported, false if not
707+ */
708+ _templateSupportsImageField ( name ) {
709+ return this . _defaultMainWindowCapability === null || _ManagerUtility . hasImageFieldOfName ( this . _defaultMainWindowCapability , name ) ;
709710 }
710711
711712 // SCREEN ITEM SETTERS AND GETTERS
0 commit comments