import { AvatarEditorFigureCategory } from '@nitrots/nitro-renderer'; import { FC, useEffect, useMemo, useState } from 'react'; import { FigureData, IAvatarEditorCategory } from '../../../api'; import { Column, Flex, Grid } from '../../../common'; import { useAvatarEditor } from '../../../hooks'; import { AvatarEditorIcon } from './AvatarEditorIcon'; import { AvatarEditorFigureSetView } from './figure-set'; import { AvatarEditorPaletteSetView } from './palette-set'; export const AvatarEditorModelView: FC<{ name: string, categories: IAvatarEditorCategory[] }> = props => { const { name = '', categories = [] } = props; const [ activeSetType, setActiveSetType ] = useState(''); const { maxPaletteCount = 1 } = useAvatarEditor(); const activeCategory = useMemo(() => { return categories.find(category => category.setType === activeSetType) ?? null; }, [ categories, activeSetType ]); const setGender = (gender: string) => { // } useEffect(() => { if(!activeCategory) return; // we need to run this when we change which parts r selected /* for(const partItem of activeCategory.partItems) { if(!partItem || !part.isSelected) continue; setMaxPaletteCount(part.maxColorIndex || 1); break; } */ }, [ activeCategory ]) useEffect(() => { if(!categories || !categories.length) return; setActiveSetType(categories[0]?.setType) }, [ categories ]); if(!activeCategory) return null; return ( { (name === AvatarEditorFigureCategory.GENERIC) && <> setGender(FigureData.MALE) }> setGender(FigureData.FEMALE) }> } { (name !== AvatarEditorFigureCategory.GENERIC) && (categories.length > 0) && categories.map(category => { return ( setActiveSetType(category.setType) }> ); }) } { (maxPaletteCount >= 1) && } { (maxPaletteCount === 2) && } ); }