mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-19 05:46:27 +01:00
Add PetImageView
This commit is contained in:
parent
16178abae3
commit
428f4bb2c8
@ -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';
|
||||
|
7
src/views/pet-image/PetImage.scss
Normal file
7
src/views/pet-image/PetImage.scss
Normal file
@ -0,0 +1,7 @@
|
||||
.pet-image {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
}
|
48
src/views/pet-image/PetImageView.tsx
Normal file
48
src/views/pet-image/PetImageView.tsx
Normal 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>;
|
||||
}
|
7
src/views/pet-image/PetImageView.types.ts
Normal file
7
src/views/pet-image/PetImageView.types.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export interface PetImageViewProps
|
||||
{
|
||||
figure: string;
|
||||
headOnly?: boolean;
|
||||
direction?: number;
|
||||
scale?: number;
|
||||
}
|
Loading…
Reference in New Issue
Block a user