// characterLoader.js - Loads character spritesheets from server and registers them import { registerCharacter } from './sprites.js'; /** * Fetch character data from the server and register all characters * with the sprite system so NPCs can use them. * @returns {Promise} number of characters loaded */ export async function loadCharacters() { try { const res = await fetch('/api/characters'); const data = await res.json(); if (!data.characters) return 0; const entries = Object.entries(data.characters); const promises = entries.map(([id, c]) => registerCharacter(id, c.name, c.spritesheet, c.frameW, c.frameH) ); await Promise.all(promises); console.log(`[characterLoader] loaded ${entries.length} character(s)`); return entries.length; } catch (e) { console.warn('[characterLoader] failed to load characters:', e); return 0; } }