🆙 Small update

This commit is contained in:
duckietm
2026-04-01 10:23:00 +02:00
parent ef008804d7
commit aa10cb54db
2 changed files with 33 additions and 20 deletions
+24 -19
View File
@@ -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
@@ -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<string>('');
const [ retryId, setRetryId ] = useState<number>(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;