mirror of
https://github.com/LCE-Hub/LCE-Emerald-Launcher.git
synced 2026-07-18 00:07:09 +00:00
fix: skin sync for neoLegacy
This commit is contained in:
parent
7941e8e1da
commit
7b25f2afbc
|
|
@ -12,37 +12,42 @@ interface UseSkinSyncProps {
|
|||
}
|
||||
|
||||
export function useSkinSync({ profile, editions }: UseSkinSyncProps) {
|
||||
const [skinUrl, setSkinUrl] = useLocalStorage("lce-skin", "/images/Default.png");
|
||||
const [skinUrl, setSkinUrl] = useLocalStorage(
|
||||
"lce-skin",
|
||||
"/images/Default.png",
|
||||
);
|
||||
const [skinBase64, setSkinBase64] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const syncSkin = async () => {
|
||||
if (!skinUrl) return;
|
||||
const edition = editions.find((e) => e.id === profile);
|
||||
const supportsSlim = edition?.supportsSlimSkins ?? false;
|
||||
if (!supportsSlim) {
|
||||
try {
|
||||
const img = new Image();
|
||||
img.crossOrigin = "anonymous";
|
||||
img.onload = () => {
|
||||
const cvs = document.createElement("canvas");
|
||||
cvs.width = 64;
|
||||
cvs.height = 32;
|
||||
const ctx = cvs.getContext("2d");
|
||||
if (ctx) {
|
||||
ctx.drawImage(img, 0, 0, 64, 32, 0, 0, 64, 32);
|
||||
setSkinBase64(cvs.toDataURL("image/png"));
|
||||
}
|
||||
};
|
||||
img.src = skinUrl;
|
||||
} catch (e) {
|
||||
console.error("Skin conversion failed:", e);
|
||||
}
|
||||
let cancelled = false;
|
||||
if (!skinUrl) return;
|
||||
|
||||
const edition = editions.find((e) => e.id === profile);
|
||||
const supportsSlim = edition?.supportsSlimSkins ?? false;
|
||||
|
||||
const img = new Image();
|
||||
img.crossOrigin = "anonymous";
|
||||
img.onload = () => {
|
||||
if (cancelled) return;
|
||||
const cvs = document.createElement("canvas");
|
||||
if (supportsSlim) {
|
||||
cvs.width = img.width;
|
||||
cvs.height = img.height;
|
||||
} else {
|
||||
setSkinBase64(null);
|
||||
cvs.width = 64;
|
||||
cvs.height = 32;
|
||||
}
|
||||
const ctx = cvs.getContext("2d");
|
||||
if (ctx) {
|
||||
ctx.drawImage(img, 0, 0);
|
||||
setSkinBase64(cvs.toDataURL("image/png"));
|
||||
}
|
||||
};
|
||||
syncSkin();
|
||||
img.src = skinUrl;
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [skinUrl, profile, editions]);
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in a new issue