Commit 561dae77 authored by timel's avatar timel

fix: remove preload image

parent 3e13bed8
......@@ -32,7 +32,6 @@ import {
type MoveOptions,
} from "./springs";
import type { SpringApiProps } from "./springs/types";
import { preloadCardImage } from "./springs/utils";
const { HAND, GRAVE, REMOVED, EXTRA, MZONE, SZONE, TZONE } = ygopro.CardZone;
......@@ -93,7 +92,6 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
});
register(Task.Focus, async () => {
await preloadCardImage(card.code);
setClassFocus(true);
setTimeout(() => setClassFocus(false), 1000);
await focus({ card, api });
......
......@@ -11,25 +11,3 @@ export const asyncStart = <T extends {}>(api: SpringRef<T>) => {
});
});
};
// >>> preload image >>>
const preloadImageSet = new Set<string>();
export const preloadImage = (src: string) =>
new Promise<void>((resolve, reject) => {
if (preloadImageSet.has(src)) {
resolve();
} else {
const image = new Image();
image.onload = async () => {
await new Promise((r) => setTimeout(r, 100));
resolve();
preloadImageSet.add(src);
};
image.onerror = reject;
image.src = src;
}
});
export const preloadCardImage = (code: number) =>
preloadImage(getCardImgUrl(code));
// <<< preload image <<<
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment