mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-28 01:49:04 +01:00
Cover null budget branches in usage line
Share the day tail between the budgeted and unlimited usage lines and narrow the nullable budget fields without defaults, so the 100% branch gate holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWViGJJaqBKGr1Hbppr
This commit is contained in:
parent
e77814e0a7
commit
0f7fae8008
@ -63,46 +63,37 @@ function warningLine(today: BudgetToday, maskedCount: number): HTMLElement {
|
|||||||
/** The "no limit" mark: the registry's no-cap icon. */
|
/** The "no limit" mark: the registry's no-cap icon. */
|
||||||
const unlimitedMark = (): HTMLElement => glyph('filter.no-cap', 'No gaming limit')
|
const unlimitedMark = (): HTMLElement => glyph('filter.no-cap', 'No gaming limit')
|
||||||
|
|
||||||
|
/** The painted tail both usage lines share: the gaming day and when it starts. */
|
||||||
|
const dayTail = (t: BudgetToday) => [
|
||||||
|
' · ',
|
||||||
|
iconInline('gaming.day'),
|
||||||
|
' ',
|
||||||
|
t.gaming_day,
|
||||||
|
' · ',
|
||||||
|
iconInline('gaming.day_start'),
|
||||||
|
' ',
|
||||||
|
t.day_starts_at.replace(/\s*local$/, ''),
|
||||||
|
]
|
||||||
|
|
||||||
function usageLine(t: BudgetToday): HTMLElement {
|
function usageLine(t: BudgetToday): HTMLElement {
|
||||||
if (t.unlimited) {
|
const { budget_seconds: budget, fraction_used: fraction } = t
|
||||||
return said(
|
const day = `gaming day ${t.gaming_day} (starts ${t.day_starts_at})`
|
||||||
`${fmtDuration(t.seconds_used)} played · gaming day ${t.gaming_day} (starts ${t.day_starts_at})`,
|
if (t.unlimited || budget === null || fraction === null) {
|
||||||
fmtDuration(t.seconds_used),
|
return said(`${fmtDuration(t.seconds_used)} played · ${day}`, fmtDuration(t.seconds_used), ...dayTail(t))
|
||||||
' · ',
|
|
||||||
iconInline('gaming.day'),
|
|
||||||
' ',
|
|
||||||
t.gaming_day,
|
|
||||||
' · ',
|
|
||||||
iconInline('gaming.day_start'),
|
|
||||||
' ',
|
|
||||||
t.day_starts_at.replace(/\s*local$/, ''),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
const used = `${fmtDuration(t.seconds_used)} / ${fmtDuration(t.budget_seconds ?? 0)} · ${Math.round((t.fraction_used ?? 0) * 100)}%`
|
const used = `${fmtDuration(t.seconds_used)} / ${fmtDuration(budget)} · ${Math.round(fraction * 100)}%`
|
||||||
const spoken =
|
const spoken = `${fmtDuration(t.seconds_used)} of ${fmtDuration(budget)} used · ${Math.round(fraction * 100)}% · ${day}`
|
||||||
`${fmtDuration(t.seconds_used)} of ${fmtDuration(t.budget_seconds ?? 0)} used · ` +
|
return said(spoken, used, ...dayTail(t))
|
||||||
`${Math.round((t.fraction_used ?? 0) * 100)}% · gaming day ${t.gaming_day} (starts ${t.day_starts_at})`
|
|
||||||
return said(
|
|
||||||
spoken,
|
|
||||||
used,
|
|
||||||
' · ',
|
|
||||||
iconInline('gaming.day'),
|
|
||||||
' ',
|
|
||||||
t.gaming_day,
|
|
||||||
' · ',
|
|
||||||
iconInline('gaming.day_start'),
|
|
||||||
' ',
|
|
||||||
t.day_starts_at.replace(/\s*local$/, ''),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function todayCard(today: BudgetToday, legend: readonly BudgetLegendEntry[], maskedCount: number): HTMLElement {
|
export function todayCard(today: BudgetToday, legend: readonly BudgetLegendEntry[], maskedCount: number): HTMLElement {
|
||||||
// Colour by the chart's legend position so a game reads the same in both
|
// Colour by the chart's legend position so a game reads the same in both
|
||||||
// places; games the capped legend left out fall back to their row order.
|
// places; games the capped legend left out fall back to their row order.
|
||||||
const indexFor = new Map(legend.map((e, i) => [e.key, i]))
|
const indexFor = new Map(legend.map((e, i) => [e.key, i]))
|
||||||
|
const { fraction_used: fraction, seconds_remaining: remaining } = today
|
||||||
|
const unlimited = today.unlimited || fraction === null || remaining === null
|
||||||
const fill = h('div', { class: 'budget-meter-fill' })
|
const fill = h('div', { class: 'budget-meter-fill' })
|
||||||
fill.style.width = `${((today.fraction_used ?? 0) * 100).toFixed(1)}%`
|
if (!unlimited) fill.style.width = `${(fraction * 100).toFixed(1)}%`
|
||||||
const unlimited = today.unlimited
|
|
||||||
return h(
|
return h(
|
||||||
'section',
|
'section',
|
||||||
{ class: 'budget-today' },
|
{ class: 'budget-today' },
|
||||||
@ -110,7 +101,7 @@ export function todayCard(today: BudgetToday, legend: readonly BudgetLegendEntry
|
|||||||
h(
|
h(
|
||||||
'p',
|
'p',
|
||||||
{ class: 'budget-hero' },
|
{ class: 'budget-hero' },
|
||||||
h('strong', {}, unlimited ? unlimitedMark() : fmtDuration(today.seconds_remaining ?? 0)),
|
h('strong', {}, unlimited ? unlimitedMark() : fmtDuration(remaining)),
|
||||||
unlimited ? null : h('span', { class: 'sr-only' }, ' left'),
|
unlimited ? null : h('span', { class: 'sr-only' }, ' left'),
|
||||||
),
|
),
|
||||||
// No budget, no meter and no warnings: there is nothing to fill or warn of.
|
// No budget, no meter and no warnings: there is nothing to fill or warn of.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user