diff --git a/Dockerfile b/Dockerfile index 4dc953c..d6aaa02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM node:22-alpine WORKDIR /app +# badge cards: the player's name and earnings are stamped onto the artwork with ffmpeg +RUN apk add --no-cache ffmpeg COPY package.json ./ RUN npm install --omit=dev --no-audit --no-fund COPY . . diff --git a/lib/badge.js b/lib/badge.js new file mode 100644 index 0000000..fce4b10 --- /dev/null +++ b/lib/badge.js @@ -0,0 +1,43 @@ +// Badge cards for Telegram (Marty, 2026-09-30: "unlocks posted on Telegram with some catchy-looking badges, +// along with how much they earned"). The artwork is pre-rendered (public/badges/.png, 1080x1080, +// tools/render-badges.mjs) with a blank plate at the bottom; ffmpeg stamps the player's name and the +// earnings line onto the plate when a card is posted. Cached on the volume: DATA_DIR/badges/. +'use strict'; +const fs = require('fs'); +const path = require('path'); +const crypto = require('crypto'); +const { spawn } = require('child_process'); + +const BADGES = { + magnet: 'Drip Magnet', ship: 'Courier Mk II', shield: 'Shield Core', slow: 'Slow Field', + ch1: 'First Chapter', ch3: 'Chapter 3', ch5: 'Chapter 5', ch10: 'Chapter 10', ch15: 'Chapter 15', ch20: 'Chapter 20', + refuel5: 'Five Refuels', refuel25: '25 Refuels', refuel100: '100 Refuels', paid: 'Paid in POL' +}; +const CHAPTER_BADGES = { 1: 'ch1', 3: 'ch3', 5: 'ch5', 10: 'ch10', 15: 'ch15', 20: 'ch20' }; +const REFUEL_BADGES = { 5: 'refuel5', 25: 'refuel25', 100: 'refuel100' }; +let PUBLIC_DIR = null, CACHE_DIR = null; +function init(opts) { PUBLIC_DIR = opts.publicDir; CACHE_DIR = path.join(opts.dataDir, 'badges'); try { fs.mkdirSync(CACHE_DIR, { recursive: true }); } catch (e) {} } +const art = id => path.join(PUBLIC_DIR, 'badges', id + '.png'); +function font(name) { const f = path.join(PUBLIC_DIR, 'fonts', name); if (fs.existsSync(f)) return f; for (const d of ['/usr/share/fonts/truetype/dejavu', '/usr/share/fonts/dejavu', '/usr/share/fonts/TTF']) { const g = path.join(d, 'DejaVuSans-Bold.ttf'); if (fs.existsSync(g)) return g; } return null; } +const ffText = t => String(t).replace(/\\/g, '\\\\').replace(/'/g, "\u2019").replace(/:/g, '\\:').replace(/%/g, '%%').replace(/,/g, '\\,'); +// ffmpeg filter paths: forward slashes, drive colon escaped +const ffPath = p => String(p).replace(/\\/g, '/').replace(/:/g, '\\:'); + +// the card: name on the plate's upper line, the earnings line under it +function render(id, who, line2, tag) { + return new Promise(resolve => { + if (!BADGES[id] || !fs.existsSync(art(id))) return resolve(null); + const f1 = font('Orbitron-Bold.ttf'), f2 = font('Manrope-Bold.ttf'); if (!f1 || !f2) return resolve(null); + const name = String(who || '').slice(0, 24), sub = String(line2 || '').slice(0, 70), tg = String(tag || '').slice(0, 40); + const out = path.join(CACHE_DIR, id + '-' + crypto.createHash('sha1').update(name + '|' + sub + '|' + tg).digest('hex').slice(0, 12) + '.jpg'); + if (fs.existsSync(out)) return resolve(out); + const vf = "drawtext=fontfile='" + ffPath(f1) + "':text='" + ffText(name) + "':fontcolor=#FFFFFF:fontsize=62:borderw=3:bordercolor=#22D3EE@0.9:shadowcolor=#000000@0.6:shadowx=0:shadowy=4:x=(w-text_w)/2:y=808" + + ",drawtext=fontfile='" + ffPath(f2) + "':text='" + ffText(sub) + "':fontcolor=#FFC24B:fontsize=36:x=(w-text_w)/2:y=910" + + (tg ? ",drawtext=fontfile='" + ffPath(f2) + "':text='" + ffText(tg) + "':fontcolor=#FF6A1A:fontsize=24:x=(w-text_w)/2:y=771" : ''); // Manrope: Orbitron has no middle dot + const p = spawn('ffmpeg', ['-v', 'error', '-y', '-i', art(id), '-vf', vf, '-frames:v', '1', '-q:v', '3', out], { stdio: ['ignore', 'ignore', 'pipe'] }); + let err = ''; p.stderr.on('data', c => { err += c; }); + p.on('error', () => resolve(null)); + p.on('close', code => { if (code === 0 && fs.existsSync(out)) resolve(out); else { console.error('badge render failed', code, err.slice(0, 300)); resolve(null); } }); + }); +} +module.exports = { BADGES, CHAPTER_BADGES, REFUEL_BADGES, init, render }; diff --git a/lib/ledger.js b/lib/ledger.js index 8747beb..bc55064 100644 --- a/lib/ledger.js +++ b/lib/ledger.js @@ -25,6 +25,7 @@ const DEFAULTS = { itemPol: { shield: 0.05, slow: 0.03 }, // hangar items paid from the POL balance (the sink) itemDrips: { magnet: 250, ship: 600 }, // hangar items paid in drips (never money) testers: [], // emails or member ids allowed through the hand-off while signups = 'testers' + trial: true, // posts say 'coming soon, in testing' and 'would have earned' until Marty flips it signups: 'testers' // 'testers' | 'key' (tester list or the curtain pass) | 'open' | 'closed' }; function settings() { return Object.assign({}, DEFAULTS, store.read('settings', {})); } diff --git a/public/admin.html b/public/admin.html index bece6ff..279ece5 100644 --- a/public/admin.html +++ b/public/admin.html @@ -31,6 +31,7 @@
+
diff --git a/public/admin.js b/public/admin.js index 695aa73..960785a 100644 --- a/public/admin.js +++ b/public/admin.js @@ -22,7 +22,7 @@ function load() { var s = d.settings, form = $('settings'); ['dripPol', 'dailyCapPol', 'thresholdPol', 'seedPol', 'poolSharePct', 'creditsPerVisit', 'usdPerCredit', 'usdPerPolFallback', 'lowBalancePol', 'signups'].forEach(function (k) { form.elements[k].value = s[k]; }); form.elements.item_shield.value = s.itemPol.shield; form.elements.item_slow.value = s.itemPol.slow; form.elements.item_magnet.value = s.itemDrips.magnet; form.elements.item_ship.value = s.itemDrips.ship; - form.elements.testers.value = (s.testers || []).join('\n'); + form.elements.testers.value = (s.testers || []).join('\n'); form.elements.trial.value = s.trial === false ? 'off' : 'on'; table('players', [['Member', function (r) { return '#' + r.memberId + (r.username ? ' @' + esc(r.username) : '') + '
' + esc(r.email || '') + ''; }], ['Wallet', function (r) { return r.wallet ? r.wallet.slice(0, 6) + '…' + r.wallet.slice(-4) : 'none'; }], ['Chapter', 'chapter', 1], ['Drips', 'bank', 1], ['Best', 'best', 1], ['Runs', 'runs', 1], ['Armed', function (r) { return Object.keys(r.items || {}).join(', '); }], ['Last seen', function (r) { return ct(r.lastSeen); }]], d.players); table('refuels', [['When', function (r) { return ct(r.ts); }], ['Member', function (r) { return '#' + r.memberId + (r.username ? ' @' + esc(r.username) : ''); }], ['Campaign', 'campaignId'], ['Credits', 'credits', 1], ['Ad $', function (r) { return f4(r.usd); }, 1], ['Share $', function (r) { return f4(r.share); }, 1], ['POL to pool', function (r) { return f4(r.pol); }, 1], ['Via', 'via']], d.refuels); table('drips', [['When', function (r) { return ct(r.ts); }], ['Member', function (r) { return '#' + r.memberId + (r.username ? ' @' + esc(r.username) : ''); }], ['Chapter', 'chapter', 1], ['POL', function (r) { return f4(r.pol); }, 1]], d.drips); @@ -35,7 +35,7 @@ $('settings').addEventListener('submit', function (e) { e.preventDefault(); var f = e.target.elements; var body = {}; ['dripPol', 'dailyCapPol', 'thresholdPol', 'seedPol', 'poolSharePct', 'creditsPerVisit', 'usdPerCredit', 'usdPerPolFallback', 'lowBalancePol', 'signups'].forEach(function (k) { body[k] = f[k].value; }); body.itemPol = { shield: Number(f.item_shield.value), slow: Number(f.item_slow.value) }; body.itemDrips = { magnet: Number(f.item_magnet.value), ship: Number(f.item_ship.value) }; - body.testers = f.testers.value.split(/\r?\n/).map(function (x) { return x.trim(); }).filter(Boolean); + body.trial = f.trial.value; body.testers = f.testers.value.split(/\r?\n/).map(function (x) { return x.trim(); }).filter(Boolean); api('/api/admin/settings', body).then(function (r) { $('saveOut').textContent = r.ok ? 'Saved.' : (r.error || 'Failed'); load(); }); }); $('tick').addEventListener('click', function () { $('tickOut').textContent = 'running…'; api('/api/admin/faucet/tick', {}).then(function (r) { $('tickOut').textContent = JSON.stringify(r); load(); }); }); diff --git a/public/badges/ch1.png b/public/badges/ch1.png new file mode 100644 index 0000000..d0a3154 Binary files /dev/null and b/public/badges/ch1.png differ diff --git a/public/badges/ch10.png b/public/badges/ch10.png new file mode 100644 index 0000000..dfdd658 Binary files /dev/null and b/public/badges/ch10.png differ diff --git a/public/badges/ch15.png b/public/badges/ch15.png new file mode 100644 index 0000000..e0b4db7 Binary files /dev/null and b/public/badges/ch15.png differ diff --git a/public/badges/ch20.png b/public/badges/ch20.png new file mode 100644 index 0000000..b9fa2b0 Binary files /dev/null and b/public/badges/ch20.png differ diff --git a/public/badges/ch3.png b/public/badges/ch3.png new file mode 100644 index 0000000..a7893ff Binary files /dev/null and b/public/badges/ch3.png differ diff --git a/public/badges/ch5.png b/public/badges/ch5.png new file mode 100644 index 0000000..fbc7878 Binary files /dev/null and b/public/badges/ch5.png differ diff --git a/public/badges/magnet.png b/public/badges/magnet.png new file mode 100644 index 0000000..2380864 Binary files /dev/null and b/public/badges/magnet.png differ diff --git a/public/badges/paid.png b/public/badges/paid.png new file mode 100644 index 0000000..68bc24b Binary files /dev/null and b/public/badges/paid.png differ diff --git a/public/badges/refuel100.png b/public/badges/refuel100.png new file mode 100644 index 0000000..d8ba414 Binary files /dev/null and b/public/badges/refuel100.png differ diff --git a/public/badges/refuel25.png b/public/badges/refuel25.png new file mode 100644 index 0000000..2427dd4 Binary files /dev/null and b/public/badges/refuel25.png differ diff --git a/public/badges/refuel5.png b/public/badges/refuel5.png new file mode 100644 index 0000000..bdd2a1c Binary files /dev/null and b/public/badges/refuel5.png differ diff --git a/public/badges/shield.png b/public/badges/shield.png new file mode 100644 index 0000000..3f161e8 Binary files /dev/null and b/public/badges/shield.png differ diff --git a/public/badges/ship.png b/public/badges/ship.png new file mode 100644 index 0000000..3ff3778 Binary files /dev/null and b/public/badges/ship.png differ diff --git a/public/badges/slow.png b/public/badges/slow.png new file mode 100644 index 0000000..f823031 Binary files /dev/null and b/public/badges/slow.png differ diff --git a/public/fonts/Manrope-Bold.ttf b/public/fonts/Manrope-Bold.ttf new file mode 100644 index 0000000..1925480 Binary files /dev/null and b/public/fonts/Manrope-Bold.ttf differ diff --git a/public/fonts/Orbitron-Bold.ttf b/public/fonts/Orbitron-Bold.ttf new file mode 100644 index 0000000..fa5b6bf Binary files /dev/null and b/public/fonts/Orbitron-Bold.ttf differ diff --git a/server.js b/server.js index a66686d..6040272 100644 --- a/server.js +++ b/server.js @@ -22,6 +22,7 @@ const game = require('./lib/game'); const ledger = require('./lib/ledger'); const faucet = require('./lib/faucet'); const spawn = require('./lib/spawn'); +const badge = require('./lib/badge'); const PORT = Number(process.env.PORT || 3000); const DATA_DIR = process.env.DATA_DIR || path.join(__dirname, 'data'); @@ -35,6 +36,7 @@ const outbound = () => process.env.OUTBOUND === 'on'; const IS_PROD = process.env.NODE_ENV === 'production'; store.init(DATA_DIR); +badge.init({ publicDir: PUBLIC_DIR, dataDir: DATA_DIR }); const faucetOn = faucet.init(); // ---- Telegram to Marty (outward: gated) ------------------------------------------------------- @@ -44,10 +46,49 @@ async function telegram(text) { try { const r = await fetch('https://api.telegram.org/bot' + tok + '/sendMessage', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ chat_id: chat, text, parse_mode: 'HTML', disable_web_page_preview: true }) }); return r.ok; } catch (e) { return false; } } const fmt = n => Number(n).toLocaleString('en-US', { maximumFractionDigits: 4 }); +// ---- public badge posts (Marty, 2026-09-30): unlocks, chapter and refuel milestones, payouts, as photo cards ---- +// DR_TG_PUBLIC_CHAT / DR_TG_PUBLIC_TOPIC = the room (PolHunter's), DR_TG_PUBLIC_GENERAL=on also posts the photo to the general channel. +async function telegramPhoto(file, caption, general) { + if (!outbound()) return false; + const tok = process.env.DR_TG_TOKEN, chat = process.env.DR_TG_PUBLIC_CHAT || process.env.DR_TG_CHAT, topic = process.env.DR_TG_PUBLIC_CHAT ? process.env.DR_TG_PUBLIC_TOPIC : null; + if (!tok || !chat || !file) return false; + try { + const fd = new FormData(); fd.append('chat_id', chat); fd.append('caption', caption); fd.append('parse_mode', 'HTML'); if (topic && !general) fd.append('message_thread_id', String(topic)); + fd.append('photo', new Blob([fs.readFileSync(file)], { type: 'image/jpeg' }), 'badge.jpg'); + const r = await fetch('https://api.telegram.org/bot' + tok + '/sendPhoto', { method: 'POST', body: fd }); return r.ok; + } catch (e) { return false; } +} +const nameOf = me => me.username ? '@' + me.username : '#' + me.memberId; +const trial = () => ledger.settings().trial !== false; // Marty, 2026-09-30: while testing, say so, and show what they WOULD have earned once live +function earningsLine(memberId) { + const a = ledger.account(memberId); const p = game.player(memberId) || {}; const refuels = store.read('refuels', []).filter(r => r.memberId === Number(memberId)).length; + return (trial() ? 'would have earned ' : 'earned ') + fmt(a.earnedTotal || 0) + ' POL so far \u00b7 ' + refuels + ' refuel' + (refuels === 1 ? '' : 's') + ' \u00b7 chapter ' + (p.chapter || 1); +} +// one post per (member, badge); a payout card is one per payout row +async function announce(id, me, opts) { + opts = opts || {}; const key = opts.key || id; + const posted = store.read('posted', {}); const mine = new Set(posted[String(me.memberId)] || []); + if (mine.has(key)) return false; + store.update('posted', {}, all => { all[String(me.memberId)] = [...mine, key]; return all; }); + const line2 = opts.line2 || earningsLine(me.memberId); + const file = await badge.render(id, nameOf(me), line2, trial() ? 'COMING SOON \u00b7 NOW IN TESTING' : ''); + const head = trial() ? opts.caption.replace('Drip Runner', 'Drip Runner (coming soon \u00b7 now in testing)') : opts.caption; + const foot = trial() ? 'Testers are playing a preview. When Drip Runner goes live, amounts like this pay out in POL to the wallet on your InstantAdPay account.' : 'Play from your InstantAdPay dashboard.'; + const cap = head + '\n' + line2 + '\n' + foot; + if (!file) return telegram(cap); + const ok = await telegramPhoto(file, cap); + if (ok && String(process.env.DR_TG_PUBLIC_GENERAL || 'off') === 'on') await telegramPhoto(file, cap, true); + return ok; +} +const ITEM_NAMES = { magnet: 'Drip Magnet', ship: 'Courier Mk II', shield: 'Shield Core', slow: 'Slow Field' }; +function announceUnlock(me, item, paid) { if (!badge.BADGES[item]) return; announce(item, me, { caption: '\u{1F3AE} Drip Runner \u00b7 ' + nameOf(me) + ' unlocked the ' + ITEM_NAMES[item] + ' (' + paid + ')' }).catch(() => {}); } +function announceChapter(me, ch, pol) { const id = badge.CHAPTER_BADGES[ch]; if (!id) return; announce(id, me, { caption: '\u{1F3C1} Drip Runner \u00b7 ' + nameOf(me) + ' cleared Chapter ' + ch + '' + (pol ? ' \u00b7 +' + fmt(pol) + ' POL' : '') }).catch(() => {}); } +function announceRefuels(me) { const n = store.read('refuels', []).filter(r => r.memberId === Number(me.memberId)).length; const id = badge.REFUEL_BADGES[n]; if (!id) return; announce(id, me, { caption: '\u26FD Drip Runner \u00b7 ' + nameOf(me) + ' has refuelled ' + n + ' times. Every refuel is a verified visit to a member\u2019s page on InstantAdPay.' }).catch(() => {}); } +function announcePaid(p) { announce('paid', { memberId: p.memberId, username: p.username }, { key: 'paid:' + p.id, caption: '\u{1F4B8} Drip Runner \u00b7 ' + nameOf(p) + ' was paid ' + fmt(p.pol) + ' POL \u00b7 verify', line2: 'paid ' + fmt(p.pol) + ' POL to their wallet \u00b7 ' + earningsLine(p.memberId).replace(/^earned [^\u00b7]+\u00b7 /, '') }).catch(() => {}); } const explorer = () => Number(process.env.DR_CHAIN_ID) === 80002 ? 'https://amoy.polygonscan.com' : 'https://polygonscan.com'; async function notify(kind, p) { const who = p && (p.username ? '@' + p.username : '#' + p.memberId); - if (kind === 'paid') return telegram('\u{1F3AE} Drip Runner · paid ' + who + ' ' + fmt(p.pol) + ' POL · verify'); + if (kind === 'paid') { announcePaid(p); return telegram('\u{1F3AE} Drip Runner · paid ' + who + ' ' + fmt(p.pol) + ' POL · verify'); } if (kind === 'failed') return telegram('❌ Drip Runner · payout to ' + who + ' failed: ' + p.error); if (kind === 'low') return telegram('⚠️ Drip Runner wallet is low: ' + fmt(p.balance) + ' POL in ' + p.address + ' (needs ' + fmt(p.threshold) + ').'); if (kind === 'refused') return telegram('\u{1F6AB} Drip Runner \u00b7 ' + who + ' (' + p.email + ') tried to sign in but is not on the tester list. Add them under Admin > Settings > Testers: ' + SITE + '/admin'); @@ -169,12 +210,22 @@ const server = http.createServer(async (req, res) => { const { body } = await readBody(req); const patch = {}; for (const k of ['usdPerCredit', 'creditsPerVisit', 'poolSharePct', 'usdPerPolFallback', 'dripPol', 'dailyCapPol', 'thresholdPol', 'seedPol', 'lowBalancePol']) if (body[k] != null && body[k] !== '') patch[k] = Number(body[k]); if (body.signups && ['testers', 'key', 'open', 'closed'].includes(body.signups)) patch.signups = body.signups; + if (body.trial === 'on' || body.trial === 'off') patch.trial = body.trial === 'on'; if (Array.isArray(body.testers)) patch.testers = body.testers.map(x => String(x).trim().toLowerCase()).filter(Boolean).slice(0, 500); if (body.itemPol && typeof body.itemPol === 'object') patch.itemPol = Object.assign({}, ledger.settings().itemPol, body.itemPol); if (body.itemDrips && typeof body.itemDrips === 'object') patch.itemDrips = Object.assign({}, ledger.settings().itemDrips, body.itemDrips); return json(res, 200, { ok: true, settings: ledger.setSettings(patch) }); } if (p === '/api/admin/faucet/tick' && req.method === 'POST') return json(res, 200, await faucet.tick(notify)); + if (p === '/api/admin/announce' && req.method === 'POST') { // post (or re-post with force) a badge for a member: {memberId, id} + const { body } = await readBody(req); const pl = game.player(Number(body.memberId)); if (!pl) return json(res, 404, { error: 'no such player' }); + const me = { memberId: pl.memberId, username: pl.username }; const id = String(body.id || ''); + if (body.force) store.update('posted', {}, all => { all[String(pl.memberId)] = (all[String(pl.memberId)] || []).filter(k => k !== id); return all; }); + const ch = Object.keys(badge.CHAPTER_BADGES).find(k => badge.CHAPTER_BADGES[k] === id); + if (ch) { announceChapter(me, Number(ch), 0); return json(res, 200, { ok: true, kind: 'chapter' }); } + if (ITEM_NAMES[id]) { announceUnlock(me, id, 'hangar'); return json(res, 200, { ok: true, kind: 'unlock' }); } + return json(res, 400, { error: 'unknown badge id' }); + } if (p === '/api/admin/handoff' && req.method === 'POST') { // a test token for a synthetic member (local checks only) const { body } = await readBody(req); return json(res, 200, { url: SITE + '/auth?t=' + sso.mint({ memberId: Number(body.memberId) || 999001, email: body.email || 'tester@example.com', wallet: body.wallet || null, username: body.username || 'tester' }) }); } @@ -187,7 +238,7 @@ const server = http.createServer(async (req, res) => { } if (p === '/api/balance' && req.method === 'GET') return json(res, 200, ledger.balance(me.memberId)); if (p === '/api/run/start' && req.method === 'POST') { const { body } = await readBody(req); const r = game.start(me, body.W, body.H); return json(res, 200, { runId: r.id, seed: r.seed, W: r.W, H: r.H, speed: r.speed, chapter: r.chapter, goal: r.goal, armed: r.armed, ship: r.ship }); } - if (p === '/api/run/events' && req.method === 'POST') { const { body } = await readBody(req); const r = game.events(me, String(body.runId || ''), body.t, body.events, !!body.goal); if (r.cleared) r.pool = ledger.pool().available; return json(res, r.error ? 400 : 200, r); } + if (p === '/api/run/events' && req.method === 'POST') { const { body } = await readBody(req); const r = game.events(me, String(body.runId || ''), body.t, body.events, !!body.goal); if (r.cleared) { r.pool = ledger.pool().available; if (r.cleared.first) announceChapter(me, r.cleared.chapter, r.cleared.pol); } return json(res, r.error ? 400 : 200, r); } if (p === '/api/run/end' && req.method === 'POST') { const { body } = await readBody(req); return json(res, 200, game.end(me, String(body.runId || ''))); } // refuel: hand the player to IAP for a verified visit; the run resumes when IAP confirms if (p === '/api/refuel/start' && req.method === 'POST') { @@ -205,10 +256,10 @@ const server = http.createServer(async (req, res) => { // the browser may carry IAP's signed receipt: it counts even when the server callback was slow if (!it.done && body.receipt) { const rc = sso.open(body.receipt); if (rc.ok && rc.claims.kind === 'refuel-receipt' && rc.claims.nonce === nonce) it = await creditRefuel(it, nonce, { campaignId: rc.claims.campaignId, credits: rc.claims.credits, via: 'receipt' }); } if (!it.done) return json(res, 200, { ok: false, reason: body.none ? 'none' : 'unverified' }); - intents.upd(nonce, x => { x.consumed = true; }); game.refuelled(me, it.runId); + intents.upd(nonce, x => { x.consumed = true; }); game.refuelled(me, it.runId); announceRefuels(me); return json(res, 200, { ok: true, pool: ledger.pool().available }); } - if (p === '/api/hangar/buy' && req.method === 'POST') { const { body } = await readBody(req); const r = game.buy(me, String(body.item || '')); if (!r.error) { r.player = game.view(me); r.balance = ledger.balance(me.memberId); } return json(res, r.error ? 400 : 200, r); } + if (p === '/api/hangar/buy' && req.method === 'POST') { const { body } = await readBody(req); const item = String(body.item || ''); const r = game.buy(me, item); if (!r.error) { r.player = game.view(me); r.balance = ledger.balance(me.memberId); announceUnlock(me, item, r.paid); } return json(res, r.error ? 400 : 200, r); } return json(res, 404, { error: 'no such route' }); } res.writeHead(404, Object.assign({ 'Content-Type': 'text/plain' }, SEC)); res.end('Not found'); diff --git a/tools/render-badges.mjs b/tools/render-badges.mjs new file mode 100644 index 0000000..b2772ed --- /dev/null +++ b/tools/render-badges.mjs @@ -0,0 +1,87 @@ +// Renders the badge card artwork (public/badges/.png, 1080x1080) with Playwright, in the game's own +// neon style. The bottom plate is left blank: lib/badge.js stamps the player's name and earnings there +// with ffmpeg when a card is posted. Run locally: node tools/render-badges.mjs +import pkg from 'file:///D:/Projects/MarketingAgent/qa-tester/node_modules/playwright/index.js'; +import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; +const { chromium } = pkg; +const OUT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'public', 'badges'); +fs.mkdirSync(OUT, { recursive: true }); + +export const BADGES = { + magnet: { title: 'Drip Magnet', sub: 'Hangar unlock', kind: 'item', color: '#FFC24B', glyph: 'orb' }, + ship: { title: 'Courier Mk II', sub: 'Hangar unlock', kind: 'item', color: '#8FF0FF', glyph: 'ship' }, + shield: { title: 'Shield Core', sub: 'Hangar unlock · paid in POL', kind: 'item', color: '#FF6A1A', glyph: 'diamond' }, + slow: { title: 'Slow Field', sub: 'Hangar unlock · paid in POL', kind: 'item', color: '#A78BFA', glyph: 'dome' }, + ch1: { title: 'First Chapter', sub: 'Chapter 1 cleared', kind: 'chapter', color: '#8FF0FF', glyph: 'hex', n: 1 }, + ch3: { title: 'Chapter 3', sub: 'Three chapters deep', kind: 'chapter', color: '#8FF0FF', glyph: 'hex', n: 3 }, + ch5: { title: 'Chapter 5', sub: 'Halfway to double digits', kind: 'chapter', color: '#FFC24B', glyph: 'hex', n: 5 }, + ch10: { title: 'Chapter 10', sub: 'Double digits', kind: 'chapter', color: '#FFC24B', glyph: 'hex', n: 10 }, + ch15: { title: 'Chapter 15', sub: 'Deep in the network', kind: 'chapter', color: '#FF6A1A', glyph: 'hex', n: 15 }, + ch20: { title: 'Chapter 20', sub: 'Network legend', kind: 'chapter', color: '#FF6A1A', glyph: 'hex', n: 20 }, + refuel5: { title: 'Five Refuels', sub: 'Keeps the run alive', kind: 'refuel', color: '#FF6A1A', glyph: 'fuel' }, + refuel25: { title: '25 Refuels', sub: 'Runs on sponsor pages', kind: 'refuel', color: '#FF6A1A', glyph: 'fuel' }, + refuel100: { title: '100 Refuels', sub: 'Never restarts', kind: 'refuel', color: '#FFC24B', glyph: 'fuel' }, + paid: { title: 'Paid in POL', sub: 'Sent to their wallet', kind: 'paid', color: '#34D399', glyph: 'coin' }, +}; + +function glyph(g, color, n) { + const c = color; + if (g === 'orb') return `
`; + if (g === 'ship') return `
`; + if (g === 'diamond') return `
`; + if (g === 'dome') return `
`; + if (g === 'hex') return `
${n}
`; + if (g === 'fuel') return `
`; + if (g === 'coin') return `
POL
`; + return ''; +} +function html(id, b) { + return ` + + +
+ +
${b.kind === 'paid' ? 'Payout sent' : 'Achievement unlocked'}
+
${glyph(b.glyph, b.color, b.n)}
+
${b.title}
+
${b.sub}
+
+
InstantAdPay members · paid in POL
+`; +} +const browser = await chromium.launch(); const page = await browser.newPage({ viewport: { width: 1080, height: 1080 }, deviceScaleFactor: 1 }); +for (const [id, b] of Object.entries(BADGES)) { + await page.setContent(html(id, b), { waitUntil: 'networkidle' }); await page.evaluate(() => document.fonts.ready); await page.waitForTimeout(300); + await page.screenshot({ path: path.join(OUT, id + '.png'), type: 'png' }); console.log('rendered', id); +} +await browser.close();