From aa10cb54dbbf2a4b3f4505f6a064b8e8d695b718 Mon Sep 17 00:00:00 2001 From: duckietm Date: Wed, 1 Apr 2026 10:23:00 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=86=99=20Small=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../avatar/AvatarEditorThumbnailsHelper.ts | 43 +++++++++++-------- .../AvatarEditorFigureSetItemView.tsx | 10 ++++- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/api/avatar/AvatarEditorThumbnailsHelper.ts b/src/api/avatar/AvatarEditorThumbnailsHelper.ts index bffc418..f40483d 100644 --- a/src/api/avatar/AvatarEditorThumbnailsHelper.ts +++ b/src/api/avatar/AvatarEditorThumbnailsHelper.ts @@ -150,34 +150,39 @@ export class AvatarEditorThumbnailsHelper if(cached) return cached; - return new Promise(async (resolve, reject) => + const avatarImage = GetAvatarRenderManager().createAvatarImage(figureString, AvatarScaleType.LARGE, null, null); + + if(avatarImage.isPlaceholder()) { - const resetFigure = async (figure: string) => - { - const avatarImage = GetAvatarRenderManager().createAvatarImage(figure, AvatarScaleType.LARGE, null, { resetFigure, dispose: null, disposed: false }); + avatarImage.dispose(); - if(avatarImage.isPlaceholder()) return; + return null; + } - const texture = avatarImage.processAsTexture(AvatarSetType.HEAD, false); - const sprite = new NitroSprite(texture); + const texture = avatarImage.processAsTexture(AvatarSetType.HEAD, false); - if(isDisabled) sprite.filters = [ AvatarEditorThumbnailsHelper.ALPHA_FILTER ]; + if(!texture) + { + avatarImage.dispose(); - const imageUrl = await TextureUtils.generateImageUrl({ - target: sprite, - frame: new NitroRectangle(0, 0, texture.width, texture.height) - }); + return null; + } - sprite.destroy(); - avatarImage.dispose(); + const sprite = new NitroSprite(texture); - AvatarEditorThumbnailsHelper.THUMBNAIL_CACHE.set(thumbnailKey, imageUrl); + if(isDisabled) sprite.filters = [ AvatarEditorThumbnailsHelper.ALPHA_FILTER ]; - resolve(imageUrl); - }; - - resetFigure(figureString); + const imageUrl = await TextureUtils.generateImageUrl({ + target: sprite, + frame: new NitroRectangle(0, 0, texture.width, texture.height) }); + + sprite.destroy(); + avatarImage.dispose(); + + if(imageUrl) AvatarEditorThumbnailsHelper.THUMBNAIL_CACHE.set(thumbnailKey, imageUrl); + + return imageUrl; } private static sortByDrawOrder(a: IFigurePart, b: IFigurePart): number diff --git a/src/components/avatar-editor/figure-set/AvatarEditorFigureSetItemView.tsx b/src/components/avatar-editor/figure-set/AvatarEditorFigureSetItemView.tsx index 789dc74..588005e 100644 --- a/src/components/avatar-editor/figure-set/AvatarEditorFigureSetItemView.tsx +++ b/src/components/avatar-editor/figure-set/AvatarEditorFigureSetItemView.tsx @@ -1,7 +1,9 @@ +import { NitroEventType } from '@nitrots/nitro-renderer'; import { FC, useEffect, useState } from 'react'; import { AvatarEditorThumbnailsHelper, GetClubMemberLevel, GetConfigurationValue, IAvatarEditorCategoryPartItem } from '../../../api'; import { LayoutCurrencyIcon, LayoutGridItemProps } from '../../../common'; import { useAvatarEditor } from '../../../hooks'; +import { useNitroEvent } from '../../../hooks/events'; import { InfiniteGrid } from '../../../layout'; import { AvatarEditorIcon } from '../AvatarEditorIcon'; @@ -14,6 +16,7 @@ export const AvatarEditorFigureSetItemView: FC<{ { const { setType = null, partItem = null, isSelected = false, width = '100%', ...rest } = props; const [ assetUrl, setAssetUrl ] = useState(''); + const [ retryId, setRetryId ] = useState(0); const { selectedColorParts = null, getFigureStringWithFace = null } = useAvatarEditor(); const clubLevel = partItem.partSet?.clubLevel ?? 0; @@ -21,6 +24,11 @@ export const AvatarEditorFigureSetItemView: FC<{ const isLocked = isHC && (GetClubMemberLevel() < clubLevel); const isSellableNotOwned = partItem.isSellableNotOwned ?? false; + useNitroEvent(NitroEventType.AVATAR_ASSET_LOADED, () => + { + if(!assetUrl || !assetUrl.length) setRetryId(prev => prev + 1); + }); + useEffect(() => { setAssetUrl(''); @@ -54,7 +62,7 @@ export const AvatarEditorFigureSetItemView: FC<{ }; loadImage(); - }, [ setType, partItem, selectedColorParts, getFigureStringWithFace, isSellableNotOwned ]); + }, [ setType, partItem, selectedColorParts, getFigureStringWithFace, isSellableNotOwned, retryId ]); if(!partItem) return null;