Skip to content

Commit

Permalink
Merge pull request #6253 from mozilla/bitecs-fix-move-permissions
Browse files Browse the repository at this point in the history
bitECS: Fix move permissions
  • Loading branch information
keianhzo authored Sep 28, 2023
2 parents 2b999e9 + 5dc6fa3 commit c01d792
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/systems/hold-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
AEntity
} from "../bit-components";
import { canMove } from "../utils/permissions-utils";
import { canMove as canMoveEntity } from "../utils/bit-permissions-utils";
import { isPinned } from "../bit-systems/networking";

const GRAB_REMOTE_RIGHT = paths.actions.cursor.right.grab;
Expand All @@ -27,8 +28,11 @@ 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);
if (hasComponent(world, AEntity, eid)) {
return canMove(world.eid2obj.get(eid).el);
} else {
return canMoveEntity(eid);
}
}

export function isAEntityPinned(world, eid) {
Expand Down
11 changes: 7 additions & 4 deletions src/systems/userinput/devices/app-aware-touchscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { paths } from "../paths";
import { Pose } from "../pose";
import { touchIsAssigned, jobIsAssigned, assign, unassign, findByJob, findByTouch } from "./touchscreen/assignments";
import { findRemoteHoverTarget } from "../../../components/cursor-controller";
// import { canMove } from "../../../utils/permissions-utils";
import ResizeObserver from "resize-observer-polyfill";
import { hasComponent } from "bitecs";
import { AEntity, HeldRemoteRight, OffersRemoteConstraint, SingleActionButton, Static } from "../../../bit-components";
import { anyEntityWith } from "../../../utils/bit-utils";
import { isPinned } from "../../../bit-systems/networking";
import { canMove } from "../../../utils/bit-permissions-utils";

const MOVE_CURSOR_JOB = "MOVE CURSOR";
const MOVE_CAMERA_JOB = "MOVE CAMERA";
Expand Down Expand Up @@ -68,9 +68,12 @@ function shouldMoveCursor(touch, rect, raycaster) {
// TODO isStatic is likely a superfluous check for things matched via OffersRemoteConstraint
const isStatic = hasComponent(APP.world, Static, remoteHoverTarget);
return (
isSingleActionButton || (isInteractable && (isSceneFrozen || !isPinned(remoteHoverTarget)) && !isStatic)
// TODO check canMove
//&& (remoteHoverTarget && canMove(remoteHoverTarget))
isSingleActionButton ||
(isInteractable &&
(isSceneFrozen || !isPinned(remoteHoverTarget)) &&
!isStatic &&
remoteHoverTarget &&
canMove(remoteHoverTarget))
);
}

Expand Down
11 changes: 11 additions & 0 deletions src/utils/bit-permissions-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { hasComponent } from "bitecs";
import { HoldableButton } from "../bit-components";
import { isPinned } from "../bit-systems/networking";

export function canMove(eid) {
// Add support to pen/emojis when those are migrated to bitECS
return (
hasComponent(APP.world, HoldableButton, eid) ||
(APP.hubChannel.can("spawn_and_move_media") && (!isPinned(eid) || APP.hubChannel.can("pin_objects")))
);
}

0 comments on commit c01d792

Please sign in to comment.