mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
🆙 Fixed Buddy Pets showing in catalogue
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { AvatarFigureContainer, GetAvatarRenderManager, IFigurePartSet } from '@nitrots/nitro-renderer';
|
||||
|
||||
const getFirstSelectableColorForSetType = (setType: string): number =>
|
||||
{
|
||||
const structure = GetAvatarRenderManager()?.structureData;
|
||||
|
||||
if(!structure) return -1;
|
||||
|
||||
const set = structure.getSetType(setType);
|
||||
|
||||
if(!set) return -1;
|
||||
|
||||
const palette = structure.getPalette(set.paletteID);
|
||||
|
||||
if(!palette) return -1;
|
||||
|
||||
for(const color of palette.colors.getValues())
|
||||
{
|
||||
if(!color || !color.isSelectable) continue;
|
||||
|
||||
return color.id;
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Builds a new figure string starting from the base figure and applying the
|
||||
* provided figure part set IDs (e.g. a purchasable clothing set or pet set).
|
||||
*
|
||||
* When the base figure does not already define colours for the set type being
|
||||
* applied (common for pet "pt" sets on an avatar that has never worn one), the
|
||||
* first selectable palette colour is used so the part still renders instead of
|
||||
* being dropped.
|
||||
*/
|
||||
export const BuildPurchasableClothingFigure = (baseFigure: string, setIds: number[]): string =>
|
||||
{
|
||||
const manager = GetAvatarRenderManager();
|
||||
|
||||
if(!manager) return baseFigure;
|
||||
|
||||
const container = new AvatarFigureContainer(baseFigure ?? '');
|
||||
const structure = manager.structureData;
|
||||
|
||||
for(const setId of setIds)
|
||||
{
|
||||
const partSet: IFigurePartSet = structure?.getFigurePartSet(setId);
|
||||
|
||||
if(!partSet) continue;
|
||||
|
||||
let colorIds = container.getPartColorIds(partSet.type) ?? [];
|
||||
|
||||
if(!colorIds.length)
|
||||
{
|
||||
const defaultColor = getFirstSelectableColorForSetType(partSet.type);
|
||||
|
||||
if(defaultColor >= 0) colorIds = [ defaultColor ];
|
||||
}
|
||||
|
||||
container.updatePart(partSet.type, partSet.id, colorIds);
|
||||
}
|
||||
|
||||
return container.getFigureString();
|
||||
};
|
||||
@@ -2,5 +2,6 @@ export * from './AvatarEditorAction';
|
||||
export * from './AvatarEditorColorSorter';
|
||||
export * from './AvatarEditorPartSorter';
|
||||
export * from './AvatarEditorThumbnailsHelper';
|
||||
export * from './BuildPurchasableClothingFigure';
|
||||
export * from './IAvatarEditorCategory';
|
||||
export * from './IAvatarEditorCategoryPartItem';
|
||||
|
||||
Reference in New Issue
Block a user