Skip to content

Commit

Permalink
Merge pull request #466 from nini22P/dev
Browse files Browse the repository at this point in the history
Move keyboard to useHotkey
  • Loading branch information
nini22P committed Feb 21, 2024
2 parents dc17fba + 8b17a9d commit 0b36de0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 5 additions & 1 deletion packages/webgal/src/UI/Title/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import useSoundEffect from '@/hooks/useSoundEffect';
import { WebGAL } from '@/Core/WebGAL';
import useApplyStyle from '@/hooks/useApplyStyle';
import { fullScreenOption } from '@/store/userDataInterface';
import { keyboard } from '@/hooks/useHotkey';

/**
* 标题页
Expand All @@ -41,7 +42,10 @@ const Title: FC = () => {
onClick={() => {
playBgm(GUIState.titleBgm);
dispatch(setVisibility({ component: 'isEnterGame', visibility: true }));
if (fullScreen === fullScreenOption.on) document.documentElement.requestFullscreen();
if (fullScreen === fullScreenOption.on) {
document.documentElement.requestFullscreen();
if (keyboard) keyboard.lock(['Escape', 'F11']);
}
}}
onMouseEnter={playSeEnter}
/>
Expand Down
7 changes: 1 addition & 6 deletions packages/webgal/src/hooks/useFullScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { fullScreenOption } from '@/store/userDataInterface';
import { setOptionData } from '@/store/userDataReducer';
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';

interface Keyboard {
lock: (keys: string[]) => Promise<void>;
unlock: () => Promise<void>;
}
import { keyboard } from './useHotkey';

export function useFullScreen() {
const userDataState = useSelector((state: RootState) => state.userData);
Expand All @@ -17,7 +13,6 @@ export function useFullScreen() {
const fullScreen = userDataState.optionData.fullScreen;
const isEnterGame = GUIState.isEnterGame;
let currentWindowHeight = window.innerHeight;
const keyboard: Keyboard | undefined = 'keyboard' in navigator && (navigator.keyboard as any); // FireFox and Safari not support

useEffect(() => {
switch (fullScreen) {
Expand Down
7 changes: 7 additions & 0 deletions packages/webgal/src/hooks/useHotkey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export interface HotKeyType {
AutoSave: {} | boolean;
}

export interface Keyboard {
lock: (keys: string[]) => Promise<void>;
unlock: () => Promise<void>;
}

export const keyboard: Keyboard | undefined = 'keyboard' in navigator && (navigator.keyboard as any); // FireFox and Safari not support

// export const fastSaveGameKey = `FastSaveKey`;
// export const isFastSaveKey = `FastSaveActive`;

Expand Down

0 comments on commit 0b36de0

Please sign in to comment.