Skip to content

Commit

Permalink
Simplify treesidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
ostatni5 committed May 18, 2023
1 parent eb25735 commit f956847
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/ThreeEditor/components/Sidebar/EditorSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export function EditorSidebar(props: { editor: Editor }) {
<SidebarTree
editor={editor}
sources={[editor.zoneManager.worldZone]}
dragDisabled
/>
<Divider sx={{ marginBottom: t => t.spacing(1) }} />
<SidebarTree
Expand Down
26 changes: 10 additions & 16 deletions src/ThreeEditor/components/Sidebar/SidebarTree/SidebarTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import { SimulationElement } from '../../../Simulation/Base/SimulationElement';
import { SidebarTreeItem, TreeItem } from './SidebarTreeItem';
import { Divider } from '@mui/material';
import { hasVisibleChildren } from '../../../../util/hooks/useKeyboardEditorControls';
import { isQuantity } from '../../../Simulation/Scoring/ScoringQuantity';
import { ChangeObjectOrderCommand } from '../../../js/commands/ChangeObjectOrderCommand';
import { isWorldZone } from '../../../Simulation/Zones/WorldZone/WorldZone';
import { generateUUID } from 'three/src/math/MathUtils';

type TreeSource = (Object3D[] | Object3D)[];

export function SidebarTree(props: { editor: Editor; sources: TreeSource }) {
export function SidebarTree(props: {
editor: Editor;
sources: TreeSource;
dragDisabled?: boolean;
}) {
const { editor, sources } = props;

const treeRef = useRef<TreeMethods>(null);
Expand Down Expand Up @@ -90,20 +92,12 @@ export function SidebarTree(props: { editor: Editor; sources: TreeSource }) {

const objectRefs = useRef<Map<string, HTMLDivElement>>(new Map());

const canDrop = (
source: TreeItem | undefined,
target: TreeItem | undefined,
dropTargetId: string | number
): boolean => {
const canDrop = (source: TreeItem | undefined, dropTargetId: string | number): boolean => {
if (!source) return false;

if (source.data?.treeId !== treeId) return false;

const object3d = source.data?.object;

if (isQuantity(object3d)) return object3d.parent === target?.data?.object;

return source.parent === dropTargetId;
return source.parent === dropTargetId; // only allow drop on same parent
};

return (
Expand Down Expand Up @@ -137,10 +131,10 @@ export function SidebarTree(props: { editor: Editor; sources: TreeSource }) {
);
}
}}
canDrop={(_, { dropTarget, dragSource, dropTargetId }) => {
return canDrop(dragSource, dropTarget, dropTargetId);
canDrop={(_, { dragSource, dropTargetId }) => {
return canDrop(dragSource, dropTargetId);
}}
canDrag={node => !isWorldZone(node?.data?.object)}
canDrag={node => !props.dragDisabled}
sort={false}
insertDroppableFirst={false}
dropTargetOffset={5}
Expand Down

0 comments on commit f956847

Please sign in to comment.