mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-27 08:00:51 +01:00
Update PetImageView
This commit is contained in:
parent
bf780ec546
commit
ca18bf2f30
@ -1,15 +1,15 @@
|
|||||||
import { PetFigureData, TextureUtils, Vector3d } from '@nitrots/nitro-renderer';
|
import { PetFigureData, TextureUtils, Vector3d } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useCallback, useEffect, useState } from 'react';
|
import { FC, useEffect, useRef, useState } from 'react';
|
||||||
import { GetRoomEngine } from '../../../api';
|
import { GetRoomEngine } from '../../../api';
|
||||||
import { PetImageViewProps } from './PetImageView.types';
|
import { PetImageViewProps } from './PetImageView.types';
|
||||||
|
|
||||||
export const PetImageView: FC<PetImageViewProps> = props =>
|
export const PetImageView: FC<PetImageViewProps> = props =>
|
||||||
{
|
{
|
||||||
const { figure = '', typeId = -1, paletteId = -1, color = 0xFFFFFF, customParts = [], posture = 'std', headOnly = false, direction = 0, scale = 1 } = props;
|
const { figure = '', typeId = -1, paletteId = -1, color = 0xFFFFFF, customParts = [], posture = 'std', headOnly = false, direction = 0, scale = 1 } = props;
|
||||||
|
|
||||||
const [ petUrl, setPetUrl ] = useState<string>(null);
|
const [ petUrl, setPetUrl ] = useState<string>(null);
|
||||||
|
const isDisposed = useRef(false);
|
||||||
|
|
||||||
const getPetImageUrl = useCallback(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
let url = null;
|
let url = null;
|
||||||
|
|
||||||
@ -31,6 +31,8 @@ export const PetImageView: FC<PetImageViewProps> = props =>
|
|||||||
const imageResult = GetRoomEngine().getRoomObjectPetImage(petTypeId, petPaletteId, petColor, new Vector3d((direction * 45)), 64, {
|
const imageResult = GetRoomEngine().getRoomObjectPetImage(petTypeId, petPaletteId, petColor, new Vector3d((direction * 45)), 64, {
|
||||||
imageReady: (id, texture, image) =>
|
imageReady: (id, texture, image) =>
|
||||||
{
|
{
|
||||||
|
if(isDisposed.current) return;
|
||||||
|
|
||||||
if(image) setPetUrl(image.src);
|
if(image) setPetUrl(image.src);
|
||||||
else if(texture) setPetUrl(TextureUtils.generateImageUrl(texture));
|
else if(texture) setPetUrl(TextureUtils.generateImageUrl(texture));
|
||||||
},
|
},
|
||||||
@ -44,16 +46,21 @@ export const PetImageView: FC<PetImageViewProps> = props =>
|
|||||||
{
|
{
|
||||||
const image = imageResult.getImage();
|
const image = imageResult.getImage();
|
||||||
|
|
||||||
if(image) url = image.src;
|
if(image) setPetUrl(image.src);
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
|
}
|
||||||
}, [ figure, typeId, paletteId, color, customParts, posture, headOnly, direction ]);
|
}, [ figure, typeId, paletteId, color, customParts, posture, headOnly, direction ]);
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
setPetUrl(getPetImageUrl());
|
isDisposed.current = false;
|
||||||
}, [ getPetImageUrl ]);
|
|
||||||
|
return () =>
|
||||||
|
{
|
||||||
|
isDisposed.current = true;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const url = `url('${ petUrl }')`;
|
const url = `url('${ petUrl }')`;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user