Add keyboard shortcut for entering play mode and handle escape key in play mode
This commit is contained in:
@@ -1263,6 +1263,12 @@ export function App({ store, initialStatusMessage }: AppProps) {
|
||||
|
||||
const hasPrimaryModifier = (event.metaKey || event.ctrlKey) && !event.altKey;
|
||||
|
||||
if (hasPrimaryModifier && event.code === "KeyR" && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
handleEnterPlayMode();
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasPrimaryModifier && event.code === "KeyS" && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
handleSaveDraft();
|
||||
@@ -1375,6 +1381,37 @@ export function App({ store, initialStatusMessage }: AppProps) {
|
||||
};
|
||||
}, [activePanelId, addMenuPosition, brushList.length, editorState.selection, editorState.toolMode, entityList.length]);
|
||||
|
||||
useEffect(() => {
|
||||
if (editorState.toolMode !== "play") {
|
||||
return;
|
||||
}
|
||||
|
||||
const handleWindowKeyDown = (event: globalThis.KeyboardEvent) => {
|
||||
if (isTextEntryTarget(event.target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.key !== "Escape") {
|
||||
return;
|
||||
}
|
||||
|
||||
const pointerCaptured = activeNavigationMode === "firstPerson" && firstPersonTelemetry?.pointerLocked === true;
|
||||
|
||||
if (pointerCaptured) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
handleExitPlayMode();
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", handleWindowKeyDown);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("keydown", handleWindowKeyDown);
|
||||
};
|
||||
}, [activeNavigationMode, editorState.toolMode, firstPersonTelemetry]);
|
||||
|
||||
const applySceneName = () => {
|
||||
const normalizedName = sceneNameDraft.trim() || "Untitled Scene";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user