Tiered goals: ordered milestones with unlocks, tier-aware goal bar, TIER UNLOCKED alerts, next-unlock line
- Tiers\TierPolicy (pure), TierRepository (atomic reached marking), Tiers\Recorder hooked before close-at-target - Admin tiers screen; goal target derived from the final tier - Overlay goal widget shows Tier N of M and fills within the tier; alert pill; donate form 'Next unlock' - Installer DB_VERSION 4 (sg_goal_tiers) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
39840a20d7
commit
4c379a0245
20 files changed
+1089
-14
No files matched your search
@@ -35,3 +35,6 @@
|
||||
.sg-donate label.sg-inline input[type=checkbox]{flex:none;width:22px;height:22px;margin:0}
|
||||
.sg-donate .sg-cover{gap:.25rem}
|
||||
.sg-donate .sg-act-title,.sg-donate .sg-act-desc,.sg-donate .sg-tip,.sg-donate .sg-msg,.sg-donate .sg-total{overflow-wrap:anywhere}
|
||||
|
||||
.sg-donate .sg-next-unlock{margin:0 0 .9rem;padding:.5rem .75rem;border:1px solid rgba(128,128,128,.5);border-left-width:4px;border-radius:.4rem;font-weight:600;line-height:1.4;overflow-wrap:anywhere}
|
||||
.sg-donate .sg-next-unlock[hidden]{display:none}
|
||||
+14
-2
@@ -82,6 +82,18 @@
|
||||
var status = el('div', { 'class': 'sg-msg', role: 'status' });
|
||||
var buttons = el('div', { 'class': 'sg-buttons' });
|
||||
|
||||
// "Next unlock" line for tiered goals (server computes title + remaining minor units per goal).
|
||||
var nextLine = el('p', { 'class': 'sg-next-unlock', 'aria-live': 'polite' });
|
||||
nextLine.hidden = true;
|
||||
function showNext() {
|
||||
var n = state.goal.nextUnlock;
|
||||
if (!n || !n.title || !(n.remaining_minor > 0)) { nextLine.hidden = true; nextLine.textContent = ''; return; }
|
||||
nextLine.textContent = String(T.nextUnlock || 'Next unlock: %1$s \u2014 %2$s to go')
|
||||
.replace('%1$s', function () { return n.title; })
|
||||
.replace('%2$s', function () { return fmt(n.remaining_minor, state.goal.exp, state.goal.currency); });
|
||||
nextLine.hidden = false;
|
||||
}
|
||||
root.appendChild(nextLine);
|
||||
if (goals.length > 1) { root.appendChild(row([el('label', { 'for': uid + '-goal', text: T.goal }), goalSel])); }
|
||||
root.appendChild(row([el('label', { text: T.amount }), presetBox, el('label', { 'class': 'sg-sub', 'for': uid + '-amt', text: T.customAmount || 'Or enter your own amount' }), amount, hint]));
|
||||
var nameRow = row([el('label', { 'for': uid + '-name', text: T.name }), name]);
|
||||
@@ -223,9 +235,9 @@
|
||||
|
||||
goalSel.addEventListener('change', function () {
|
||||
state.goal = goals.filter(function (g) { return String(g.id) === goalSel.value; })[0] || goals[0];
|
||||
buildPresets(); refresh(); renderButtons();
|
||||
showNext(); buildPresets(); refresh(); renderButtons();
|
||||
});
|
||||
buildPresets(); refresh(); renderButtons();
|
||||
showNext(); buildPresets(); refresh(); renderButtons();
|
||||
}
|
||||
|
||||
function boot() { Array.prototype.forEach.call(document.querySelectorAll('.sg-donate'), init); }
|
||||
|
||||
@@ -49,3 +49,13 @@ body.sg-offline #sg-root{opacity:.6}
|
||||
.sg-menu-track.sg-scrolling{animation:sg-scroll var(--sg-scroll-s,20s) linear infinite}
|
||||
@keyframes sg-scroll{from{transform:translateY(0)}to{transform:translateY(-50%)}}
|
||||
@media (prefers-reduced-motion:reduce){.sg-menu-track.sg-scrolling{animation:none}}
|
||||
|
||||
/* Tiered goals */
|
||||
.sg-tier{font-size:.85em;font-weight:600;margin-bottom:.3em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--sg-accent2)}
|
||||
.sg-tier[hidden]{display:none}
|
||||
.sg-card.sg-tiers-done .sg-tier{font-weight:800}
|
||||
.sg-card.sg-tier-up{animation:sg-tier-pop 1.1s cubic-bezier(.22,1,.36,1) 2,sg-tier-glow 1.3s ease-in-out 2}
|
||||
.sg-bonus-line.sg-tier-line{background:linear-gradient(90deg,#f59e0b,#ef4444);color:#fff;border-radius:.3em;letter-spacing:.04em}
|
||||
@keyframes sg-tier-pop{0%{transform:scale(1)}30%{transform:scale(1.06)}100%{transform:scale(1)}}
|
||||
@keyframes sg-tier-glow{0%,100%{box-shadow:0 0 0 transparent}50%{box-shadow:0 0 1em #f59e0b,0 0 2em var(--sg-accent2)}}
|
||||
@media (prefers-reduced-motion:reduce){.sg-card.sg-tier-up{animation:none;box-shadow:0 0 .8em #f59e0b}}
|
||||
@@ -16,26 +16,52 @@
|
||||
}
|
||||
|
||||
// ---- goal ----
|
||||
var goal = null, shownRaised = 0, raf = 0;
|
||||
var goal = null, shownRaised = 0, raf = 0, lastTierKey = null, celebrateTimer = 0;
|
||||
function renderGoal(d) {
|
||||
if (!d.active) { root.textContent = ''; goal = null; return; }
|
||||
if (!d.active) { root.textContent = ''; goal = null; lastTierKey = null; return; }
|
||||
if (!goal) {
|
||||
root.textContent = '';
|
||||
var card = el('div', 'sg-card');
|
||||
goal = { title: el('div', 'sg-title'), fill: el('div', 'sg-fill'), pct: el('div', 'sg-pct'),
|
||||
goal = { card: card, tier: el('div', 'sg-tier'), title: el('div', 'sg-title'), fill: el('div', 'sg-fill'), pct: el('div', 'sg-pct'),
|
||||
raised: el('span'), target: el('span') };
|
||||
var track = el('div', 'sg-track');
|
||||
track.appendChild(goal.fill); track.appendChild(goal.pct);
|
||||
var nums = el('div', 'sg-nums'); nums.appendChild(goal.raised); nums.appendChild(goal.target);
|
||||
card.appendChild(goal.title); card.appendChild(track); card.appendChild(nums);
|
||||
goal.tier.hidden = true;
|
||||
card.appendChild(goal.title); card.appendChild(goal.tier); card.appendChild(track); card.appendChild(nums);
|
||||
root.appendChild(card);
|
||||
}
|
||||
goal.title.textContent = d.title;
|
||||
goal.target.textContent = d.target_display;
|
||||
goal.fill.style.width = d.percent + '%';
|
||||
goal.pct.textContent = d.percent + '%';
|
||||
renderTier(d.tiers);
|
||||
tweenRaised(d);
|
||||
}
|
||||
// Tiered goals only (d.tiers present): "Tier 2 of 4 \u00b7 title" above the bar, or "All tiers unlocked!".
|
||||
// Untiered goals keep the tier line hidden, so they look exactly as before. textContent only.
|
||||
function renderTier(t) {
|
||||
var valid = t && typeof t === 'object' && isFinite(Number(t.count)) && Number(t.count) > 0;
|
||||
goal.tier.hidden = !valid;
|
||||
goal.card.classList.toggle('sg-tiered', !!valid);
|
||||
goal.card.classList.toggle('sg-tiers-done', !!(valid && t.all_reached));
|
||||
if (!valid) { goal.tier.textContent = ''; lastTierKey = null; return; }
|
||||
var cur = t.current && typeof t.current === 'object' ? t.current : null;
|
||||
goal.tier.textContent = t.all_reached || !cur
|
||||
? 'All tiers unlocked!'
|
||||
: 'Tier ' + parseInt(t.index, 10) + ' of ' + parseInt(t.count, 10) + ' \u00b7 ' + String(cur.title || '');
|
||||
// Celebrate when the current tier changed between polls (never on the first poll / after a reload).
|
||||
var key = (t.all_reached ? 'done' : String(t.index)) + '/' + t.count;
|
||||
if (lastTierKey !== null && lastTierKey !== key) {
|
||||
goal.card.classList.remove('sg-tier-up');
|
||||
void goal.card.offsetWidth; // restart the animation
|
||||
goal.card.classList.add('sg-tier-up');
|
||||
clearTimeout(celebrateTimer);
|
||||
var card = goal.card;
|
||||
celebrateTimer = setTimeout(function () { card.classList.remove('sg-tier-up'); }, 2600);
|
||||
}
|
||||
lastTierKey = key;
|
||||
}
|
||||
function tweenRaised(d) {
|
||||
cancelAnimationFrame(raf);
|
||||
var from = shownRaised, to = d.raised_minor, t0 = performance.now(), dur = 1200;
|
||||
@@ -203,11 +229,16 @@
|
||||
}
|
||||
}
|
||||
var acts = Array.isArray(a.actions) ? a.actions : [];
|
||||
if (acts.length) card.classList.add('sg-bonus');
|
||||
var tiersUnlocked = Array.isArray(a.tiers) ? a.tiers : [];
|
||||
if (acts.length || tiersUnlocked.length) card.classList.add('sg-bonus');
|
||||
for (var k = 0; k < acts.length; k++) {
|
||||
var times = parseInt(acts[k].times, 10) || 1;
|
||||
card.appendChild(el('div', 'sg-bonus-line', 'ACTION: ' + String(acts[k].title) + (times > 1 ? ' x' + times : '')));
|
||||
}
|
||||
for (var q = 0; q < tiersUnlocked.length; q++) {
|
||||
var tt = tiersUnlocked[q] && tiersUnlocked[q].title;
|
||||
if (tt) card.appendChild(el('div', 'sg-bonus-line sg-tier-line', 'TIER UNLOCKED: ' + String(tt)));
|
||||
}
|
||||
if (a.message) card.appendChild(el('div', 'sg-alert-msg', a.message));
|
||||
root.appendChild(card);
|
||||
|
||||
|
||||
Reference in new issue
Block a user