Add rotate & state click on room previewer

This commit is contained in:
Bill 2022-03-16 05:38:15 -04:00
parent ff46a89e79
commit d0145cc0ed

View File

@ -1,5 +1,5 @@
import { ColorConverter, IRoomRenderingCanvas, RoomPreviewer, TextureUtils } from '@nitrots/nitro-renderer'; import { ColorConverter, IRoomRenderingCanvas, RoomPreviewer, TextureUtils } from '@nitrots/nitro-renderer';
import { FC, useCallback, useEffect, useRef, useState } from 'react'; import { FC, MouseEvent, useCallback, useEffect, useRef, useState } from 'react';
import { GetNitroInstance } from '../../api'; import { GetNitroInstance } from '../../api';
export interface LayoutRoomPreviewerViewProps export interface LayoutRoomPreviewerViewProps
@ -14,6 +14,20 @@ export const LayoutRoomPreviewerView: FC<LayoutRoomPreviewerViewProps> = props =
const [ renderingCanvas, setRenderingCanvas ] = useState<IRoomRenderingCanvas>(null); const [ renderingCanvas, setRenderingCanvas ] = useState<IRoomRenderingCanvas>(null);
const elementRef = useRef<HTMLDivElement>(); const elementRef = useRef<HTMLDivElement>();
const onClick = (event: MouseEvent<HTMLDivElement>) =>
{
if(!roomPreviewer) return;
if(event.shiftKey)
{
roomPreviewer.changeRoomObjectDirection();
}
else
{
roomPreviewer.changeRoomObjectState();
}
}
const update = useCallback((time: number) => const update = useCallback((time: number) =>
{ {
if(!roomPreviewer || !renderingCanvas || !elementRef.current) return; if(!roomPreviewer || !renderingCanvas || !elementRef.current) return;
@ -83,7 +97,7 @@ export const LayoutRoomPreviewerView: FC<LayoutRoomPreviewerViewProps> = props =
return ( return (
<div className="room-preview-container"> <div className="room-preview-container">
<div ref={ elementRef } className="room-preview-image" style={ { height } } /> <div ref={ elementRef } className="room-preview-image" style={ { height } } onClick={ onClick } />
{ props.children } { props.children }
</div> </div>
); );