#244 add use pointer lock#254
Merged
debabin merged 3 commits intosiberiacancode:mainfrom Nov 12, 2024
Merged
Conversation
debabin
requested changes
Nov 10, 2024
Comment on lines
+45
to
+68
| useEventListener(document, 'pointerlockchange', () => { | ||
| if (!isSupported) return; | ||
|
|
||
| const currentElement = document!.pointerLockElement ?? element; | ||
|
|
||
| if (targetElement && currentElement === targetElement.current) { | ||
| setElement(document.pointerLockElement as MaybeHTMLElement); | ||
| if (!element) { | ||
| targetElement.current = triggerElement.current = null; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| useEventListener(document, 'pointerlockerror', () => { | ||
| if (!isSupported) return; | ||
|
|
||
| const currentElement = document!.pointerLockElement ?? element; | ||
|
|
||
| if (currentElement === (target?.current || triggerElement.current)) { | ||
| const action = document!.pointerLockElement ? 'release' : 'acquire'; | ||
|
|
||
| throw new Error(`Failed to ${action} pointer lock.`); | ||
| } | ||
| }); |
Member
There was a problem hiding this comment.
в хуке лучше не использовать другие хуки особенно. лучше сделать обычный useEffect
Member
There was a problem hiding this comment.
- не бери прям все из vueuse, смотри на другие хуки из нашей либы
Member
There was a problem hiding this comment.
- данную логику все можно легко описать в одном useEffect
Comment on lines
+9
to
+11
| interface UsePointerLockOptions { | ||
| document?: Document; | ||
| } |
| } | ||
|
|
||
| interface UsePointerLockReturn { | ||
| isSupported: boolean; |
Comment on lines
+15
to
+16
| triggerElement: MutableRefObject<MaybeHTMLElement>; | ||
| element: MaybeHTMLElement; |
Member
There was a problem hiding this comment.
MaybeHTMLElement это опять же своровано из vueuse, не надо тащить все оттуда
Comment on lines
+42
to
+43
| const triggerElement = useRef<MaybeHTMLElement>(); | ||
| const targetElement = useRef<MaybeHTMLElement>(); |
Member
There was a problem hiding this comment.
это пока тоже удаляем, я думаю самое важно просто lock и unlock на сегодня
| }); | ||
|
|
||
| const lock = (event: MouseEvent<HTMLDivElement> | Event) => { | ||
| if (!isSupported) throw new Error('Pointer Lock API is not supported by your browser.'); |
…ерез useEffect, убрал лишние targetElement & triggerElement, поменял типы
debabin
requested changes
Nov 10, 2024
| setElement(document.pointerLockElement as Element); | ||
| } | ||
| }; | ||
| const handlePointerLockError = () => { |
Member
There was a problem hiding this comment.
хендлер нужно делать внутри useEffect, а то removeEventListener работать не будет, нужна таже ссылка
|
|
||
| /** | ||
| * @name usePointerLock | ||
| * @description - Reactive pointer lock |
Member
There was a problem hiding this comment.
Посмотри, как другие оформляются desc
| * @description - Reactive pointer lock | ||
| * @category Sensors | ||
| * | ||
| * @param {RefObject<Element>} target |
| const lock = (event: MouseEvent<Element> | Event) => { | ||
| if (!supported) return; | ||
|
|
||
| const targetElement = event instanceof Event ? target?.current : event.currentTarget; |
debabin
approved these changes
Nov 11, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.