Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object list fixes #6291

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/react-components/room/object-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { rotateInPlaceAroundWorldUp, affixToWorldUp } from "../../utils/three-ut
import { getPromotionTokenForFile } from "../../utils/media-utils";
import { hasComponent } from "bitecs";
import { isPinned as getPinnedState } from "../../bit-systems/networking";
import { MediaInfo, Static } from "../../bit-components";
import { AEntity, MediaInfo, Static } from "../../bit-components";
import { deleteTheDeletableAncestor } from "../../bit-systems/delete-entity-system";
import { isAEntityPinned } from "../../systems/hold-system";

export function isMe(object) {
return object.id === "avatar-rig";
Expand Down Expand Up @@ -39,8 +40,16 @@ export function getObjectUrl(object) {
return null;
}

function isObjectPinned(world, eid) {
if (hasComponent(world, AEntity, eid)) {
return isAEntityPinned(APP.world, eid);
} else {
return getPinnedState(eid);
}
}

export function usePinObject(hubChannel, scene, object) {
const [isPinned, setIsPinned] = useState(getPinnedState(object.eid));
const [isPinned, setIsPinned] = useState(isObjectPinned(APP.world, object.eid));

const pinObject = useCallback(() => {
const el = object.el;
Expand Down Expand Up @@ -71,11 +80,11 @@ export function usePinObject(hubChannel, scene, object) {
const el = object.el;

function onPinStateChanged() {
setIsPinned(getPinnedState(el.eid));
setIsPinned(isObjectPinned(APP.world, object.eid));
}
el.addEventListener("pinned", onPinStateChanged);
el.addEventListener("unpinned", onPinStateChanged);
setIsPinned(getPinnedState(el.eid));
setIsPinned(isObjectPinned(APP.world, object.eid));
return () => {
el.removeEventListener("pinned", onPinStateChanged);
el.removeEventListener("unpinned", onPinStateChanged);
Expand Down Expand Up @@ -148,7 +157,7 @@ export function useRemoveObject(hubChannel, scene, object) {
const canRemoveObject = !!(
scene.is("entered") &&
!isPlayer(object) &&
!getPinnedState(eid) &&
!isObjectPinned(APP.world, object.eid) &&
!hasComponent(APP.world, Static, eid) &&
hubChannel.can("spawn_and_move_media")
);
Expand Down
2 changes: 1 addition & 1 deletion src/systems/hold-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function hasPermissionToGrab(world, eid) {
return canMove(world.eid2obj.get(eid).el);
}

function isAEntityPinned(world, eid) {
export function isAEntityPinned(world, eid) {
if (hasComponent(world, AEntity, eid)) {
const el = world.eid2obj.get(eid).el;
return !!el.components?.pinnable?.data?.pinned;
Expand Down
Loading