Your Claude session and weekly usage limits as an animated villager health card, with a weekly pace hourglass, rank badges and a death screen at 0 HP

Your Claude usage limits as a game health card, drawn above the prompt in Claude Code.
villager-hp is a Claude Code mod (a plugin). It turns your 5-hour session limit and your weekly limit into two health bars, tells you when the week is on pace to run out early, and puts an animated villager beside them who feels every point you spend.

You paste one line. It works even if you only have the Claude desktop app.
powershell and press Enter. A window opens. irm https://raw.githubusercontent.com/Ashley-Pettit/villager-hp/prod/install.ps1 | iex
terminal and press Enter. A window opens. curl -fsSL https://raw.githubusercontent.com/Ashley-Pettit/villager-hp/prod/install.sh | bash
In the Claude desktop app, open the Code tab. The health card sits above where you type. Type /hp 40 and press Enter to see it at 40 HP.
Good to know:
/plugin install villager-hp --marketplace Ashley-Pettit/villager-hp there instead.Two bars, SESSION (your 5-hour limit) and WEEKLY (your weekly limit across all models), show the hit points you have left. HP is 100 minus the percent used, with the time each one resets. An Age of Empires–style villager watches over them, and his mood follows your lowest bar.
/pace tells you when you'd run out. It makes no call in a week's first 12 hours, when one busy sitting would look like a blown week.

