Initial commit

This commit is contained in:
Z User
2026-03-25 07:22:25 +00:00
commit 5b6e50c0bd
99 changed files with 20636 additions and 0 deletions

43
src/lib/game/formatting.ts Executable file
View File

@@ -0,0 +1,43 @@
// ─── Shared Formatting Utilities ─────────────────────────────────────────────────
// Utility functions for consistent formatting across components
import { ELEMENTS } from '@/lib/game/constants';
import type { SpellCost } from '@/lib/game/types';
/**
* Format a spell cost for display
*/
export function formatSpellCost(cost: SpellCost): string {
if (cost.type === 'raw') {
return `${cost.amount} raw`;
}
const elemDef = ELEMENTS[cost.element || ''];
return `${cost.amount} ${elemDef?.sym || '?'}`;
}
/**
* Get the display color for a spell cost
*/
export function getSpellCostColor(cost: SpellCost): string {
if (cost.type === 'raw') {
return '#60A5FA'; // Blue for raw mana
}
return ELEMENTS[cost.element || '']?.color || '#9CA3AF';
}
/**
* Format study time in hours to human-readable string
*/
export function formatStudyTime(hours: number): string {
if (hours < 1) return `${Math.round(hours * 60)}m`;
return `${hours.toFixed(1)}h`;
}
/**
* Format time (hour of day) to HH:MM format
*/
export function formatHour(hour: number): string {
const h = Math.floor(hour);
const m = Math.floor((hour % 1) * 60);
return `${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}`;
}