2026-10-31 10:07:36 +00:00
|
|
|
import type { Cost } from '~/types/game'
|
|
|
|
|
|
|
|
|
|
type Translate = (key: string, values?: Record<string, unknown>) => string
|
|
|
|
|
|
|
|
|
|
/** A route's interval in real time: "2 h 30 min", "45 min", "1 d 2 h". */
|
|
|
|
|
export function formatInterval(seconds: number, t: Translate) {
|
|
|
|
|
const m = Math.round(Math.max(0, seconds) / 60)
|
|
|
|
|
const days = Math.floor(m / 1440)
|
|
|
|
|
const hours = Math.floor((m % 1440) / 60)
|
|
|
|
|
const minutes = m % 60
|
2026-10-31 10:15:54 +00:00
|
|
|
if (days) return hours ? t('market.interval.dh', { d: days, h: hours }) : t('market.interval.d', { d: days })
|
2026-10-31 10:07:36 +00:00
|
|
|
if (hours && minutes) return t('market.interval.hm', { h: hours, m: minutes })
|
|
|
|
|
if (hours) return t('market.interval.h', { h: hours })
|
|
|
|
|
return t('market.interval.m', { m: minutes })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** The resources of a cargo with an amount above zero, in wood, clay, iron order. */
|
|
|
|
|
export const cargoRows = (cargo: Cost | null | undefined) => (['wood', 'clay', 'iron'] as const).filter((r) => (cargo?.[r] ?? 0) > 0).map((r) => [r, cargo![r]] as const)
|