Add PetImageView

This commit is contained in:
Bill 2021-04-29 04:00:10 -04:00
parent 16178abae3
commit 428f4bb2c8
4 changed files with 63 additions and 0 deletions

View File

@ -7,6 +7,7 @@
@import './loading/LoadingView';
@import './main/MainView';
@import './navigator/NavigatorView';
@import './pet-image/PetImage';
@import './purse/PurseView';
@import './right-side/RightSideView';
@import './room/RoomView';

View File

@ -0,0 +1,7 @@
.pet-image {
position: relative;
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-position: center;
}

View File

@ -0,0 +1,48 @@
import { PetFigureData, TextureUtils, Vector3d } from 'nitro-renderer';
import { FC, useCallback, useEffect, useState } from 'react';
import { GetRoomEngine } from '../../api';
import { PetImageViewProps } from './PetImageView.types';
export const PetImageView: FC<PetImageViewProps> = props =>
{
const { figure = '', headOnly = false, direction = 0, scale = 1 } = props;
const [ petUrl, setPetUrl ] = useState<string>(null);
const getPetImageUrl = useCallback(() =>
{
let url = null;
const petFigureData = new PetFigureData(figure);
const imageResult = GetRoomEngine().getRoomObjectPetImage(petFigureData.typeId, petFigureData.paletteId, petFigureData.color, new Vector3d((direction * 45)), 64, {
imageReady: (id, texture, image) =>
{
if(image) setPetUrl(image.src);
else if(texture) setPetUrl(TextureUtils.generateImageUrl(texture));
},
imageFailed: (id) =>
{
}
}, headOnly, 0, petFigureData.customParts, 'std');
if(imageResult)
{
const image = imageResult.getImage();
if(image) url = image.src;
}
return url;
}, [ figure, headOnly, direction ]);
useEffect(() =>
{
setPetUrl(getPetImageUrl());
}, [ getPetImageUrl ]);
const url = `url('${ petUrl }')`;
return <div className={ 'pet-image scale-' + scale } style={ (petUrl && url.length) ? { backgroundImage: url } : {} }></div>;
}

View File

@ -0,0 +1,7 @@
export interface PetImageViewProps
{
figure: string;
headOnly?: boolean;
direction?: number;
scale?: number;
}