retry refmap (#19007)

This commit is contained in:
Kashargul
2026-01-16 21:49:30 +01:00
committed by GitHub
parent 5ef6d5adc6
commit c80ce6e4ab
+24 -4
View File
@@ -12,10 +12,7 @@ export function handleLoadAssets(payload: Record<string, string>): 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<string, string>): 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();
}