import { AvatarEditorFigureCategory, AvatarFigurePartType } 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 { InfiniteGrid } from '../../../layout'; import { AvatarEditorIcon } from '../AvatarEditorIcon'; export const AvatarEditorFigureSetItemView: FC<{ setType: string; partItem: IAvatarEditorCategoryPartItem; isSelected: boolean; width?: string; } & LayoutGridItemProps> = props => { const { setType = null, partItem = null, isSelected = false, width = '100%', ...rest } = props; const [ assetUrl, setAssetUrl ] = useState(''); const { activeModelKey = '', selectedColorParts = null, getFigureStringWithFace = null } = useAvatarEditor(); const clubLevel = partItem.partSet?.clubLevel ?? 0; const isHC = !GetConfigurationValue('hc.disabled', false) && (clubLevel > 0); const isLocked = isHC && (GetClubMemberLevel() < clubLevel); const isSellableNotOwned = partItem.isSellableNotOwned ?? false; useEffect(() => { if(!setType || !setType.length || !partItem) return; const loadImage = async () => { const partClubLevel = partItem.partSet?.clubLevel ?? 0; const partIsHC = !GetConfigurationValue('hc.disabled', false) && (partClubLevel > 0); const partIsLocked = partIsHC && (GetClubMemberLevel() < partClubLevel); let url: string = null; if(setType === AvatarFigurePartType.HEAD && activeModelKey !== AvatarEditorFigureCategory.NFT) { url = await AvatarEditorThumbnailsHelper.buildForFace(getFigureStringWithFace(partItem.id), partIsLocked || isSellableNotOwned); } else { url = await AvatarEditorThumbnailsHelper.build( setType, partItem, partItem.usesColor, selectedColorParts[setType] ?? null, partIsLocked || isSellableNotOwned ); } if(url && url.length) setAssetUrl(url); }; loadImage(); }, [ setType, partItem, selectedColorParts, getFigureStringWithFace, isSellableNotOwned, activeModelKey ]); if(!partItem) return null; return ( { !partItem.isClear && isHC && } { partItem.isClear && } { !partItem.isClear && partItem.partSet.isSellable && !isSellableNotOwned && } { !partItem.isClear && isSellableNotOwned &&
}
); };