Reward / Power-up icon as a top-left sticker on the cassette and the video box
Twitch icons of channel point rewards (custom images) and Custom Power-ups are cached (10 min, refreshed on unknown triggers, never holding an alert more than 2 s) and attached as alert.icon; cassette.js and video.js show it as a white-outlined sticker on the top-left corner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b3caac7a31
commit
8ac8fe024c
6 changed files with 63 additions and 7 deletions
|
|
@ -38,3 +38,8 @@
|
|||
background:rgba(201,182,228,.85); background-image:repeating-linear-gradient(45deg,#fff6 0 7px,#0000 7px 14px); }
|
||||
#cassette-alert .strip:before { left:-22px; transform:rotate(-28deg); }
|
||||
#cassette-alert .strip:after { right:-22px; transform:rotate(24deg); }
|
||||
|
||||
/* the reward's / Power-up's Twitch icon as a small sticker on the top-left corner (only when Twitch has one) */
|
||||
#cassette-alert .ico { position:absolute; left:-30px; top:-28px; width:76px; height:76px; display:flex; align-items:center; justify-content:center; z-index:2; }
|
||||
#cassette-alert .ico img { max-width:76px; max-height:76px;
|
||||
filter:drop-shadow(3px 0 0 #fff) drop-shadow(-3px 0 0 #fff) drop-shadow(0 3px 0 #fff) drop-shadow(0 -3px 0 #fff) drop-shadow(0 5px 8px rgba(0,0,0,.35)); }
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@
|
|||
<div class="title">${esc(d.title)}</div>
|
||||
<div class="sub">${d.sub && d.sub !== d.title ? esc(d.sub) : ''}</div>
|
||||
<div class="stk"><img src="${esc(d.sticker || DEFAULT_STICKER)}" alt=""></div>
|
||||
${d.icon ? `<div class="ico"><img src="${esc(d.icon)}" alt=""></div>` : ''}
|
||||
${ultra ? '<div class="foil"></div>' + '<div class="spark"></div>'.repeat(6) : ''}
|
||||
</div>
|
||||
<div class="strip"><span class="u">${esc(d.name)}</span> ${esc(d.line)}${d.msg ? `<span class="msg">“${esc(d.msg)}”</span>` : ''}</div>`;
|
||||
|
|
@ -74,6 +75,11 @@
|
|||
{ transform:`translateX(-4px) rotate(${tilt - .6}deg)`, offset:.88 },
|
||||
{ transform:`translateX(0) rotate(${tilt}deg)`, opacity:1 },
|
||||
], { duration:700, easing:'cubic-bezier(.2,.8,.3,1)' });
|
||||
if (q('.ico')) A(q('.ico'), [ // the reward's / Power-up's Twitch icon, top-left corner
|
||||
{ transform:'rotate(10deg) scale(0)', opacity:0 },
|
||||
{ transform:'rotate(-18deg) scale(1.2)', opacity:1, offset:.6 },
|
||||
{ transform:'rotate(-10deg) scale(1)', opacity:1 },
|
||||
], { delay:560, duration:360, easing:'ease-out' });
|
||||
A(q('.stk'), [
|
||||
{ transform:'rotate(-30deg) scale(0)', opacity:0 },
|
||||
{ transform:'rotate(8deg) scale(1.2)', opacity:1, offset:.6 },
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@
|
|||
case 'redeem': {
|
||||
// shown as a cassette tape (cassette.js); polaroid:false = sound only
|
||||
const fill = t => String(t || '').replace(/\{reward\}/g, e.reward || '').replace(/\{variation\}/g, e.variation || '');
|
||||
return { cassette: true, style: e.style || 'cassette', emote: e.emote || null, sticker: rebase(e.art) || null,
|
||||
return { cassette: true, style: e.style || 'cassette', emote: e.emote || null, sticker: rebase(e.art) || null, icon: e.icon || null,
|
||||
name: e.user || 'Someone', line: fill(e.caption || 'redeemed it! ♡'), msg: e.input,
|
||||
title: e.variation || e.reward, sub: e.reward, rarity: e.rarity,
|
||||
sound: e.sound || null, volume: e.volume, soundOnly: e.polaroid === false && !e.tts,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
radial-gradient(ellipse at 50% 45%, #43361a 0%, var(--screen) 70%) #241e12;
|
||||
font-family:'VT323', monospace; color:#fff; text-align:center;
|
||||
}
|
||||
#vfx-box .rec { position:absolute; left:24px; top:16px; font-size:26px; color:#ff3b4e; text-shadow:0 0 6px rgba(255,59,78,.7);
|
||||
#vfx-box .rec { position:absolute; left:58px; top:16px; font-size:26px; color:#ff3b4e; text-shadow:0 0 6px rgba(255,59,78,.7);
|
||||
animation:vfx-blink 1s steps(1) infinite; }
|
||||
#vfx-box .tc { position:absolute; right:24px; top:16px; font-size:24px; opacity:.85; }
|
||||
#vfx-box .title { font-size:36px; line-height:1; text-transform:uppercase; overflow-wrap:anywhere;
|
||||
|
|
@ -33,3 +33,8 @@
|
|||
#vfx-box .brand { position:absolute; right:46px; bottom:14px; font:900 13px/1 'Nunito', sans-serif; letter-spacing:1.5px;
|
||||
color:var(--yellow); opacity:.8; }
|
||||
@keyframes vfx-blink { 0% { opacity:1; } 50% { opacity:0; } }
|
||||
|
||||
/* the Power-up's / reward's Twitch icon as a sticker on the box's top-left corner */
|
||||
#vfx-box .ico { position:absolute; left:-30px; top:-30px; width:72px; height:72px; object-fit:contain; transform:rotate(-10deg); z-index:2;
|
||||
filter:drop-shadow(3px 0 0 #fff) drop-shadow(-3px 0 0 #fff) drop-shadow(0 3px 0 #fff) drop-shadow(0 -3px 0 #fff) drop-shadow(0 5px 8px rgba(0,0,0,.35)); }
|
||||
#vfx-box .ico[hidden] { display:none; }
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
if (vid) return;
|
||||
vid = document.createElement('video'); vid.id = 'vfx-video'; vid.playsInline = true; document.body.appendChild(vid);
|
||||
box = document.createElement('div'); box.id = 'vfx-box';
|
||||
box.innerHTML = '<div class="rec">● REC</div><div class="tc"></div><div class="title"></div><div class="who"></div><div class="amt"></div><div class="brand">POWER-UP</div>';
|
||||
box.innerHTML = '<img class="ico" alt=""><div class="rec">● REC</div><div class="tc"></div><div class="title"></div><div class="who"></div><div class="amt"></div><div class="brand">POWER-UP</div>';
|
||||
document.body.appendChild(box);
|
||||
fit(); addEventListener('resize', fit);
|
||||
}
|
||||
|
|
@ -31,6 +31,8 @@
|
|||
box.querySelector('.who').textContent = a.user || '';
|
||||
box.querySelector('.amt').textContent = a.bits ? `◆ ${a.bits} bits ◆` : '';
|
||||
box.querySelector('.tc').textContent = fmt(0);
|
||||
const ico = box.querySelector('.ico'); // the Power-up's / reward's Twitch icon, top-left corner
|
||||
if (a.icon) { ico.src = a.icon; ico.hidden = false; } else { ico.removeAttribute('src'); ico.hidden = true; }
|
||||
box.style.visibility = 'visible';
|
||||
box.animate([{ opacity: 0, transform: 'translateY(-12px)' }, { opacity: 1, transform: 'none' }], { duration: 400, easing: 'ease-out', fill: 'both' });
|
||||
clearInterval(tcTimer); tcTimer = setInterval(() => { box.querySelector('.tc').textContent = fmt(vid.currentTime); }, 250);
|
||||
|
|
|
|||
|
|
@ -93,6 +93,41 @@ async function addSpeech(v, alert) {
|
|||
}
|
||||
}
|
||||
|
||||
// Twitch icons of channel point rewards (custom images only) and Custom Power-ups.
|
||||
// alert.icon -> top-left sticker on the cassette (cassette.js) and the video box (video.js).
|
||||
// Cached; reloaded every 10 min, or (at most every 30 s) when an unknown trigger comes in.
|
||||
const icons = new Map();
|
||||
let iconsAt = 0, iconsLoading = null;
|
||||
const bestImg = i => (i && (i.url_4x || i.url_2x || i.url_1x)) || null;
|
||||
async function loadIcons() {
|
||||
const twitch = require('./twitch');
|
||||
const u = twitch.getUser();
|
||||
if (!u) return;
|
||||
const next = new Map();
|
||||
try {
|
||||
const r = await twitch.helix(`/channel_points/custom_rewards?broadcaster_id=${u.twitch_id}`);
|
||||
if (r.ok) for (const x of (await r.json()).data || []) { const img = bestImg(x.image); if (img) next.set(`reward|${x.id}`, img); }
|
||||
} catch (e) { console.warn('[redeems] reward icons:', e.message); }
|
||||
try {
|
||||
const r = await twitch.helix(`/bits/custom_power_ups?broadcaster_id=${u.twitch_id}`);
|
||||
if (r.ok) for (const x of (await r.json()).data || []) {
|
||||
const img = bestImg(x.image) || bestImg(x.icon) || bestImg(x.default_image) || x.image_url || null;
|
||||
if (img) next.set(`custom_power_up|${x.id}`, img);
|
||||
}
|
||||
} catch (e) { console.warn('[redeems] power-up icons:', e.message); }
|
||||
if (next.size || !icons.size) { icons.clear(); for (const [k, v] of next) icons.set(k, v); }
|
||||
iconsAt = Date.now();
|
||||
}
|
||||
async function iconFor(kind, key) {
|
||||
if (kind !== 'reward' && kind !== 'custom_power_up') return null;
|
||||
const age = Date.now() - iconsAt;
|
||||
if (age > 10 * 60000 || (!icons.has(`${kind}|${key}`) && age > 30000)) {
|
||||
iconsLoading = iconsLoading || loadIcons().finally(() => { iconsLoading = null; });
|
||||
await Promise.race([iconsLoading, new Promise(r => setTimeout(r, 2000))]); // never hold an alert long
|
||||
}
|
||||
return icons.get(`${kind}|${key}`) || null;
|
||||
}
|
||||
|
||||
// legacy action event type for the actions system / activity log
|
||||
const LEGACY = { reward: 'channel_points', auto_reward: 'auto_reward', power_up: 'power_up', custom_power_up: 'custom_power_up' };
|
||||
|
||||
|
|
@ -106,8 +141,9 @@ function handle(kind, key, title, { user, input, emote, bits }, raw) {
|
|||
return null;
|
||||
}
|
||||
const alert = toAlert(v, { user, input, emote, bits });
|
||||
if (v.tts_voice_id && input && !v.video) addSpeech(v, alert).then(() => alerts.send(alert, raw)); // speech first, then the alert
|
||||
else alerts.send(alert, raw);
|
||||
const ready = iconFor(kind, key).then(icon => { alert.icon = icon; });
|
||||
if (v.tts_voice_id && input && !v.video) ready.then(() => addSpeech(v, alert)).then(() => alerts.send(alert, raw)); // speech first, then the alert
|
||||
else ready.then(() => alerts.send(alert, raw));
|
||||
return alert;
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +153,7 @@ async function rebuild(kind, key, { user, input, emote, bits }) {
|
|||
const v = pick(db.getVariationsFor(kind, key));
|
||||
if (!v) return null;
|
||||
const alert = toAlert(v, { user, input, emote, bits });
|
||||
alert.icon = await iconFor(kind, key);
|
||||
if (v.tts_voice_id && input && !v.video) await addSpeech(v, alert);
|
||||
return alert;
|
||||
}
|
||||
|
|
@ -138,8 +175,9 @@ function test({ id, kind, key }) {
|
|||
: v.kind === 'reward' ? 'test input' : null;
|
||||
const alert = toAlert({ ...v, enabled: 1 }, { user: 'ChickenWhisperer', input, emote: v.kind === 'power_up' ? '25' : null,
|
||||
bits: v.kind === 'custom_power_up' ? 50 : null }); // 25 = Kappa
|
||||
if (v.tts_voice_id && !v.video) addSpeech(v, alert).then(() => alerts.sendTestAlert(alert));
|
||||
else alerts.sendTestAlert(alert);
|
||||
const ready = iconFor(v.kind, v.key).then(icon => { alert.icon = icon; });
|
||||
if (v.tts_voice_id && !v.video) ready.then(() => addSpeech(v, alert)).then(() => alerts.sendTestAlert(alert));
|
||||
else ready.then(() => alerts.sendTestAlert(alert));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue