Fix locked tokens being selected in tools other than the move tool

This commit is contained in:
Mitchell McCaffrey 2021-08-04 07:42:36 +10:00
parent 3ad726f5ad
commit 9e5eb9d258
2 changed files with 11 additions and 4 deletions

View File

@ -42,6 +42,7 @@ type MapTokenProps = {
onTokenDragStart: TokenDragEventHandler; onTokenDragStart: TokenDragEventHandler;
onTokenDragEnd: TokenDragEventHandler; onTokenDragEnd: TokenDragEventHandler;
draggable: boolean; draggable: boolean;
selectable: boolean;
fadeOnHover: boolean; fadeOnHover: boolean;
map: Map; map: Map;
selected: boolean; selected: boolean;
@ -55,6 +56,7 @@ function Token({
onTokenDragStart, onTokenDragStart,
onTokenDragEnd, onTokenDragEnd,
draggable, draggable,
selectable,
fadeOnHover, fadeOnHover,
map, map,
selected, selected,
@ -153,7 +155,7 @@ function Token({
} }
function handleClick() { function handleClick() {
if (draggable && tokenRef.current) { if (selectable && tokenRef.current) {
onTokenMenuOpen(tokenState.id, tokenRef.current); onTokenMenuOpen(tokenState.id, tokenRef.current);
} }
} }
@ -165,7 +167,7 @@ function Token({
if (draggable) { if (draggable) {
setPreventMapInteraction(true); setPreventMapInteraction(true);
} }
if (tokenState.locked && map.owner === userId) { if (tokenState.locked && selectable) {
tokenPointerDownTimeRef.current = event.evt.timeStamp; tokenPointerDownTimeRef.current = event.evt.timeStamp;
} }
} }
@ -174,9 +176,9 @@ function Token({
if (draggable) { if (draggable) {
setPreventMapInteraction(false); setPreventMapInteraction(false);
} }
// Check token click when locked and we are the map owner // Check token click when locked and selectable
// We can't use onClick because that doesn't check pointer distance // We can't use onClick because that doesn't check pointer distance
if (tokenState.locked && map.owner === userId && tokenRef.current) { if (tokenState.locked && selectable && tokenRef.current) {
// If down and up time is small trigger a click // If down and up time is small trigger a click
const delta = event.evt.timeStamp - tokenPointerDownTimeRef.current; const delta = event.evt.timeStamp - tokenPointerDownTimeRef.current;
if (delta < 300) { if (delta < 300) {

View File

@ -99,6 +99,11 @@ function useMapTokens(
!(tokenState.id in disabledTokens) && !(tokenState.id in disabledTokens) &&
!tokenState.locked !tokenState.locked
} }
selectable={
selectedToolId === "move" &&
((!(tokenState.id in disabledTokens) && !tokenState.locked) ||
map.owner === userId)
}
fadeOnHover={selectedToolId === "drawing"} fadeOnHover={selectedToolId === "drawing"}
map={map} map={map}
selected={ selected={