Skip to content

Commit

Permalink
Fix move permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Sep 13, 2023
1 parent ebabfdf commit 5569aee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/systems/hold-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
42 changes: 26 additions & 16 deletions src/utils/permissions-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 5569aee

Please sign in to comment.