From 5569aee98aed9ea7b55cf1b08c383fd2f1cf9cc8 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Wed, 13 Sep 2023 12:19:20 +0200 Subject: [PATCH] Fix move permissions --- src/systems/hold-system.js | 3 +-- src/utils/permissions-utils.js | 42 +++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/systems/hold-system.js b/src/systems/hold-system.js index 149e6f21de..7c262c23c4 100644 --- a/src/systems/hold-system.js +++ b/src/systems/hold-system.js @@ -27,8 +27,7 @@ const GRAB_HAND_LEFT = paths.actions.leftHand.grab; const DROP_HAND_LEFT = paths.actions.leftHand.drop; function hasPermissionToGrab(world, eid) { - if (!hasComponent(world, AEntity, eid)) return true; - return canMove(world.eid2obj.get(eid).el); + return canMove(hasComponent(world, AEntity, eid) ? world.eid2obj.get(eid).el : eid); } function isAEntityPinned(world, eid) { diff --git a/src/utils/permissions-utils.js b/src/utils/permissions-utils.js index 1ef6bb9beb..a2fa3bf12d 100644 --- a/src/utils/permissions-utils.js +++ b/src/utils/permissions-utils.js @@ -2,6 +2,7 @@ import { hasComponent } from "bitecs"; import { HoldableButton } from "../bit-components"; +import { isPinned } from "../bit-systems/networking"; // https://github.com/mozilla/hubs/wiki/Hubs-authorization export function showHoverEffect(el) { @@ -18,22 +19,31 @@ export function showHoverEffect(el) { return (isSpawner || !isPinned || isFrozen) && canMove; } -export function canMove(entity) { - const isPinned = entity.components.pinnable && entity.components.pinnable.data.pinned; - const networkedTemplate = entity && entity.components.networked && entity.components.networked.data.template; - const isPen = networkedTemplate === "#interactable-pen"; - const spawnerTemplate = - entity && entity.components["super-spawner"] && entity.components["super-spawner"].data.template; - const isEmojiSpawner = spawnerTemplate === "#interactable-emoji"; - const isEmoji = !!entity.components.emoji; - return ( - hasComponent(APP.world, HoldableButton, entity.eid) || - ((isEmoji || isEmojiSpawner - ? window.APP.hubChannel.can("spawn_emoji") - : window.APP.hubChannel.can("spawn_and_move_media")) && - (!isPinned || window.APP.hubChannel.can("pin_objects")) && - (!isPen || window.APP.hubChannel.can("spawn_drawing"))) - ); +export function canMove(elOrEid) { + if (!elOrEid.isEntity) { + return ( + hasComponent(APP.world, HoldableButton, elOrEid) || + (window.APP.hubChannel.can("spawn_and_move_media") && + (!isPinned(elOrEid) || window.APP.hubChannel.can("pin_objects"))) + ); + } else { + const isPinned = elOrEid.components.pinnable && elOrEid.components.pinnable.data.pinned; + // TODO Move pen/emojis to bitECS when it's migrated + const networkedTemplate = elOrEid && elOrEid.components.networked && elOrEid.components.networked.data.template; + const isPen = networkedTemplate === "#interactable-pen"; + const spawnerTemplate = + elOrEid && elOrEid.components["super-spawner"] && elOrEid.components["super-spawner"].data.template; + const isEmojiSpawner = spawnerTemplate === "#interactable-emoji"; + const isEmoji = !!elOrEid.components.emoji; + return ( + hasComponent(APP.world, HoldableButton, elOrEid.eid) || + ((isEmoji || isEmojiSpawner + ? window.APP.hubChannel.can("spawn_emoji") + : window.APP.hubChannel.can("spawn_and_move_media")) && + (!isPinned || window.APP.hubChannel.can("pin_objects")) && + (!isPen || window.APP.hubChannel.can("spawn_drawing"))) + ); + } } function indexForComponent(component, schema) {