Skip to content

Commit

Permalink
Remove Pinnable and Pinned component to prevent confusion, modify how…
Browse files Browse the repository at this point in the history
… pinned state is determined in relevant react components
  • Loading branch information
Stalgia Grigg committed Jun 2, 2023
1 parent 93cf42d commit 8fcc847
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 33 deletions.
2 changes: 0 additions & 2 deletions src/bit-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
1 change: 0 additions & 1 deletion src/bit-systems/object-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Interacted,
ObjectMenu,
ObjectMenuTarget,
Pinned,
RemoteRight,
Rigidbody
} from "../bit-components";
Expand Down
9 changes: 0 additions & 9 deletions src/components/pinnable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { addComponent, removeComponent } from "bitecs";
import { Pinnable, Pinned } from "../bit-components";

AFRAME.registerComponent("pinnable", {
schema: {
Expand All @@ -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() {
Expand Down
15 changes: 6 additions & 9 deletions src/react-components/room/object-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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")
);
Expand Down
15 changes: 3 additions & 12 deletions src/systems/userinput/devices/app-aware-touchscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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))
);
Expand Down

0 comments on commit 8fcc847

Please sign in to comment.