Add Redeems: channel points, built-in rewards and bits Power-ups
- reward_variations (src/db.js in the wiring commit): each trigger has variations, one is picked at random weighted by rarity (Common 50 / Uncommon 25 / Rare 12 / Ultra Rare 3), like Twitch alert variations. - /redeems page: rewards listed live from Twitch, plus Power-ups and built-in rewards; per variation name, rarity (with % chance), sound + volume, show cassette or sound only, caption, sticker, on/off, play/test/two-click delete. - Special styles: Gigantify -> giant emote, Celebration -> bouncing emotes, Highlight my message / Message Effect -> big taped note. - redeems-seed.json: first-run defaults rebuilt from the Twitch alert setup (96 variations, 21 triggers); only loaded when the table is empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1766e37336
commit
553cc35b9e
4 changed files with 372 additions and 0 deletions
132
views/redeems.ejs
Normal file
132
views/redeems.ejs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
<style>
|
||||
.trig { border:1px solid var(--pico-muted-border-color); border-radius:10px; padding:.4rem .9rem; margin-bottom:.6rem; }
|
||||
.trig > summary { display:flex; align-items:center; gap:.6rem; flex-wrap:wrap; cursor:pointer; }
|
||||
.trig > summary img { width:22px; height:22px; }
|
||||
.trig .meta { color:var(--pico-muted-color); font-size:.85rem; }
|
||||
.var { display:grid; grid-template-columns: 1.4fr 1fr 2fr .8fr; gap:.4rem .6rem; align-items:end;
|
||||
padding:.6rem 0; border-top:1px dashed var(--pico-muted-border-color); }
|
||||
.var label { font-size:.75rem; margin:0; color:var(--pico-muted-color); }
|
||||
.var input, .var select { margin:0; padding:.3rem .5rem; font-size:.85rem; height:auto; }
|
||||
.var input[type=checkbox] { padding:0; }
|
||||
.var .row2 { grid-column: 1 / -1; display:flex; gap:.6rem; flex-wrap:wrap; align-items:center; }
|
||||
.var .row2 .grow { flex:1; min-width:220px; }
|
||||
.var button { margin:0; padding:.25rem .7rem; font-size:.8rem; width:auto; }
|
||||
.var.off { opacity:.55; }
|
||||
.chance { font-size:.8rem; color:var(--pico-muted-color); }
|
||||
.btn-sm { margin:0; padding:.25rem .7rem; font-size:.8rem; width:auto; }
|
||||
.danger { color:#f88; border-color:#f88; }
|
||||
.warn { color:#e6b800; }
|
||||
@media (max-width: 800px) { .var { grid-template-columns: 1fr 1fr; } }
|
||||
</style>
|
||||
|
||||
<h2>Redeems</h2>
|
||||
<p class="meta">
|
||||
Each redeem plays <strong>one</strong> of its enabled variations, picked at random by rarity
|
||||
(<% for (const [k, r] of Object.entries(rarity)) { %><%= r.label %> <%= r.weight %><% if (k !== 'ultra_rare') { %> · <% } %><% } %>, relative weights).
|
||||
Sounds: built-in library, or upload more on the <a href="/media">Media</a> page.
|
||||
<% if (!twitchOk) { %><br><span class="warn">Could not load your rewards from Twitch right now, so only rewards that already have variations are listed.</span><% } %>
|
||||
</p>
|
||||
|
||||
<% for (const g of groups) { %>
|
||||
<h3 style="margin-top:1.5rem;"><%= g.name %></h3>
|
||||
<% for (const t of g.items) {
|
||||
const on = t.variations.filter(v => v.enabled);
|
||||
const total = on.reduce((s, v) => s + (rarity[v.rarity]?.weight || 1), 0);
|
||||
const anchor = `t-${t.kind}-${t.key}`; %>
|
||||
<details class="trig" id="<%= anchor %>">
|
||||
<summary>
|
||||
<% if (t.image) { %><img src="<%= t.image %>" alt=""><% } %>
|
||||
<strong><%= t.title %></strong>
|
||||
<% if (t.cost != null) { %><span class="meta"><%= t.cost %> pts</span><% } %>
|
||||
<% if (t.missing) { %><span class="badge badge-red">not on Twitch anymore</span><% } %>
|
||||
<% if (t.live === false) { %><span class="badge badge-grey">paused on Twitch</span><% } %>
|
||||
<span class="meta">
|
||||
<%= t.variations.length ? `${on.length}/${t.variations.length} variation${t.variations.length === 1 ? '' : 's'} on` : 'no alert' %>
|
||||
</span>
|
||||
<% if (on.length) { %>
|
||||
<button type="button" class="outline btn-sm" data-test-trigger data-kind="<%= t.kind %>" data-key="<%= t.key %>">Test random</button>
|
||||
<% } %>
|
||||
</summary>
|
||||
|
||||
<% for (const v of t.variations) { %>
|
||||
<form method="POST" action="/redeems/variation/<%= v.id %>" class="var<%= v.enabled ? '' : ' off' %>">
|
||||
<div><label>Name (cassette label)</label><input name="name" value="<%= v.name %>" required></div>
|
||||
<div><label>Rarity</label>
|
||||
<select name="rarity">
|
||||
<% for (const [k, r] of Object.entries(rarity)) { %><option value="<%= k %>" <%= v.rarity === k ? 'selected' : '' %>><%= r.label %></option><% } %>
|
||||
</select>
|
||||
<% if (v.enabled && total) { %><span class="chance"><%= Math.round(100 * (rarity[v.rarity]?.weight || 1) / total) %>% chance</span><% } %>
|
||||
</div>
|
||||
<div><label>Sound</label>
|
||||
<select name="sound" data-sound>
|
||||
<option value="">— silent —</option>
|
||||
<% for (const s of sounds) { %><option value="<%= s.url %>" <%= v.sound === s.url ? 'selected' : '' %>><%= s.label %></option><% } %>
|
||||
</select>
|
||||
</div>
|
||||
<div><label>Volume</label><input type="number" name="volume" min="0" max="1" step="0.05" value="<%= v.volume %>"></div>
|
||||
<div class="row2">
|
||||
<label><input type="checkbox" name="enabled" <%= v.enabled ? 'checked' : '' %>> on</label>
|
||||
<label title="Off = only the sound plays, no cassette on screen (still waits its turn in the queue)"><input type="checkbox" name="polaroid" <%= v.polaroid ? 'checked' : '' %>> show cassette</label>
|
||||
<span class="grow"><input name="caption" value="<%= v.caption %>" title="Text after the viewer's name on the paper strip. {reward} = reward name, {variation} = this variation's name. The viewer's typed message is added automatically."></span>
|
||||
<select name="art" style="width:auto;" title="Sticker in the cassette's corner">
|
||||
<option value="">sticker: headset Streamer</option>
|
||||
<% for (const st of stickers) { %><option value="<%= st.url %>" <%= v.art === st.url ? 'selected' : '' %>>sticker: <%= st.label %></option><% } %>
|
||||
</select>
|
||||
<button type="button" class="outline btn-sm" data-play title="Play the sound here in the browser">▶</button>
|
||||
<button type="submit" class="btn-sm">Save</button>
|
||||
<button type="button" class="outline btn-sm" data-test-var="<%= v.id %>" title="Show it on the overlay">Test</button>
|
||||
<button type="button" class="outline btn-sm danger" data-del>Delete</button>
|
||||
<button type="submit" class="btn-sm danger" data-del-confirm formaction="/redeems/variation/<%= v.id %>/delete" hidden>Really delete</button>
|
||||
</div>
|
||||
</form>
|
||||
<% } %>
|
||||
|
||||
<form method="POST" action="/redeems/variation" style="margin:.5rem 0 .3rem;">
|
||||
<input type="hidden" name="kind" value="<%= t.kind %>">
|
||||
<input type="hidden" name="key" value="<%= t.key %>">
|
||||
<input type="hidden" name="title" value="<%= t.title %>">
|
||||
<button type="submit" class="outline btn-sm">+ Add variation</button>
|
||||
</form>
|
||||
</details>
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
<p><small id="redeem-status"></small></p>
|
||||
|
||||
<script>
|
||||
(() => {
|
||||
const status = document.getElementById('redeem-status');
|
||||
const say = t => { status.textContent = t; };
|
||||
// open the trigger we just edited
|
||||
if (location.hash) { const d = document.getElementById(decodeURIComponent(location.hash.slice(1))); if (d) d.open = true; }
|
||||
|
||||
let player = null;
|
||||
document.querySelectorAll('[data-play]').forEach(b => b.addEventListener('click', () => {
|
||||
const url = b.closest('form').querySelector('[data-sound]').value;
|
||||
if (player) player.pause();
|
||||
if (!url) return say('No sound selected');
|
||||
player = new Audio(url);
|
||||
player.volume = parseFloat(b.closest('form').querySelector('[name=volume]').value) || 0.8;
|
||||
player.play().catch(e => say('Could not play: ' + e.message));
|
||||
}));
|
||||
|
||||
const post = async (url, body) => {
|
||||
try {
|
||||
const r = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) });
|
||||
say(r.ok ? 'Sent to overlay (save first if you changed something)' : `Failed (${r.status})`);
|
||||
} catch (e) { say('Failed: ' + e.message); }
|
||||
};
|
||||
document.querySelectorAll('[data-test-var]').forEach(b => b.addEventListener('click', () => post(`/redeems/variation/${b.dataset.testVar}/test`)));
|
||||
document.querySelectorAll('[data-test-trigger]').forEach(b => b.addEventListener('click', e => {
|
||||
e.preventDefault(); // inside <summary>: do not toggle
|
||||
post('/redeems/trigger/test', { kind: b.dataset.kind, key: b.dataset.key });
|
||||
}));
|
||||
|
||||
// two-step delete, no browser dialog
|
||||
document.querySelectorAll('[data-del]').forEach(b => b.addEventListener('click', () => {
|
||||
const c = b.parentElement.querySelector('[data-del-confirm]');
|
||||
b.hidden = true; c.hidden = false;
|
||||
setTimeout(() => { b.hidden = false; c.hidden = true; }, 4000);
|
||||
}));
|
||||
})();
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue