UNPKG

lingo3d

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

157 lines 9.32 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "preact/jsx-runtime"; import MeshAppendable from "../../../display/core/MeshAppendable"; import downloadBlob from "../../../utils/downloadBlob"; import JointBase from "../../../display/core/JointBase"; import PhysicsObjectManager from "../../../display/core/PhysicsObjectManager"; import SpriteSheet from "../../../display/SpriteSheet"; import Timeline from "../../../display/Timeline"; import deleteSelected from "../../../engine/hotkeys/deleteSelected"; import { emitSelectionTarget } from "../../../events/onSelectionTarget"; import { getGameGraph, setGameGraph } from "../../../states/useGameGraph"; import { getMultipleSelectionTargets } from "../../../states/useMultipleSelectionTargets"; import { getSelectionFocus, setSelectionFocus } from "../../../states/useSelectionFocus"; import { removeSelectionFrozen, addSelectionFrozen, clearSelectionFrozen, getSelectionFrozen } from "../../../states/useSelectionFrozen"; import { getTimeline, setTimeline } from "../../../states/useTimeline"; import { getTimelineData } from "../../../states/useTimelineData"; import Connector from "../../../visualScripting/Connector"; import GameGraph from "../../../visualScripting/GameGraph"; import MenuButton from "../../component/MenuButton"; import useSyncState from "../../hooks/useSyncState"; import selectAllJointed from "./selectAllJointed"; import CreateJointItems from "./CreateJointItems"; import Template from "../../../display/Template"; import VisibleObjectManager from "../../../display/core/VisibleObjectManager"; import { librarySignal } from "../../Library/librarySignal"; import { selectTab } from "../../component/tabs/Tab"; import { sceneGraphContextMenuSignal } from "."; import Model from "../../../display/Model"; import { clearSelectionHideId, getSelectionHideId } from "../../../states/useSelectionHideId"; import groupSelected from "../../../engine/hotkeys/groupSelected"; import Script from "../../../display/Script"; import { getScript, setScript } from "../../../states/useScript"; const MenuItems = ({ selectionTarget }) => { const [selectionFrozen] = useSyncState(getSelectionFrozen); const [timelineData] = useSyncState(getTimelineData); const timeline = useSyncState(getTimeline); const gameGraph = useSyncState(getGameGraph); const script = useSyncState(getScript); const [multipleSelectionTargets] = useSyncState(getMultipleSelectionTargets); const selectionFocus = useSyncState(getSelectionFocus); const [selectionHideId] = useSyncState(getSelectionHideId); if (sceneGraphContextMenuSignal.value?.createJoint) return _jsx(CreateJointItems, {}); const children = []; if (multipleSelectionTargets.size) children.push(_jsxs(_Fragment, { children: [_jsx(MenuButton, { disabled: multipleSelectionTargets.size === 1, onClick: () => { sceneGraphContextMenuSignal.value = { x: sceneGraphContextMenuSignal.value?.x ?? 0, y: sceneGraphContextMenuSignal.value?.y ?? 0, createJoint: true }; }, children: "Create joint" }), _jsx(MenuButton, { disabled: multipleSelectionTargets.size === 1, onClick: groupSelected, children: "Group selected" })] })); else if (selectionTarget instanceof Script) children.push(_jsx(MenuButton, { disabled: selectionTarget === script, onClick: () => { setScript(selectionTarget); sceneGraphContextMenuSignal.value = undefined; }, children: selectionTarget === script ? "Already editing" : "Edit Script" })); else if (selectionTarget instanceof Timeline) children.push(_jsx(MenuButton, { disabled: selectionTarget === timeline, onClick: () => { setTimeline(selectionTarget); sceneGraphContextMenuSignal.value = undefined; }, children: selectionTarget === timeline ? "Already editing" : "Edit Timeline" })); else if (selectionTarget instanceof GameGraph) children.push(_jsx(MenuButton, { disabled: selectionTarget === gameGraph, onClick: () => { setGameGraph(selectionTarget); sceneGraphContextMenuSignal.value = undefined; }, children: selectionTarget === gameGraph ? "Already editing" : "Edit GameGraph" })); else if (selectionTarget instanceof Connector) { //todo: connector context menu } else if (selectionTarget) { if (selectionTarget instanceof SpriteSheet) children.push(_jsx(MenuButton, { onClick: () => { downloadBlob("spriteSheet.png", selectionTarget.toBlob()); sceneGraphContextMenuSignal.value = undefined; }, children: "Save image" })); else if (selectionTarget instanceof MeshAppendable) { if (selectionTarget instanceof Model) children.push(_jsx(MenuButton, { onClick: () => (sceneGraphContextMenuSignal.value = { x: sceneGraphContextMenuSignal.value?.x ?? 0, y: sceneGraphContextMenuSignal.value?.y ?? 0, search: true }), children: "Search children" })); if (selectionTarget instanceof VisibleObjectManager) { children.push(_jsx(MenuButton, { onClick: () => { setSelectionFocus(selectionFocus === selectionTarget ? undefined : selectionTarget); emitSelectionTarget(undefined); sceneGraphContextMenuSignal.value = undefined; }, children: selectionFocus === selectionTarget ? "Unfocus children" : "Focus children" }), _jsx(MenuButton, { onClick: () => { const template = new Template(); template.source = selectionTarget; selectTab(librarySignal, "templates"); sceneGraphContextMenuSignal.value = undefined; }, children: "Convert to template" })); if (selectionTarget instanceof PhysicsObjectManager) children.push(_jsx(MenuButton, { onClick: () => { selectAllJointed(selectionTarget instanceof JointBase ? selectionTarget.$fromManager ?? selectionTarget.$toManager : selectionTarget instanceof PhysicsObjectManager ? selectionTarget : undefined); sceneGraphContextMenuSignal.value = undefined; }, children: "Select all jointed" })); } children.push(_jsx(MenuButton, { onClick: () => { selectionFrozen.has(selectionTarget) ? removeSelectionFrozen(selectionTarget) : addSelectionFrozen(selectionTarget); sceneGraphContextMenuSignal.value = undefined; }, children: selectionFrozen.has(selectionTarget) ? "Unfreeze selection" : "Freeze selection" })); } children.push(_jsx(MenuButton, { disabled: !timelineData || selectionTarget.uuid in timelineData, onClick: () => { timeline?.mergeData({ [selectionTarget.uuid]: {} }); sceneGraphContextMenuSignal.value = undefined; }, children: timelineData && selectionTarget.uuid in timelineData ? "Already in Timeline" : "Add to Timeline" })); } children.push(_jsx(MenuButton, { onClick: () => (sceneGraphContextMenuSignal.value = { x: sceneGraphContextMenuSignal.value?.x ?? 0, y: sceneGraphContextMenuSignal.value?.y ?? 0, hideId: true }), children: "Hide objects by id" })); if (!selectionTarget) children.push(_jsx(MenuButton, { disabled: !selectionFrozen.size, onClick: () => { clearSelectionFrozen(); sceneGraphContextMenuSignal.value = undefined; }, children: "Unfreeze all" }), _jsx(MenuButton, { disabled: !selectionFocus, onClick: () => { setSelectionFocus(undefined); emitSelectionTarget(undefined); sceneGraphContextMenuSignal.value = undefined; }, children: "Unfocus all" }), _jsx(MenuButton, { disabled: !selectionHideId.size, onClick: () => { clearSelectionHideId(); sceneGraphContextMenuSignal.value = undefined; }, children: "Unhide all" })); else children.push(_jsx(MenuButton, { disabled: !selectionTarget, onClick: () => { deleteSelected(); sceneGraphContextMenuSignal.value = undefined; }, children: "Delete selected" })); return _jsx(_Fragment, { children: children }); }; export default MenuItems; //# sourceMappingURL=MenuItems.js.map