From 0c1e9c5204079c68a77e1842317de3c43b350506 Mon Sep 17 00:00:00 2001 From: SirStendec Date: Wed, 25 Mar 2020 19:05:38 -0400 Subject: [PATCH] 4.19.4 * Fixed: Error loading bits configuration after a Twitch update changed the format, causing an exception that prevents the add-on from initializing fully. --- package.json | 2 +- src/modules/chat/room.js | 6 +- .../twitch-twilight/modules/chat/index.js | 62 ++++++++++++++----- 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 67e1ce50..25f4eb37 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "frankerfacez", "author": "Dan Salvato LLC", - "version": "4.19.3", + "version": "4.19.4", "description": "FrankerFaceZ is a Twitch enhancement suite.", "license": "Apache-2.0", "scripts": { diff --git a/src/modules/chat/room.js b/src/modules/chat/room.js index 6ce76282..f227a993 100644 --- a/src/modules/chat/room.js +++ b/src/modules/chat/room.js @@ -513,8 +513,8 @@ export default class Room { return this.style.delete('bits'); const animated = this.manager.context.get('chat.bits.animated') ? 'animated' : 'static', - theme = this.manager.context.get('theme.is-dark') ? 'DARK' : 'LIGHT', - tt_theme = this.manager.context.get('theme.tooltips-dark') ? 'DARK' : 'LIGHT', + theme = this.manager.context.get('theme.is-dark') ? 'dark' : 'light', + tt_theme = this.manager.context.get('theme.tooltips-dark') ? 'dark' : 'light', out = []; for(const key in this.bitsConfig) @@ -529,7 +529,7 @@ export default class Room { tt_images = tiers[i].images[tt_theme][animated]; out.push(`.ffz-cheer[data-prefix="${prefix}"][data-tier="${i}"] { - color: ${tiers[i].color}; + color: ${tiers[i].color || 'inherit'}; background-image: url("${images[1]}"); background-image: ${WEBKIT}image-set( url("${images[1]}") 1x, diff --git a/src/sites/twitch-twilight/modules/chat/index.js b/src/sites/twitch-twilight/modules/chat/index.js index 0a31f110..a4e98544 100644 --- a/src/sites/twitch-twilight/modules/chat/index.js +++ b/src/sites/twitch-twilight/modules/chat/index.js @@ -2336,7 +2336,12 @@ export function formatBitsConfig(config) { return; const out = {}, - actions = config.indexedActions; + actions = config.indexedActions, + tier_colors = {}; + + if ( Array.isArray(config.tiers) ) + for(const tier of config.tiers) + tier_colors[tier.bits] = tier.color; for(const key in actions) if ( has(actions, key) ) { @@ -2347,22 +2352,51 @@ export function formatBitsConfig(config) { tiers: [] }; - for(const tier of action.orderedTiers) { - const images = {}; - for(const im of tier.images) { - const themed = images[im.theme] = images[im.theme] || [], - ak = im.isAnimated ? 'animated' : 'static', - anim = themed[ak] = themed[ak] || {}; + if ( config?.getImage ) { + for(const tier of action.orderedTiers) { + const images = {}; - anim[im.dpiScale] = im.url; + for(const theme of ['light', 'dark']) { + const themed = images[theme] = images[theme] || {}, + stat = themed.static = themed.static || {}, + animated = themed.animated = themed.animated || {}; + + for(const scale of [1, 2, 4]) { + // Static Images + stat[scale] = config.getImage(action.prefix, theme, 'static', tier.bits, scale, 'png'); + + // Animated Images + animated[scale] = config.getImage(action.prefix, theme, 'animated', tier.bits, scale, 'gif'); + } + } + + new_act.tiers.push({ + amount: tier.bits, + color: tier.color || tier_colors[tier.bits] || 'inherit', + id: tier.id, + images + }); } - new_act.tiers.push({ - amount: tier.bits, - color: tier.color, - id: tier.id, - images - }) + } else if ( action.orderedTiers[0]?.images ) { + for(const tier of action.orderedTiers) { + const images = {}; + + for(const im of tier.images) { + const themed = images[im.theme] = images[im.theme] || [], + ak = im.isAnimated ? 'animated' : 'static', + anim = themed[ak] = themed[ak] || {}; + + anim[im.dpiScale] = im.url; + } + + new_act.tiers.push({ + amount: tier.bits, + color: tier.color || tier_colors[tier.bits] || 'inherit', + id: tier.id, + images + }) + } } }