diff --git a/tgui/packages/tgui/events/handlers/assets.ts b/tgui/packages/tgui/events/handlers/assets.ts index 89b32ce07ea..521801fce40 100644 --- a/tgui/packages/tgui/events/handlers/assets.ts +++ b/tgui/packages/tgui/events/handlers/assets.ts @@ -12,10 +12,7 @@ export function handleLoadAssets(payload: Record): void { Byond.iconRefMap && Object.keys(Byond.iconRefMap).length === 0 ) { - fetchRetry(payload['icon_ref_map.json']) - .then((res) => res.json()) - .then(setIconRefMap) - .catch(console.error); + fetchIconRefMapWithRetry(payload['icon_ref_map.json']); } } @@ -29,3 +26,26 @@ export function getIconFromRefMap(icon: string): string | undefined { function setIconRefMap(map: Record): void { Byond.iconRefMap = map; } + +function fetchIconRefMapWithRetry(url: string, retries = 5, delay = 2500) { + const attempt = () => { + fetchRetry(url) + .then((res) => res.json()) + .then((json) => { + setIconRefMap(json); + console.log('Icon ref map loaded successfully.'); + }) + .catch((err) => { + console.error(`Failed to load icon_ref_map.json:`, err); + if (retries > 0) { + console.log(`Retrying in ${delay / 1000}s...`); + setTimeout( + () => fetchIconRefMapWithRetry(url, retries - 1, delay), + delay, + ); + } + }); + }; + + attempt(); +}