From 8fcc8473ae507ab69fa1f2aef86783fa795dfb5d Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Fri, 2 Jun 2023 10:21:43 -0400 Subject: [PATCH] Remove Pinnable and Pinned component to prevent confusion, modify how pinned state is determined in relevant react components --- src/bit-components.js | 2 -- src/bit-systems/object-menu.ts | 1 - src/components/pinnable.js | 9 --------- src/react-components/room/object-hooks.js | 15 ++++++--------- .../userinput/devices/app-aware-touchscreen.js | 15 +++------------ 5 files changed, 9 insertions(+), 33 deletions(-) diff --git a/src/bit-components.js b/src/bit-components.js index d831e8d0d1..28a82778b7 100644 --- a/src/bit-components.js +++ b/src/bit-components.js @@ -124,8 +124,6 @@ export const PhysicsShape = defineComponent({ heightfieldDistance: Types.f32, flags: Types.ui8 }); -export const Pinnable = defineComponent(); -export const Pinned = defineComponent(); export const DestroyAtExtremeDistance = defineComponent(); export const MediaLoading = defineComponent(); export const FloatyObject = defineComponent({ flags: Types.ui8, releaseGravity: Types.f32 }); diff --git a/src/bit-systems/object-menu.ts b/src/bit-systems/object-menu.ts index 595b7393e4..3aaba8597c 100644 --- a/src/bit-systems/object-menu.ts +++ b/src/bit-systems/object-menu.ts @@ -7,7 +7,6 @@ import { Interacted, ObjectMenu, ObjectMenuTarget, - Pinned, RemoteRight, Rigidbody } from "../bit-components"; diff --git a/src/components/pinnable.js b/src/components/pinnable.js index aa1533a746..94169be00c 100644 --- a/src/components/pinnable.js +++ b/src/components/pinnable.js @@ -1,5 +1,4 @@ import { addComponent, removeComponent } from "bitecs"; -import { Pinnable, Pinned } from "../bit-components"; AFRAME.registerComponent("pinnable", { schema: { @@ -16,18 +15,10 @@ AFRAME.registerComponent("pinnable", { this.el.addEventListener("owned-pager-page-changed", this._persist); this.el.addEventListener("owned-video-state-changed", this._persistAndAnimate); - - addComponent(APP.world, Pinnable, this.el.object3D.eid); }, update() { this._animate(); - - if (this.data.pinned) { - addComponent(APP.world, Pinned, this.el.object3D.eid); - } else { - removeComponent(APP.world, Pinned, this.el.object3D.eid); - } }, _persistAndAnimate() { diff --git a/src/react-components/room/object-hooks.js b/src/react-components/room/object-hooks.js index 66a7d83354..7e56253e9e 100644 --- a/src/react-components/room/object-hooks.js +++ b/src/react-components/room/object-hooks.js @@ -3,11 +3,8 @@ import { removeNetworkedObject } from "../../utils/removeNetworkedObject"; import { rotateInPlaceAroundWorldUp, affixToWorldUp } from "../../utils/three-utils"; import { getPromotionTokenForFile } from "../../utils/media-utils"; import { hasComponent } from "bitecs"; -import { Pinnable, Pinned, Static } from "../../bit-components"; - -function getPinnedState(el) { - return !!(hasComponent(APP.world, Pinnable, el.eid) && hasComponent(APP.world, Pinned, el.eid)); -} +import { Static } from "../../bit-components"; +import { isPinned } from "../../bit-systems/networking"; export function isMe(object) { return object.el.id === "avatar-rig"; @@ -31,7 +28,7 @@ export function getObjectUrl(object) { } export function usePinObject(hubChannel, scene, object) { - const [isPinned, setIsPinned] = useState(getPinnedState(object.el)); + const [isPinned, setIsPinned] = useState(isPinned(object.el.eid)); const pinObject = useCallback(() => { const el = object.el; @@ -57,11 +54,11 @@ export function usePinObject(hubChannel, scene, object) { const el = object.el; function onPinStateChanged() { - setIsPinned(getPinnedState(el)); + setIsPinned(isPinned(el.eid)); } el.addEventListener("pinned", onPinStateChanged); el.addEventListener("unpinned", onPinStateChanged); - setIsPinned(getPinnedState(el)); + setIsPinned(isPinned(el.eid)); return () => { el.removeEventListener("pinned", onPinStateChanged); el.removeEventListener("unpinned", onPinStateChanged); @@ -125,7 +122,7 @@ export function useRemoveObject(hubChannel, scene, object) { const canRemoveObject = !!( scene.is("entered") && !isPlayer(object) && - !getPinnedState(el) && + !isPinned(el.eid) && !hasComponent(APP.world, Static, el.eid) && hubChannel.can("spawn_and_move_media") ); diff --git a/src/systems/userinput/devices/app-aware-touchscreen.js b/src/systems/userinput/devices/app-aware-touchscreen.js index 1c77657601..449a231a31 100644 --- a/src/systems/userinput/devices/app-aware-touchscreen.js +++ b/src/systems/userinput/devices/app-aware-touchscreen.js @@ -5,16 +5,9 @@ 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, - Pinnable, - Pinned, - SingleActionButton, - Static -} from "../../../bit-components"; +import { AEntity, HeldRemoteRight, OffersRemoteConstraint, SingleActionButton, Static } from "../../../bit-components"; import { anyEntityWith } from "../../../utils/bit-utils"; +import { isPinned } from "../../../bit-systems/networking"; const MOVE_CURSOR_JOB = "MOVE CURSOR"; const MOVE_CAMERA_JOB = "MOVE CAMERA"; @@ -70,14 +63,12 @@ function shouldMoveCursor(touch, rect, raycaster) { .get(remoteHoverTarget) .el.matches(".interactable, .interactable *, .occupiable-waypoint-icon, .teleport-waypoint-icon")); - const isPinned = - hasComponent(APP.world, Pinnable, remoteHoverTarget) && hasComponent(APP.world, Pinned, remoteHoverTarget); const isSceneFrozen = AFRAME.scenes[0].is("frozen"); // TODO isStatic is likely a superfluous check for things matched via OffersRemoteConstraint const isStatic = hasComponent(APP.world, Static, remoteHoverTarget); return ( - isSingleActionButton || (isInteractable && (isSceneFrozen || !isPinned) && !isStatic) + isSingleActionButton || (isInteractable && (isSceneFrozen || !isPinned(remoteHoverTarget)) && !isStatic) // TODO check canMove //&& (remoteHoverTarget && canMove(remoteHoverTarget)) );