| Command | What it does |
|---|---|
/hp | Show both bars and your weekly pace as text |
/hp 40 | Preview the card at any HP from 0 to 100 |
/hp off | Back to your real limits |
/die | Watch Claude die (same as /hp 0) |
/revive | Bring Claude back to your real limits |
/rank top | Change your badge: scout, contributor, innovator, top or god |
/pace | Say whether your weekly limit lasts at this rate, and when it runs out if not |
/pace over | Preview the hourglass warning (/pace ok previews being on track) |
/pace off | Back to your real pace |
In a terminal, an over-pace week adds ⏳ out by Thu 3pm to the WEEKLY row.
It reads your session's usage figures and keeps your chosen rank in its own small store. It makes no network calls, starts no processes, and reads or writes no files of yours.
Readings appear on Claude subscriptions, which report rate-limit windows; on API keys the bars show — until a reading arrives.
/pace. The villager stays cheerful for as long as the bar is green.MIT
hooks/register.tsx 189 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import type { Limit } from '../types'
5import { RANKS, backIn, bars, hudSvg, killer, mood, outBy, weeklyPace } from './hud'
6import type { Pace, Rank } from './hud'
7
8const limitsAtom = atom({ plugin: 'villager-hp', key: 'limits' } as const, [] as Limit[])
9const demoAtom = atom({ plugin: 'villager-hp', key: 'demo' } as const, null as number | null)
10const paceDemoAtom = atom({ plugin: 'villager-hp', key: 'paceDemo' } as const, null as boolean | null)
11const nowAtom = atom({ plugin: 'villager-hp', key: 'now' } as const, 0)
12const rankAtom = atom({ plugin: 'villager-hp', key: 'rank' } as const, 'god' as Rank)
13
14const FACES = { healthy: '(◕‿◕)', hurt: '(•_•)', critical: '(╥﹏╥)', dead: '(x_x)', unknown: '(•‿•)' }
15const SEGMENTS = 20
16// Named by /hp, to tell at a glance which version is loaded.
17const VERSION = '2.8: weekly pace hourglass; the villager stays cheerful for longer'
18// AoE-style: green for what's left, red for what's gone.
19const split = (hp: number) => {
20 const full = Math.round((hp / 100) * SEGMENTS)
21 return { green: '█'.repeat(full), red: '█'.repeat(SEGMENTS - full) }
22}
23
24// The weekly pace in a sentence, for /hp and /pace.
25const paceLine = (pace: Pace | null) =>
26 pace === null
27 ? 'Weekly pace: not enough of the week to go on yet.'
28 : pace.isOver
29 ? `Weekly pace: over. At this rate you're ${outBy(pace.runsOut)}, before the week resets (about ${pace.projected}% of the limit by then).`
30 : `Weekly pace: on track. At this rate about ${pace.projected}% of the limit is used by the reset.`
31
32export const register: Register = on => {
33 on('session.start', async ($, e, next) => {
34 const started = await next(e)
35 await $.command.register({
36 name: 'hp',
37 description: "Show Claude's HP, or preview a level: /hp 10, /hp 0 to die, /hp off for real readings",
38 argumentHint: '[0-100 | off]',
39 })
40 await $.command.register({ name: 'die', description: 'Watch Claude die on the health card (same as /hp 0); /revive to undo' })
41 await $.command.register({ name: 'revive', description: 'Bring Claude back to your real health (same as /hp off)' })
42 await $.command.register({
43 name: 'rank',
44 description: 'Change the rank badge on your health card: /rank scout, contributor, innovator, top, god',
45 argumentHint: '[scout | contributor | innovator | top | god]',
46 })
47 await $.command.register({
48 name: 'pace',
49 description: 'Whether your weekly limit lasts at this rate, or preview the warning: /pace over, /pace ok, /pace off for the real one',
50 argumentHint: '[over | ok | off]',
51 })
52 // The rank you picked, kept across sessions.
53 const saved = await $.store.get('rank')
54 if (typeof saved === 'string' && saved in RANKS) await update($, rankAtom, () => saved as Rank)
55 const usage = await $.session.usage()
56 await update($, limitsAtom, () => usage.rateLimits)
57 await update($, nowAtom, () => Date.now())
58 // Tick each minute so the reset countdowns move.
59 $.clock.every(60_000, () => {
60 void update($, nowAtom, () => Date.now())
61 })
62 return started
63 })
64
65 on('command.run', { command: 'die' }, async $ => {
66 await update($, demoAtom, () => 0)
67 return { text: 'Claude has been defeated. /revive to bring it back.' }
68 })
69
70 on('command.run', { command: 'revive' }, async $ => {
71 await update($, demoAtom, () => null)
72 return { text: 'Claude is back, at your real health.' }
73 })
74
75 on('command.run', { command: 'rank' }, async ($, e) => {
76 const arg = e.args.trim().toLowerCase().replace(/\s+/g, ' ')
77 const aliases: Record<string, Rank> = { 'top contributor': 'top', 'god mode': 'god', godmode: 'god' }
78 const rank = (arg in RANKS ? arg : aliases[arg]) as Rank | undefined
79 if (!rank) {
80 const current = await read($, rankAtom)
81 const list = (Object.keys(RANKS) as Rank[]).map(r => `${r}${r === current ? ' (yours)' : ''}`).join(', ')
82 return { text: arg ? `No rank called "${arg}". Ranks: ${list}.` : `Your rank: ${RANKS[current].name}. Change it with /rank and one of: ${list}.` }
83 }
84 await $.store.set('rank', rank)
85 await update($, rankAtom, () => rank)
86 return { text: `Your badge is now ${RANKS[rank].name}.` }
87 })
88
89 on('command.run', { command: 'pace' }, async ($, e) => {
90 const arg = e.args.trim().toLowerCase()
91 if (arg === 'over' || arg === 'ok') {
92 await update($, paceDemoAtom, () => arg === 'over')
93 return { text: arg === 'over' ? 'Preview: over pace for the week. /pace off for the real one.' : 'Preview: on track for the week. /pace off for the real one.' }
94 }
95 if (arg === 'off' || arg === 'real') await update($, paceDemoAtom, () => null)
96 else if (arg !== '') return { text: 'Use /pace, /pace over, /pace ok or /pace off.' }
97 return { text: paceLine(weeklyPace(await read($, limitsAtom), await read($, paceDemoAtom), Date.now())) }
98 })
99
100 // Fresh readings arrive after each turn and whenever a window moves a point.
101 on('session.measure', async ($, e, next) => {
102 await update($, limitsAtom, () => e.rateLimits)
103 await update($, nowAtom, () => Date.now())
104 return next(e)
105 })
106
107 on('command.run', { command: 'hp' }, async ($, e) => {
108 const arg = e.args.trim().toLowerCase()
109 if (arg === 'off' || arg === 'real') {
110 await update($, demoAtom, () => null)
111 return { text: 'HP bars show your real limits again.' }
112 }
113 if (arg !== '') {
114 const n = Number(arg)
115 if (!Number.isFinite(n) || n < 0 || n > 100) return { text: 'Give an HP from 0 to 100, or "off".' }
116 await update($, demoAtom, () => Math.round(n))
117 return { text: n <= 0 ? 'Preview: Claude is dead. /hp off to revive.' : `Preview: both bars at ${Math.round(n)} HP. /hp off for real readings.` }
118 }
119 const all = bars(await read($, limitsAtom), await read($, demoAtom), Date.now())
120 return {
121 text: [
122 ...all.map(b => `${b.label}: ${b.hp === null ? 'no reading yet' : `${b.hp}/100 HP${b.respawn ? `, resets in ${b.respawn}` : ''}`}`),
123 paceLine(weeklyPace(await read($, limitsAtom), await read($, paceDemoAtom), Date.now())),
124 `(villager-hp ${VERSION})`,
125 ].join('\n'),
126 }
127 })
128
129 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
130 const below = await next(e)
131 if (e.props.hasSurvey) return below
132
133 const now = (await read($, nowAtom)) || Date.now()
134 const all = bars(await read($, limitsAtom), await read($, demoAtom), now)
135 const m = mood(all)
136 const pace = weeklyPace(await read($, limitsAtom), await read($, paceDemoAtom), now)
137 // Set while the week is on course to run out, and he is still standing.
138 const over = pace !== null && pace.isOver && m !== 'dead' ? pace : null
139 const elements = $.ui.resolve(e)
140
141 // The animated card everywhere but the terminal, which gets the text bars.
142 // Chosen by the surface, not by which elements the table lists: a table can
143 // carry an element its surface draws as nothing.
144 if (e.surface !== 'terminal' && 'Svg' in elements) {
145 const { Box, Svg } = elements
146 const alt = all.map(b => `${b.label} ${b.hp === null ? 'unknown' : `${b.hp} of 100`} HP`).join(', ') + (over !== null ? `, on course to be ${outBy(over.runsOut)}` : '')
147 return (
148 <Box flexDirection="column">
149 {below}
150 <Svg key={`hp-${m}-${over !== null}`} source={hudSvg(all, await read($, rankAtom), over !== null)} alt={`Claude's health: ${alt}`} />
151 </Box>
152 )
153 }
154
155 const { Box, Text } = elements
156 const dead = killer(all)
157 return (
158 <Box flexDirection="column">
159 {below}
160 {dead !== undefined ? (
161 <Text color="#c9a14a" bold>
162 {`(x_x) Claude has been defeated. Out of ${dead.label === 'SESSION' ? 'session' : 'weekly'} hit points · ${backIn(dead.respawn)}`}
163 </Text>
164 ) : (
165 <>
166 {all.map((b, i) => (
167 <Box key={b.label} flexDirection="row">
168 <Text color="#d97757">{i === 0 ? `${FACES[m]} ` : ' '}</Text>
169 <Text bold color="#d4ab52">{b.label.padEnd(8)}</Text>
170 {b.hp === null ? (
171 <Text dimColor>{'░'.repeat(SEGMENTS)} ??/100</Text>
172 ) : (
173 <>
174 <Text color="#3fd23f">{split(b.hp).green}</Text>
175 <Text color="#a01d14">{split(b.hp).red}</Text>
176 <Text color="#f1e3c0" bold>{` ${b.hp}/100`}</Text>
177 <Text color="#cdbb94">{b.respawn ? ` ${b.respawn}` : ''}</Text>
178 {over !== null && b.label === 'WEEKLY' ? <Text color="#f59e0b">{` ⏳ ${outBy(over.runsOut)}`}</Text> : null}
179 </>
180 )}
181 </Box>
182 ))}
183 </>
184 )}
185 </Box>
186 )
187 })
188}
189hooks/hud.ts 576 lines1import type { Limit } from '../types'
2
3// Turns the account's rate-limit windows into two game health bars, and
4// draws them as an SVG HUD for surfaces that draw Svg.
5
6export type Bar = {
7 label: 'SESSION' | 'WEEKLY'
8 hp: number | null // 0 to 100; null before the first reading
9 respawn: string // when the window resets: "2h 50m", "38m" or "Sun 10am"
10}
11
12export type Mood = 'healthy' | 'hurt' | 'critical' | 'dead' | 'unknown'
13
14const KINDS: Record<Bar['label'], string> = { SESSION: 'five_hour', WEEKLY: 'seven_day' }
15const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
16
17const respawnIn = (resetsAt: string | undefined, now: number) => {
18 if (resetsAt === undefined) return ''
19 const at = Date.parse(resetsAt)
20 if (Number.isNaN(at)) return ''
21 const mins = Math.max(0, Math.round((at - now) / 60000))
22 if (mins < 60) return `${mins}m`
23 if (mins < 24 * 60) return `${Math.floor(mins / 60)}h ${mins % 60}m`
24 const d = new Date(at)
25 const h = d.getHours()
26 const time = `${h % 12 === 0 ? 12 : h % 12}${d.getMinutes() ? `:${String(d.getMinutes()).padStart(2, '0')}` : ''}${h < 12 ? 'am' : 'pm'}`
27 return `${DAYS[d.getDay()]} ${time}`
28}
29
30export const bars = (limits: Limit[], demo: number | null, now: number): Bar[] =>
31 (['SESSION', 'WEEKLY'] as const).map(label => {
32 const limit = limits.find(l => l.kind === KINDS[label])
33 if (demo !== null) return { label, hp: demo, respawn: respawnIn(limit?.resetsAt, now) || '4h 20m' }
34 if (limit === undefined) return { label, hp: null, respawn: '' }
35 return { label, hp: Math.max(0, Math.round(100 - limit.percentUsed)), respawn: respawnIn(limit.resetsAt, now) }
36 })
37
38const lowest = (all: Bar[]) => {
39 const known = all.flatMap(b => (b.hp === null ? [] : [b.hp]))
40 return known.length === 0 ? null : Math.min(...known)
41}
42
43export const mood = (all: Bar[]): Mood => {
44 const low = lowest(all)
45 if (low === null) return 'unknown'
46 return low <= 0 ? 'dead' : low < 25 ? 'critical' : low < 50 ? 'hurt' : 'healthy'
47}
48
49// "back in 2h 50m", "back Sun 10am"
50export const backIn = (respawn: string) => (respawn ? (/^\d/.test(respawn) ? `back in ${respawn}` : `back ${respawn}`) : 'back soon')
51
52export const killer = (all: Bar[]) => all.find(b => b.hp !== null && b.hp <= 0)
53
54// ---- weekly pace: at this rate, does the week's allowance last to its reset? ----
55
56export type Pace = {
57 isOver: boolean // on course to run out before the reset
58 projected: number // percent of the weekly limit used by the reset, at this rate
59 runsOut: string // when it runs out at this rate, as a reset reads ("Thu 3pm"); '' when it lasts
60}
61
62const WEEK_MS = 7 * 24 * 60 * 60 * 1000
63// Too early to call: in a week's first hours one busy sitting reads as a blown week.
64const PACE_MIN_MS = 12 * 60 * 60 * 1000
65
66// The week's use so far, carried on at the same rate to the reset. `demo`
67// pins the answer for a preview: true over, false on track, null the real one.
68// Null when there is nothing to go on yet.
69export const weeklyPace = (limits: Limit[], demo: boolean | null, now: number): Pace | null => {
70 if (demo === false) return { isOver: false, projected: 80, runsOut: '' }
71 const limit = limits.find(l => l.kind === KINDS.WEEKLY)
72 const resets = Date.parse(limit?.resetsAt ?? '')
73 const elapsed = now - (resets - WEEK_MS)
74 const isKnown = limit !== undefined && !Number.isNaN(resets) && elapsed >= PACE_MIN_MS && now < resets
75 if (demo === true) return { isOver: true, projected: 130, runsOut: isKnown ? respawnIn(new Date(now + (resets - now) / 2).toISOString(), now) : 'Thu 3pm' }
76 if (!isKnown) return null
77 const projected = Math.round((limit.percentUsed / elapsed) * WEEK_MS)
78 if (projected <= 100) return { isOver: false, projected, runsOut: '' }
79 const left = Math.max(0, 100 - limit.percentUsed)
80 return { isOver: true, projected, runsOut: respawnIn(new Date(now + (left / limit.percentUsed) * elapsed).toISOString(), now) }
81}
82
83// "out in 2h 50m", "out by Thu 3pm"
84export const outBy = (runsOut: string) => (/^\d/.test(runsOut) ? `out in ${runsOut}` : `out by ${runsOut}`)
85
86// ---- the SVG HUD: a modern status card with the villager, 960 x 64 ----
87
88export const HUD_W = 960
89export const HUD_H = 64
90// A little air above the card, in the same units. Outside the card's own
91// coordinates, so nothing on it moves.
92export const HUD_PAD_TOP = 6
93const AV = { cx: 34, cy: 32, r: 25 } // the avatar circle
94const ICON_X = 74
95const LABEL_X = 92
96const BAR_X = 172
97// The right of the card is kept for the rank badge: a zone as wide as the
98// widest badge, so every rank sits the same distance from the reset times.
99const BADGE_ZONE = 156
100const BADGE_GAP = 24 // between the reset times and the badge zone
101// The bars fill what the badge leaves; hudSvg fits them to the badge it draws.
102let BAR_W = 960 - 16 - BADGE_ZONE - BADGE_GAP - 78 - 66 - 16 - 172
103const BAR_H = 12
104let VALUE_X = BAR_X + BAR_W + 16
105const ROW_CY = [20, 44] // the two rows' centre lines
106const UI = `font-family="'Segoe UI Variable Display', 'Segoe UI', system-ui, -apple-system, sans-serif"`
107
108const T = {
109 text: '#f1f4f8',
110 muted: '#8f9aa7',
111 faint: '#5d6875',
112 track: '#1b2129',
113 trackEdge: '#2b333d',
114 lost: '#3a1c20', // lost HP, a faint red under the track
115 chip: '#1e252e',
116 green: ['#22c55e', '#86efac'],
117 amber: ['#f59e0b', '#fcd34d'],
118 red: ['#ef4444', '#fca5a5'],
119}
120
121const tone = (hp: number) => (hp > 50 ? 'green' : hp > 25 ? 'amber' : 'red') as 'green' | 'amber' | 'red'
122
123// ---- the villager: a vector bust in a brown cap and a blue tunic ----
124
125const SKIN = { base: '#eab98e', shade: '#d39a6c', ear: '#dca57a' }
126const DEAD = { base: '#9a958e', shade: '#7f7a73', ear: '#8c8780' }
127const INK = '#2b1a12'
128
129// A tear that runs from under an eye down the cheek, over and over.
130const tear = (x: number, delay: number) => `
131 <path d="M ${x},35 q 1.3,2.2 0,3 q -1.3,-0.8 0,-3 z" fill="#5ec4ff" opacity="0">
132 <animateTransform attributeName="transform" type="translate" values="0 0; 0 9" dur="1.1s" begin="${delay}s" repeatCount="indefinite"/>
133 <animate attributeName="opacity" values="0.95;0.95;0" keyTimes="0;0.7;1" dur="1.1s" begin="${delay}s" repeatCount="indefinite"/>
134 </path>`
135
136// The least health for each of his spirits; under the last he sobs. He grins
137// for as long as the bar is green and only frowns once it is red.
138const STAGE = { happy: 50, content: 25, hurt: 10, crying: 5 }
139
140// His face by how much health is left: grinning, flat, frowning, crying, sobbing.
141const face = (hp: number) => {
142 const ry = hp < STAGE.hurt ? 1.5 : 2
143 const blink = `keyTimes="0;0.9;0.94;0.98;1" dur="4.2s" repeatCount="indefinite"`
144 const eye = (x: number) =>
145 `<ellipse cx="${x}" cy="32.2" rx="1.7" ry="${ry}" fill="${INK}"><animate attributeName="ry" values="${ry};${ry};0.2;${ry};${ry}" ${blink}/></ellipse>` +
146 `<circle cx="${x + 0.6}" cy="31.4" r="0.6" fill="#fff"><animate attributeName="opacity" values="1;1;0;1;1" ${blink}/></circle>`
147 const eyes = eye(29.8) + eye(38.2)
148 const nose = `<path d="M 34,33.5 q 1.2,1.6 0,2.3" fill="none" stroke="${SKIN.shade}" stroke-width="1.1" stroke-linecap="round"/>`
149 const stroke = (d: string) => `<path d="${d}" fill="none" stroke="${INK}" stroke-width="1.4" stroke-linecap="round"/>`
150 const brows = (sad: boolean) =>
151 sad
152 ? stroke('M 27.4,28.6 L 31.4,27.2') + stroke('M 36.6,27.2 L 40.6,28.6')
153 : stroke('M 27.6,27.6 Q 29.8,26.6 32,27.4') + stroke('M 36,27.4 Q 38.2,26.6 40.4,27.6')
154 const blush = `<circle cx="27.2" cy="36" r="2" fill="#f28b82" opacity="0.35"/><circle cx="40.8" cy="36" r="2" fill="#f28b82" opacity="0.35"/>`
155 if (hp >= STAGE.happy) return brows(false) + eyes + nose + blush + stroke('M 30.4,38.2 Q 34,41.4 37.6,38.2')
156 if (hp >= STAGE.content) return brows(false) + eyes + nose + stroke('M 31,39.2 L 37,39.2')
157 if (hp >= STAGE.hurt) return brows(true) + eyes + nose + stroke('M 30.6,40.4 Q 34,37.8 37.4,40.4')
158 if (hp >= STAGE.crying) return brows(true) + eyes + nose + stroke('M 30.4,40.6 Q 34,37.4 37.6,40.6') + tear(29.4, 0)
159 return (
160 brows(true) +
161 eyes +
162 nose +
163 `<ellipse cx="34" cy="39.8" rx="3" ry="2" fill="#5a1d14"/>` +
164 tear(29.4, 0) +
165 tear(38.6, 0.55) +
166 tear(29.4, 0.55)
167 )
168}
169
170// How the villager moves in each state: his pickaxe, his head, his breathing.
171type Motion = { pick: string; head: string; breathe: number; tremble?: string }
172const motion = (m: Mood, hp: number): Motion => {
173 if (m === 'dead') return { pick: '', head: '', breathe: 0 }
174 // Happy: hard at work, the pickaxe chopping, head bobbing along.
175 if (hp >= STAGE.happy)
176 return {
177 pick: `values="0 44 62;-24 44 62;6 44 62;0 44 62" keyTimes="0;0.45;0.6;1" dur="1.6s"`,
178 head: `values="0 0;0 -0.9;0 0" dur="0.8s"`,
179 breathe: 2.4,
180 }
181 // Content: a slower, steadier swing.
182 if (hp >= STAGE.content)
183 return { pick: `values="0 44 62;-14 44 62;0 44 62" dur="2.6s"`, head: `values="0 0;0 -0.5;0 0" dur="2.6s"`, breathe: 2.8 }
184 // Hurt: the pickaxe barely lifts, his head drooping.
185 if (hp >= STAGE.hurt)
186 return { pick: `values="0 44 62;-5 44 62;0 44 62" dur="3.6s"`, head: `values="0 0;0 0.8;0 0" dur="3.6s"`, breathe: 3.6 }
187 // Crying: the dropped pickaxe drags a little; he sniffles.
188 if (hp >= STAGE.crying)
189 return { pick: `values="0 46 62;3 46 62;0 46 62" dur="2.2s"`, head: `values="0 0;0 0.7;0 0;0 0.5;0 0" dur="1.1s"`, breathe: 1.4 }
190 // Sobbing: shoulders heaving, the whole villager trembling.
191 return {
192 pick: `values="0 46 62;4 46 62;0 46 62" dur="1.4s"`,
193 head: `values="0 0;0 1;0 0;0 1;0 0" dur="0.7s"`,
194 breathe: 0.7,
195 tremble: `values="0 0;-0.4 0;0.4 0;0 0" dur="0.18s"`,
196 }
197}
198
199const villager = (m: Mood, hp: number) => {
200 const dead = m === 'dead'
201 const skin = dead ? DEAD : SKIN
202 const tunic = dead ? '#5f6470' : '#3b6fe0'
203 const tunicDark = dead ? '#4c505a' : '#2c56b8'
204 const cap = dead ? '#5a554f' : '#7a4a24'
205 const capDark = dead ? '#4a4540' : '#5e3818'
206 const coping = hp >= STAGE.hurt || dead
207 const mv = motion(m, hp)
208 const spin = (v: string) => (v ? `<animateTransform attributeName="transform" type="rotate" ${v} repeatCount="indefinite"/>` : '')
209 const move = (v: string) => (v ? `<animateTransform attributeName="transform" type="translate" ${v} repeatCount="indefinite"/>` : '')
210
211 // The pickaxe, behind him: on his shoulder while he's coping, dropped once he isn't.
212 const pick = coping
213 ? `<g>${spin(mv.pick)}
214 <path d="M 44,62 L 53,24" stroke="${dead ? '#6a655e' : '#8b5a2b'}" stroke-width="2.6" stroke-linecap="round"/>
215 <path d="M 45.5,24.5 Q 53,19 60,26" fill="none" stroke="${dead ? '#77726b' : '#c7cfd8'}" stroke-width="3" stroke-linecap="round"/></g>`
216 : `<g>${spin(mv.pick)}
217 <path d="M 46,62 L 60,48" stroke="#8b5a2b" stroke-width="2.6" stroke-linecap="round"/>
218 <path d="M 56,44 Q 62,47 61,54" fill="none" stroke="#c7cfd8" stroke-width="3" stroke-linecap="round"/></g>`
219
220 // His body breathes: the tunic rises and settles.
221 const body = `<g>${mv.breathe ? move(`values="0 0;0 -0.7;0 0" dur="${mv.breathe}s"`) : ''}
222 <ellipse cx="34" cy="63" rx="19" ry="14" fill="${tunic}"/>
223 <path d="M 22,55 Q 34,60 46,55 L 46,60 Q 34,65 22,60 Z" fill="${tunicDark}" opacity="0.6"/>
224 <path d="M 29.5,49.5 L 34,55.5 L 38.5,49.5" fill="none" stroke="${tunicDark}" stroke-width="1.6" stroke-linejoin="round"/>
225 <rect x="30.5" y="41" width="7" height="9" rx="2" fill="${skin.shade}"/></g>`
226
227 const head = `
228 <circle cx="23.8" cy="33.5" r="2.4" fill="${skin.ear}"/>
229 <circle cx="44.2" cy="33.5" r="2.4" fill="${skin.ear}"/>
230 <ellipse cx="34" cy="32.5" rx="10.2" ry="11" fill="${skin.base}"/>
231 <path d="M 40,24.5 Q 45.5,32 40.5,42 Q 44.8,33 40,24.5 Z" fill="${skin.shade}" opacity="0.55"/>
232 <path d="M 23.4,30 Q 23,18.6 34,18.2 Q 45,18.6 44.6,30 Q 41,25.2 34,25.6 Q 27,25.2 23.4,30 Z" fill="${cap}"/>
233 <path d="M 23.4,30 Q 27,25.2 34,25.6 Q 41,25.2 44.6,30 Q 41,27.4 34,27.6 Q 27,27.4 23.4,30 Z" fill="${capDark}"/>`
234
235 const bandage =
236 !dead && hp < STAGE.content
237 ? `<rect x="25" y="26.2" width="18" height="3.4" rx="1.2" fill="#f3efe6" transform="rotate(-8 34 28)"/><circle cx="38.5" cy="27.4" r="0.9" fill="#d84a4a"/>`
238 : ''
239 const sweat =
240 !dead && hp < STAGE.hurt
241 ? `<path d="M 45.5,24 q 1.6,2.8 0,3.8 q -1.6,-1 0,-3.8 z" fill="#5ec4ff"><animate attributeName="opacity" values="1;0.2;1" dur="0.9s" repeatCount="indefinite"/></path>`
242 : ''
243 // Dead: X eyes and a halo that bobs above him, glinting.
244 const deadFace = dead
245 ? `<path d="M 28.4,30.6 l 3,3 M 31.4,30.6 l -3,3 M 36.6,30.6 l 3,3 M 39.6,30.6 l -3,3" stroke="${INK}" stroke-width="1.4" stroke-linecap="round"/>
246 <path d="M 31,39.4 L 37,39.4" stroke="${INK}" stroke-width="1.4" stroke-linecap="round"/>
247 <path d="M 35,39.4 q 0.6,2.6 2,0" fill="#e57373"/>
248 <g>${move(`values="0 0;0 -1.6;0 0" dur="2.4s"`)}
249 <ellipse cx="34" cy="14.6" rx="8" ry="2.2" fill="none" stroke="#f5d061" stroke-width="1.8">
250 <animate attributeName="stroke-opacity" values="1;0.55;1" dur="2.4s" repeatCount="indefinite"/>
251 </ellipse></g>`
252 : face(hp)
253
254 const headGroup = `<g>${move(mv.head)}${head}${bandage}${deadFace}${sweat}</g>`
255 const all = pick + body + headGroup
256 return mv.tremble ? `<g>${move(mv.tremble)}${all}</g>` : all
257}
258
259// The villager in a round avatar. His ring is coloured by his health, and a
260// bright arc orbits it.
261const avatar = (m: Mood, low: number | null) => {
262 const ring = m === 'dead' ? '#59616d' : low === null ? '#3a4350' : T[tone(low)][0]
263 const pulse =
264 m === 'critical' ? `<animate attributeName="stroke-opacity" values="1;0.3;1" dur="0.9s" repeatCount="indefinite"/>` : ''
265 const orbit =
266 m === 'dead'
267 ? ''
268 : `<circle cx="${AV.cx}" cy="${AV.cy}" r="${AV.r + 3.5}" fill="none" stroke="${ring}" stroke-width="2" stroke-linecap="round" stroke-dasharray="22 160" opacity="0.85" filter="url(#soft)">
269 <animateTransform attributeName="transform" type="rotate" values="0 ${AV.cx} ${AV.cy};360 ${AV.cx} ${AV.cy}" dur="${low !== null && low < 25 ? 1.2 : 3.2}s" repeatCount="indefinite"/>
270 </circle>`
271 return `
272 <circle cx="${AV.cx}" cy="${AV.cy}" r="${AV.r + 5}" fill="${ring}" opacity="0.10"/>
273 ${orbit}
274 <circle cx="${AV.cx}" cy="${AV.cy}" r="${AV.r}" fill="url(#avbg)"/>
275 <g clip-path="url(#avclip)">${villager(m, low ?? 100)}</g>
276 <circle cx="${AV.cx}" cy="${AV.cy}" r="${AV.r}" fill="none" stroke="${ring}" stroke-width="2.5">${pulse}</circle>`
277}
278
279// Over pace for the week: an hourglass floats at his shoulder, its sand
280// running out and the glass turning over. Drawn over the avatar's ring, so
281// the villager himself stays as his health has him.
282const PACE = { cx: 58, cy: 10.5, r: 8 }
283const paceBadge = () => {
284 const sand = T.amber[1]
285 const glass = '#f1e3c0'
286 const turn = `dur="3s" repeatCount="indefinite"`
287 return `<g>
288 <animateTransform attributeName="transform" type="translate" values="0 0;0 -1.2;0 0" dur="2.2s" repeatCount="indefinite"/>
289 <circle cx="${PACE.cx}" cy="${PACE.cy}" r="${PACE.r}" fill="#1a1410" stroke="${T.amber[0]}" stroke-width="1.4" filter="url(#soft)"/>
290 <g transform="translate(${PACE.cx} ${PACE.cy}) scale(1.15)"><g>
291 <animateTransform attributeName="transform" type="rotate" values="0;0;180" keyTimes="0;0.8;1" ${turn}/>
292 <path d="M -2.6,-3.6 L 2.6,-3.6 L 0.5,0 L 2.6,3.6 L -2.6,3.6 L -0.5,0 Z" fill="#2a2118" stroke="${glass}" stroke-width="0.8" stroke-linejoin="round"/>
293 <path d="M -3.2,-3.9 L 3.2,-3.9 M -3.2,3.9 L 3.2,3.9" stroke="${glass}" stroke-width="1.1" stroke-linecap="round"/>
294 <path d="M -1.7,-2.9 L 1.7,-2.9 L 0,0 Z" fill="${sand}">
295 <animateTransform attributeName="transform" type="scale" values="1;0.15;0.15" keyTimes="0;0.8;1" ${turn}/>
296 </path>
297 <line x1="0" y1="0" x2="0" y2="3.2" stroke="${sand}" stroke-width="0.5">
298 <animate attributeName="opacity" values="1;1;0;0" keyTimes="0;0.75;0.8;1" ${turn}/>
299 </line>
300 <g transform="translate(0 3.2)"><path d="M -2,0 L 2,0 L 0,-2.2 Z" fill="${sand}">
301 <animateTransform attributeName="transform" type="scale" values="1 0.1;1 1;1 1" keyTimes="0;0.8;1" ${turn}/>
302 </path></g>
303 </g></g>
304 </g>`
305}
306
307// ---- the bars ----
308
309// A heart that beats, faster the lower the health.
310const heartIcon = (x: number, cy: number, fill: string, hp: number | null) => {
311 const beat = hp === null || hp <= 0 ? '' : `<animateTransform attributeName="transform" type="scale" values="1;1.28;1;1.16;1" keyTimes="0;0.14;0.3;0.44;1" dur="${hp < 25 ? 0.6 : hp < 50 ? 0.9 : 1.3}s" repeatCount="indefinite"/>`
312 return `<g transform="translate(${x + 6} ${cy})"><g>${beat}<path transform="translate(-6.2 -6.6) scale(0.62)" d="M10 18 L2.4 10.4 A5 5 0 0 1 10 3.6 A5 5 0 0 1 17.6 10.4 Z" fill="${fill}"/></g></g>`
313}
314const calendarIcon = (x: number, cy: number, fill: string) =>
315 `<g transform="translate(${x} ${cy - 6})"><rect x="0.5" y="1.5" width="11" height="10" rx="2" fill="none" stroke="${fill}" stroke-width="1.5"/><path d="M 0.5,5 L 11.5,5 M 3.5,0 L 3.5,3 M 8.5,0 L 8.5,3" stroke="${fill}" stroke-width="1.5" stroke-linecap="round"/></g>`
316
317// One row: icon and label, a living bar, the value and a reset chip. The bar
318// sweeps in from empty, energy stripes flow through it, a shine passes along
319// it now and then, and sparks drift off its glowing leading edge.
320// Sci-fi accents, all drawn over the card without moving anything on it.
321const HUD_CYAN = '#5ec4ff'
322
323// Thin targeting brackets at the card's four corners, pulsing gently.
324const cornerBrackets = () => {
325 const L = 14
326 const i = 6
327 const W = HUD_W
328 const H = HUD_H
329 const d = [
330 `M ${i},${i + L} L ${i},${i} L ${i + L},${i}`,
331 `M ${W - i - L},${i} L ${W - i},${i} L ${W - i},${i + L}`,
332 `M ${i},${H - i - L} L ${i},${H - i} L ${i + L},${H - i}`,
333 `M ${W - i - L},${H - i} L ${W - i},${H - i} L ${W - i},${H - i - L}`,
334 ].join(' ')
335 return `<path d="${d}" fill="none" stroke="${HUD_CYAN}" stroke-width="1.4" stroke-linecap="round" opacity="0.45">
336 <animate attributeName="opacity" values="0.25;0.6;0.25" dur="3.6s" repeatCount="indefinite"/>
337 </path>`
338}
339
340// A faint dot grid, and a light band that sweeps across like a hologram scan.
341const hologram = () => `
342 <g clip-path="url(#cardclip)">
343 <rect x="0" y="0" width="${HUD_W}" height="${HUD_H}" fill="url(#dots)"/>
344 <rect x="-120" y="0" width="90" height="${HUD_H}" fill="url(#scanband)">
345 <animate attributeName="x" values="-120;-120;${HUD_W + 30}" keyTimes="0;0.55;1" dur="7s" repeatCount="indefinite"/>
346 </rect>
347 </g>`
348
349// A dashed radar ring with tick marks, turning against the glowing arc.
350const radar = (m: Mood) =>
351 m === 'dead'
352 ? ''
353 : `<g opacity="0.55">
354 <circle cx="${AV.cx}" cy="${AV.cy}" r="${AV.r + 7.5}" fill="none" stroke="${HUD_CYAN}" stroke-width="0.9" stroke-dasharray="2 5">
355 <animateTransform attributeName="transform" type="rotate" values="360 ${AV.cx} ${AV.cy};0 ${AV.cx} ${AV.cy}" dur="12s" repeatCount="indefinite"/>
356 </circle>
357 ${[0, 90, 180, 270].map(a => `<line x1="${AV.cx}" y1="${AV.cy - AV.r - 5}" x2="${AV.cx}" y2="${AV.cy - AV.r - 10}" stroke="${HUD_CYAN}" stroke-width="1.2" transform="rotate(${a} ${AV.cx} ${AV.cy})"/>`).join('')}
358 </g>`
359
360// Electric arcs crackling along a full bar's edges.
361const zigzag = (x0: number, x1: number, y: number, amp: number, seed: number) => {
362 const pts: string[] = []
363 for (let x = x0, k = 0; x <= x1; x += 7, k++) {
364 const jitter = ((Math.sin((k + 1) * 12.9898 + seed * 78.233) * 43758.5453) % 1 + 1) % 1
365 pts.push(`${x.toFixed(1)},${(y + (k % 2 === 0 ? -1 : 1) * amp * (0.4 + jitter)).toFixed(1)}`)
366 }
367 return pts.join(' ')
368}
369const overcharge = (x0: number, x1: number, top: number) => `
370 <g>
371 <polyline points="${zigzag(x0, x1, top - 1, 2.4, 1)}" fill="none" stroke="#e8fbff" stroke-width="1.1" opacity="0">
372 <animate attributeName="opacity" values="0;0.95;0;0;0.8;0" keyTimes="0;0.08;0.16;0.5;0.58;0.66" dur="1.7s" repeatCount="indefinite"/>
373 </polyline>
374 <polyline points="${zigzag(x0, x1, top + BAR_H + 1, 2.4, 2)}" fill="none" stroke="${HUD_CYAN}" stroke-width="1.1" opacity="0">
375 <animate attributeName="opacity" values="0;0;0.9;0;0;0.7;0" keyTimes="0;0.25;0.33;0.41;0.75;0.83;0.91" dur="1.7s" repeatCount="indefinite"/>
376 </polyline>
377 </g>`
378
379// Flashing red chevrons warning that a bar is low.
380const redAlert = (x: number, cy: number) => `
381 <text x="${x}" y="${cy + 5}" ${UI} font-size="13" font-weight="900" letter-spacing="-1" fill="#ff4d5e">❯❯
382 <animate attributeName="opacity" values="1;0.15;1" dur="0.7s" repeatCount="indefinite"/>
383 </text>`
384
385const row = (bar: Bar, cy: number, id: string, delay: number) => {
386 const hp = bar.hp
387 const top = cy - BAR_H / 2
388 const colour = (hp === null ? T.faint : T[tone(hp)][0]) ?? T.faint
389 const light = (hp === null ? T.faint : T[tone(hp)][1]) ?? T.faint
390 const icon = bar.label === 'SESSION' ? heartIcon(ICON_X, cy, colour, hp) : calendarIcon(ICON_X + 1, cy, colour)
391 const label = `<text x="${LABEL_X}" y="${cy + 4}" ${UI} font-size="11.5" font-weight="700" letter-spacing="1.4" fill="${T.muted}">${bar.label}</text>`
392 const track = `<rect x="${BAR_X}" y="${top}" width="${BAR_W}" height="${BAR_H}" rx="${BAR_H / 2}" fill="${hp === null || hp >= 100 ? T.track : T.lost}" stroke="${T.trackEdge}" stroke-width="1"/>`
393 let ticks = ''
394 for (let k = 1; k < 10; k++) {
395 const x = BAR_X + (BAR_W * k) / 10
396 ticks += `<line x1="${x}" y1="${top + 2}" x2="${x}" y2="${top + BAR_H - 2}" stroke="#0b0e12" stroke-opacity="0.4" stroke-width="1.5"/>`
397 }
398 if (hp === null) {
399 return `${icon}${label}${track}${ticks}<text x="${VALUE_X}" y="${cy + 5}" ${UI} font-size="15" font-weight="600" fill="${T.faint}">—</text>`
400 }
401 const w = hp <= 0 ? 0 : Math.max(BAR_H, Math.round((BAR_W * hp) / 100))
402 const sweep = `begin="${delay}s" dur="1.1s" calcMode="spline" keyTimes="0;1" keySplines="0.16 1 0.3 1" fill="freeze"`
403 const pulse = hp < 25 && hp > 0 ? `<animate attributeName="opacity" values="1;0.55;1" dur="0.9s" repeatCount="indefinite"/>` : ''
404 const edge = BAR_X + w - BAR_H / 2
405 const sparks = [0, 1, 2]
406 .map(
407 k => `<circle cx="${edge}" cy="${cy}" r="1.4" fill="${light}" opacity="0">
408 <animate attributeName="cy" values="${cy};${cy - 13}" dur="1.4s" begin="${delay + 1.1 + k * 0.47}s" repeatCount="indefinite"/>
409 <animate attributeName="cx" values="${edge};${edge + (k - 1) * 5}" dur="1.4s" begin="${delay + 1.1 + k * 0.47}s" repeatCount="indefinite"/>
410 <animate attributeName="opacity" values="0;0.9;0" dur="1.4s" begin="${delay + 1.1 + k * 0.47}s" repeatCount="indefinite"/>
411 </circle>`,
412 )
413 .join('')
414 const fill =
415 w > 0
416 ? `<g>${pulse}
417 <clipPath id="clip-${id}"><rect x="${BAR_X}" y="${top - 1}" width="0" height="${BAR_H + 2}" rx="${BAR_H / 2}"><animate attributeName="width" values="0;${w}" ${sweep}/></rect></clipPath>
418 <g clip-path="url(#clip-${id})">
419 <rect x="${BAR_X}" y="${top}" width="${w}" height="${BAR_H}" rx="${BAR_H / 2}" fill="url(#${id})" filter="url(#soft)"/>
420 <rect x="${BAR_X}" y="${top}" width="${w}" height="${BAR_H}" rx="${BAR_H / 2}" fill="url(#stripes)"/>
421 <rect x="${BAR_X + 4}" y="${top + 2}" width="${Math.max(0, w - 10)}" height="3" rx="1.5" fill="#fff" opacity="0.32"/>
422 <rect x="${BAR_X - 60}" y="${top - 2}" width="46" height="${BAR_H + 4}" fill="url(#shine)">
423 <animate attributeName="x" values="${BAR_X - 60};${BAR_X - 60};${BAR_X + w + 10}" keyTimes="0;0.55;1" dur="3.4s" begin="${delay + 1.2}s" repeatCount="indefinite"/>
424 </rect>
425 </g>
426 <circle cx="${BAR_X + BAR_H / 2}" cy="${cy}" r="${BAR_H / 2 + 1.5}" fill="${light}" opacity="0.5" filter="url(#soft)">
427 <animate attributeName="cx" values="${BAR_X + BAR_H / 2};${edge}" ${sweep}/>
428 <animate attributeName="r" values="${BAR_H / 2};${BAR_H / 2 + 2.5};${BAR_H / 2}" dur="1.6s" repeatCount="indefinite"/>
429 </circle>
430 <circle cx="${BAR_X + BAR_H / 2}" cy="${cy}" r="${BAR_H / 2 - 2}" fill="#fff" opacity="0.85">
431 <animate attributeName="cx" values="${BAR_X + BAR_H / 2};${edge}" ${sweep}/>
432 </circle>
433 ${sparks}
434 </g>`
435 : ''
436 const chipText = bar.respawn
437 // Only a full bar reads MAX; a nearly full one still crackles, and says its number.
438 const isMax = hp >= 100
439 const isCharged = hp >= 90
440 const value = isMax
441 ? `<text x="${VALUE_X}" y="${cy + 5.5}" ${UI} font-size="15" font-weight="800" letter-spacing="1.5" fill="${HUD_CYAN}" filter="url(#soft)">MAX</text>`
442 : `<text x="${VALUE_X}" y="${cy + 5.5}" ${UI} font-size="17" font-weight="700" fill="${T.text}">${hp}<tspan font-size="12" font-weight="600" fill="${T.muted}">/100</tspan></text>`
443 const fx = isCharged ? overcharge(BAR_X + 4, BAR_X + w - 4, top) : hp > 0 && hp < 25 ? redAlert(VALUE_X + 66 + 78 + 5, cy) : ''
444 const chipX = VALUE_X + 66
445 const CHIP_W = 78 // one width for both rows, so their edges line up
446 const chip = chipText
447 ? `<rect x="${chipX}" y="${cy - 10}" width="${CHIP_W}" height="20" rx="10" fill="${T.chip}" stroke="${T.trackEdge}"/>
448 <text x="${chipX + CHIP_W / 2}" y="${cy + 4.5}" text-anchor="middle" ${UI} font-size="12.5" font-weight="500" fill="${T.muted}">${chipText}</text>`
449 : ''
450 return icon + label + track + fill + ticks + fx + value + chip
451}
452
453// The contributor ranks, lowest first, as the draft rank sheet draws them.
454export type Rank = 'scout' | 'contributor' | 'innovator' | 'top' | 'god'
455type RankLook = { label: string; name: string; stops: [string, string, string]; edge: string; ink: string; glow?: string; shine?: true }
456export const RANKS: Record<Rank, RankLook> = {
457 scout: { label: '◇ SCOUT', name: 'Scout', stops: ['#d9e2ec', '#9aa9b8', '#6c7b8a'], edge: '#f1f5f9', ink: '#1b2430' },
458 contributor: { label: '✦ CONTRIBUTOR', name: 'Contributor', stops: ['#ffd2a8', '#d98a4e', '#a65a26'], edge: '#ffe7d1', ink: '#2e1606' },
459 innovator: { label: '◆ INNOVATOR', name: 'Innovator', stops: ['#c7f0ff', '#5ec4ff', '#2b8fd6'], edge: '#e6f7ff', ink: '#062033', glow: '#5ec4ff' },
460 top: { label: '★ OPEN', name: 'Top contributor', stops: ['#ffe27a', '#f7b733', '#e98a15'], edge: '#fff3c4', ink: '#2b1a03', glow: '#f7b733', shine: true },
461 god: { label: '⚡ GOD MODE', name: 'GOD MODE', stops: ['#ffe27a', '#f7b733', '#e98a15'], edge: '#fff3c4', ink: '#2b1a03', glow: '#f7b733', shine: true },
462}
463
464// The rank badge at the card's right end, past the reset times: a badge to
465// show, not a control. Its right edge sits 16 in from the card's, as the
466// avatar's left does; long names get a wider pill.
467const BADGE_H = 26
468const BADGE_Y = 19
469const badgeBox = (rank: Rank) => {
470 const w = Math.min(BADGE_ZONE, Math.max(108, Math.round(RANKS[rank].label.length * 7.6 + 28)))
471 return { x: 960 - 16 - w, w }
472}
473const rankBadge = (rank: Rank) => {
474 const look = RANKS[rank]
475 const { x, w } = badgeBox(rank)
476 const pill = `<rect x="${x}" y="${BADGE_Y}" width="${w}" height="${BADGE_H}" rx="${BADGE_H / 2}" fill="url(#badgegrad)"/>`
477 const shine = look.shine
478 ? `<g clip-path="url(#badgeclip)">
479 <rect x="${x - 40}" y="${BADGE_Y - 10}" width="22" height="${BADGE_H + 20}" fill="#fff" opacity="0.55" transform="skewX(-20)">
480 <animate attributeName="x" values="${x - 40};${x - 40};${x + w + 30}" keyTimes="0;0.6;1" dur="3s" repeatCount="indefinite"/>
481 </rect>
482 </g>`
483 : ''
484 return `
485 ${look.glow ? `<g filter="url(#badgeglow)">${pill}</g>` : pill}
486 ${shine}
487 <rect x="${x + 0.5}" y="${BADGE_Y + 0.5}" width="${w - 1}" height="${BADGE_H - 1}" rx="${(BADGE_H - 1) / 2}" fill="none" stroke="${look.edge}" stroke-opacity="0.6"/>
488 <text x="${x + w / 2}" y="${BADGE_Y + 17.5}" text-anchor="middle" ${UI} font-size="${look.label.length > 12 ? 11.5 : 12}" font-weight="800" letter-spacing="${look.label.length > 12 ? 0.9 : 1.2}" fill="${look.ink}">${look.label}</text>`
489}
490
491const badgeDefs = (rank: Rank) => {
492 const look = RANKS[rank]
493 const { x, w } = badgeBox(rank)
494 return `<linearGradient id="badgegrad" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="${look.stops[0]}"/><stop offset="0.55" stop-color="${look.stops[1]}"/><stop offset="1" stop-color="${look.stops[2]}"/></linearGradient>
495 <clipPath id="badgeclip"><rect x="${x}" y="${BADGE_Y}" width="${w}" height="${BADGE_H}" rx="${BADGE_H / 2}"/></clipPath>
496 <filter id="badgeglow" x="-20%" y="-60%" width="140%" height="220%"><feGaussianBlur in="SourceAlpha" stdDeviation="3" result="b"/><feFlood flood-color="${look.glow ?? '#000'}" flood-opacity="0.55"/><feComposite in2="b" operator="in" result="g"/><feMerge><feMergeNode in="g"/><feMergeNode in="SourceGraphic"/></feMerge></filter>`
497}
498
499const gradient = (id: string, hp: number | null) => {
500 const [a, b] = T[tone(hp ?? 100)]
501 return `<linearGradient id="${id}" x1="0" y1="0" x2="1" y2="0"><stop offset="0" stop-color="${a}"/><stop offset="1" stop-color="${b}"/></linearGradient>`
502}
503
504// Two soft blobs of the health colour drifting slowly behind the card.
505const aurora = (colour: string) => `
506 <g clip-path="url(#cardclip)" opacity="0.5">
507 <ellipse cx="160" cy="34" rx="170" ry="46" fill="url(#aura)">
508 <animate attributeName="cx" values="120;420;120" dur="14s" repeatCount="indefinite"/>
509 </ellipse>
510 <ellipse cx="700" cy="30" rx="150" ry="40" fill="url(#aura2)">
511 <animate attributeName="cx" values="760;460;760" dur="18s" repeatCount="indefinite"/>
512 </ellipse>
513 </g>
514 <radialGradient id="aura"><stop offset="0" stop-color="${colour}" stop-opacity="0.16"/><stop offset="1" stop-color="${colour}" stop-opacity="0"/></radialGradient>
515 <radialGradient id="aura2"><stop offset="0" stop-color="#3b82f6" stop-opacity="0.10"/><stop offset="1" stop-color="#3b82f6" stop-opacity="0"/></radialGradient>`
516
517export const hudSvg = (all: Bar[], rank: Rank = 'god', isOverPace = false) => {
518 // Fit the bars to this badge, so the gap before it is the same for every rank.
519 BAR_W = 960 - 16 - badgeBox(rank).w - BADGE_GAP - 78 - 66 - 16 - BAR_X
520 VALUE_X = BAR_X + BAR_W + 16
521 const m = mood(all)
522 const dead = killer(all)
523 const known = all.flatMap(b => (b.hp === null ? [] : [b.hp]))
524 const low = known.length === 0 ? null : Math.min(...known)
525 const session = all[0] ?? { label: 'SESSION' as const, hp: null, respawn: '' }
526 const weekly = all[1] ?? { label: 'WEEKLY' as const, hp: null, respawn: '' }
527 const glow = (m === 'dead' ? '#59616d' : low === null ? '#3a4350' : T[tone(low)][0]) ?? '#3a4350'
528
529 const deathScreen = dead
530 ? `<g>
531 <rect x="0.5" y="0.5" width="${HUD_W - 1}" height="${HUD_H - 1}" rx="14" fill="#0b0d11" opacity="0.9"/>
532 <rect x="0.5" y="0.5" width="${HUD_W - 1}" height="${HUD_H - 1}" rx="14" fill="none" stroke="#ef4444" stroke-opacity="0.55"/>
533 ${avatar(m, 0)}
534 <text x="${ICON_X}" y="29" ${UI} font-size="18" font-weight="700" fill="${T.text}">Claude has been defeated<animate attributeName="opacity" values="0;1" dur="0.8s" fill="freeze"/></text>
535 <text x="${ICON_X}" y="49" ${UI} font-size="13" fill="${T.muted}">Out of ${dead.label === 'SESSION' ? 'session' : 'weekly'} hit points · ${backIn(dead.respawn)}</text>
536 </g>`
537 : ''
538
539 return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${HUD_W} ${HUD_H + HUD_PAD_TOP}" width="${HUD_W * 3}" height="${(HUD_H + HUD_PAD_TOP) * 3}" preserveAspectRatio="xMinYMin meet">
540 <defs>
541 <clipPath id="frameclip"><rect x="0" y="0" width="${HUD_W}" height="${HUD_H}"/></clipPath>
542 <linearGradient id="card" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#1a2029"/><stop offset="1" stop-color="#12161c"/></linearGradient>
543 <clipPath id="cardclip"><rect x="0.5" y="0.5" width="${HUD_W - 1}" height="${HUD_H - 1}" rx="14"/></clipPath>
544 <pattern id="dots" width="10" height="10" patternUnits="userSpaceOnUse"><circle cx="1" cy="1" r="0.7" fill="#ffffff" opacity="0.05"/></pattern>
545 <linearGradient id="scanband" x1="0" y1="0" x2="1" y2="0"><stop offset="0" stop-color="${HUD_CYAN}" stop-opacity="0"/><stop offset="0.5" stop-color="${HUD_CYAN}" stop-opacity="0.09"/><stop offset="1" stop-color="${HUD_CYAN}" stop-opacity="0"/></linearGradient>
546 <radialGradient id="cardglow" cx="0.04" cy="0.5" r="0.32"><stop offset="0" stop-color="${glow}" stop-opacity="0.16"/><stop offset="1" stop-color="${glow}" stop-opacity="0"/></radialGradient>
547 <radialGradient id="avbg" cx="0.5" cy="0.3" r="0.8"><stop offset="0" stop-color="#4b7d46"/><stop offset="0.65" stop-color="#2b4a2c"/><stop offset="1" stop-color="#1b2f1d"/></radialGradient>
548 ${badgeDefs(rank)}
549 <clipPath id="avclip"><circle cx="${AV.cx}" cy="${AV.cy}" r="${AV.r - 1}"/></clipPath>
550 <filter id="soft" x="-5%" y="-80%" width="110%" height="260%"><feGaussianBlur in="SourceGraphic" stdDeviation="2.4" result="b"/><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge></filter>
551 <pattern id="stripes" x="0" y="0" width="14" height="14" patternUnits="userSpaceOnUse" patternTransform="rotate(-35)">
552 <rect width="6" height="14" fill="#ffffff" opacity="0.16"/>
553 <animate attributeName="x" values="0;14" dur="0.9s" repeatCount="indefinite"/>
554 </pattern>
555 <linearGradient id="shine" x1="0" y1="0" x2="1" y2="0"><stop offset="0" stop-color="#fff" stop-opacity="0"/><stop offset="0.5" stop-color="#fff" stop-opacity="0.55"/><stop offset="1" stop-color="#fff" stop-opacity="0"/></linearGradient>
556 ${gradient('g0', session.hp)}
557 ${gradient('g1', weekly.hp)}
558 </defs>
559 <g transform="translate(0 ${HUD_PAD_TOP})" clip-path="url(#frameclip)">
560 <rect x="0.5" y="0.5" width="${HUD_W - 1}" height="${HUD_H - 1}" rx="14" fill="url(#card)" stroke="#2a313b"/>
561 ${aurora(glow)}
562 <rect x="0.5" y="0.5" width="${HUD_W - 1}" height="${HUD_H - 1}" rx="14" fill="url(#cardglow)"/>
563 <line x1="14" y1="1.5" x2="${HUD_W - 14}" y2="1.5" stroke="#ffffff" stroke-opacity="0.06"/>
564 ${hologram()}
565 ${radar(m)}
566 ${avatar(m, low)}
567 ${isOverPace && m !== 'dead' ? paceBadge() : ''}
568 ${row(session, ROW_CY[0] ?? 20, 'g0', 0.15)}
569 ${row(weekly, ROW_CY[1] ?? 44, 'g1', 0.35)}
570 ${rankBadge(rank)}
571 ${cornerBrackets()}
572 ${deathScreen}
573 </g>
574</svg>`
575}
576types/index.d.ts 18 lines1export type Limit = { kind: string; percentUsed: number; resetsAt?: string }
2
3declare module 'claude-code' {
4 interface PluginState {
5 'villager-hp': {
6 limits: Limit[]
7 // /hp <n> pins both bars to n HP to preview; null shows the real readings.
8 demo: number | null
9 // /pace over or /pace ok pins the weekly pace to preview; null shows the real one.
10 paceDemo: boolean | null
11 // The clock, ticked each minute so the respawn countdowns move.
12 now: number
13 // The rank badge on the card: scout, contributor, innovator, top or god.
14 rank: 'scout' | 'contributor' | 'innovator' | 'top' | 'god'
15 }
16 }
17}
18