Add noFollow option to ObjectLocationView

This commit is contained in:
Bill 2021-06-30 19:47:48 -04:00
parent 9a55b57022
commit 97db013e45
2 changed files with 16 additions and 4 deletions

View File

@ -5,7 +5,7 @@ import { ObjectLocationViewProps } from './ObjectLocationView.types';
export const ObjectLocationView: FC<ObjectLocationViewProps> = props =>
{
const { objectId = -1, category = -1, children = null } = props;
const { objectId = -1, category = -1, noFollow = false, children = null } = props;
const [ pos, setPos ] = useState<{ x: number, y: number }>({ x: -1, y: -1});
const elementRef = useRef<HTMLDivElement>();
@ -31,13 +31,24 @@ export const ObjectLocationView: FC<ObjectLocationViewProps> = props =>
useEffect(() =>
{
Nitro.instance.ticker.add(updatePosition);
let remove = false;
if(noFollow)
{
updatePosition();
}
else
{
remove = true;
Nitro.instance.ticker.add(updatePosition);
}
return () =>
{
Nitro.instance.ticker.remove(updatePosition);
if(remove) Nitro.instance.ticker.remove(updatePosition);
}
}, [ updatePosition ]);
}, [ updatePosition, noFollow ]);
return (
<div ref={ elementRef } className={ 'object-location position-absolute ' + (pos.x > -1 ? 'visible' : 'invisible') } style={ { left: pos.x, top: pos.y } }>

View File

@ -2,4 +2,5 @@ export interface ObjectLocationViewProps
{
objectId: number;
category: number;
noFollow?: boolean;
}