Overlay: cassette redeems, emote effects, poll card, Hype Train bar, raid card

New overlay modules (taped-paper look, shared with the polaroid alerts):
- cassette.js: redeems as a cassette tape; rarity = shell colour (Ultra Rare gold
  with glow, foil and sparkles), reels spin for the sound's length, sticker corner.
- fx.js: Gigantify (viewer's emote grows giant), On-Screen Celebration (emote
  copies bounce around the screen), highlight / Message Effect (tall taped note).
- poll.js: live poll card with bars, countdown and a WINNER stamp.
- hypebar.js: persistent Hype Train strip (level, progress, time left).
- raidcard.js: silent raid send-off card that stays during the raid countdown.
- nowplaying.js: Feishin now-playing slip (not loaded yet, see overlay).

polaroid.js: shared queue now also drives cassettes/effects; test alerts replace
only other tests and never cut off real alerts; alerts stay up for the animation
+ 3 s or the sound's length; sound lengths measured in the browser for UI-picked
sounds; tip and Hype Train alerts; optional ALERTS_BASE for offline test pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-11-20 23:18:15 +02:00
parent 8c649c5bce
commit 1766e37336
14 changed files with 774 additions and 18 deletions

63
public/alerts/raidcard.js Normal file
View file

@ -0,0 +1,63 @@
/*
Outgoing raid send-off card. Silent, outside the alert queue.
RaidCard.update(phase, raid) phase: start | done | cancel
raid: { target, avatar (Twitch profile picture URL or null), viewers, started_at }
start: appears and stays with a countdown (Twitch raids wait up to 90 s); done: "raid sent!" then leaves; cancel: leaves.
*/
(function () {
const COUNTDOWN_S = 90;
const BASE = window.ALERTS_BASE || '/alerts/';
const FALLBACK = BASE + 'art/CharacterHappy.png';
const esc = s => String(s ?? '').replace(/[&<>"]/g, c => ({ '&':'&amp;', '<':'&lt;', '>':'&gt;', '"':'&quot;' }[c]));
let el = null, timer = null, hideTimer = null, startedAt = 0, shown = false;
function root() { if (!el) { el = document.createElement('div'); el.id = 'raid-card'; document.body.appendChild(el); } return el; }
function render(raid, line, badge) {
const img = raid.avatar ? `<img src="${esc(raid.avatar)}" alt="" onerror="this.onerror=null;this.className='fallback';this.src='${FALLBACK}'">`
: `<img class="fallback" src="${FALLBACK}" alt="">`;
el.innerHTML = `<div class="ph">${img}</div>
<div class="cap"><span class="u">raiding ${esc(raid.target)}</span>${esc(line)}</div>
<div class="when">${esc(badge)}</div>`;
}
function tick() {
const left = Math.max(0, COUNTDOWN_S - Math.round((Date.now() - startedAt) / 1000));
const w = el.querySelector('.when');
if (w) w.textContent = left ? `raid in ${Math.floor(left / 60)}:${String(left % 60).padStart(2, '0')}` : 'any second now…';
}
function enter() {
if (shown) return;
shown = true; el.style.visibility = 'visible';
el.getAnimations().forEach(a => a.cancel());
el.animate([{ transform:'translateY(-420px) rotate(-10deg)', opacity:0 }, { transform:'translateY(10px) rotate(2deg)', opacity:1, offset:.75 },
{ transform:'translateY(0) rotate(-1deg)', opacity:1 }], { duration:700, easing:'cubic-bezier(.2,.8,.3,1)', fill:'forwards' });
}
function leave(delay) {
clearTimeout(hideTimer);
hideTimer = setTimeout(() => {
clearInterval(timer);
el.animate([{ transform:'translateY(0) rotate(-1deg)', opacity:1 }, { transform:'translateX(700px) rotate(18deg)', opacity:0 }],
{ duration:700, easing:'ease-in', fill:'forwards' }).finished.then(() => { el.style.visibility = 'hidden'; shown = false; }).catch(() => {});
}, delay);
}
function update(phase, raid) {
root(); clearTimeout(hideTimer);
const viewers = raid.viewers != null ? `with ${raid.viewers} of you, be nice! ♡` : 'with all of you, be nice! ♡';
if (phase === 'start') {
startedAt = raid.started_at ? Date.parse(raid.started_at) : Date.now();
render(raid, viewers, '');
enter(); clearInterval(timer); timer = setInterval(tick, 500); tick();
} else if (phase === 'done') {
clearInterval(timer);
render(raid, 'raid sent! see you there ♡', 'GO GO GO');
enter(); leave(6000);
} else if (phase === 'cancel') {
clearInterval(timer);
if (!shown) return;
const w = el.querySelector('.when'); if (w) w.textContent = 'cancelled';
leave(1500);
}
}
window.RaidCard = { update };
})();