@rpg-engine/long-bow 0.5.89 → 0.5.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/long-bow.cjs.development.js +22 -14
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +22 -14
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Shortcuts/Shortcuts.tsx +16 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpg-engine/long-bow",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.91",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"@rollup/plugin-image": "^2.1.1",
|
|
86
|
-
"@rpg-engine/shared": "^0.9.
|
|
86
|
+
"@rpg-engine/shared": "^0.9.32",
|
|
87
87
|
"dayjs": "^1.11.2",
|
|
88
88
|
"font-awesome": "^4.7.0",
|
|
89
89
|
"fs-extra": "^10.1.0",
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
IShortcut,
|
|
7
7
|
ShortcutType,
|
|
8
8
|
} from '@rpg-engine/shared';
|
|
9
|
-
import React, { useEffect, useRef } from 'react';
|
|
9
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
10
10
|
import styled from 'styled-components';
|
|
11
11
|
import { uiColors } from '../../constants/uiColors';
|
|
12
12
|
import { countItemFromInventory } from '../../libs/itemCounter';
|
|
@@ -41,26 +41,36 @@ export const Shortcuts: React.FC<ShortcutsProps> = ({
|
|
|
41
41
|
onShortcutCast
|
|
42
42
|
);
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const handleKeyDown = useCallback(
|
|
45
|
+
(e: KeyboardEvent) => {
|
|
46
46
|
if (isBlockedCastingByKeyboard) return;
|
|
47
47
|
|
|
48
48
|
const shortcutIndex = Number(e.key) - 1;
|
|
49
49
|
if (shortcutIndex >= 0 && shortcutIndex <= 11) {
|
|
50
50
|
handleShortcutCast(shortcutIndex);
|
|
51
51
|
shortcutsRefs.current[shortcutIndex]?.classList.add('active');
|
|
52
|
-
setTimeout(() => {
|
|
52
|
+
const timeoutId = setTimeout(() => {
|
|
53
53
|
shortcutsRefs.current[shortcutIndex]?.classList.remove('active');
|
|
54
54
|
}, 150);
|
|
55
|
+
// Store timeoutId for later cleanup
|
|
56
|
+
timeoutIds.current.push((timeoutId as unknown) as number);
|
|
55
57
|
}
|
|
56
|
-
}
|
|
58
|
+
},
|
|
59
|
+
[isBlockedCastingByKeyboard, handleShortcutCast]
|
|
60
|
+
);
|
|
57
61
|
|
|
62
|
+
// Initialize a ref to store the timeout ids
|
|
63
|
+
const timeoutIds = useRef<number[]>([]);
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
58
66
|
window.addEventListener('keydown', handleKeyDown);
|
|
59
67
|
|
|
60
68
|
return () => {
|
|
61
69
|
window.removeEventListener('keydown', handleKeyDown);
|
|
70
|
+
// Clear all timeouts when the component unmounts
|
|
71
|
+
timeoutIds.current.forEach(id => clearTimeout(id));
|
|
62
72
|
};
|
|
63
|
-
}, [
|
|
73
|
+
}, [handleKeyDown]);
|
|
64
74
|
|
|
65
75
|
return (
|
|
66
76
|
<List>
|