@rpg-engine/long-bow 0.8.87 → 0.8.89

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.8.87",
3
+ "version": "0.8.89",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -84,7 +84,7 @@
84
84
  "dependencies": {
85
85
  "@capacitor/core": "^6.1.0",
86
86
  "@rollup/plugin-image": "^2.1.1",
87
- "@rpg-engine/shared": "^0.10.35",
87
+ "@rpg-engine/shared": "^0.10.38",
88
88
  "dayjs": "^1.11.2",
89
89
  "font-awesome": "^4.7.0",
90
90
  "fs-extra": "^10.1.0",
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useRef } from 'react';
1
+ import React, { useCallback, useEffect, useRef } from 'react';
2
2
  import Draggable from 'react-draggable';
3
3
  import styled, { css } from 'styled-components';
4
4
  import { uiFonts } from '../constants/uiFonts';
@@ -62,21 +62,23 @@ export const DraggableContainer: React.FC<IDraggableContainerProps> = ({
62
62
 
63
63
  useOutsideClick(draggableRef, 'item-container');
64
64
 
65
- useEffect(() => {
66
- document.addEventListener('clickOutside', event => {
65
+ const handleClickOutside = useCallback(
66
+ (event: Event) => {
67
67
  const e = event as CustomEvent;
68
-
69
68
  if (e.detail.id === 'item-container') {
70
- if (onOutsideClick) {
71
- onOutsideClick();
72
- }
69
+ onOutsideClick?.();
73
70
  }
74
- });
71
+ },
72
+ [onOutsideClick]
73
+ );
74
+
75
+ useEffect(() => {
76
+ document.addEventListener('clickOutside', handleClickOutside);
75
77
 
76
78
  return () => {
77
- document.removeEventListener('clickOutside', _e => {});
79
+ document.removeEventListener('clickOutside', handleClickOutside);
78
80
  };
79
- }, []);
81
+ }, [handleClickOutside]);
80
82
 
81
83
  return (
82
84
  <Draggable
@@ -23,9 +23,6 @@ export const ProgressBar: React.FC<IBarProps> = ({
23
23
  style,
24
24
  mobileScale,
25
25
  }) => {
26
- value = Math.round(value);
27
- max = Math.round(max);
28
-
29
26
  const calculatePercentageValue = function(max: number, value: number) {
30
27
  if (value > max) {
31
28
  value = max;
@@ -34,6 +31,10 @@ export const ProgressBar: React.FC<IBarProps> = ({
34
31
  return Math.min(99.99, percentage);
35
32
  };
36
33
 
34
+ // Round only for display, not for calculation
35
+ const displayValue = Math.round(value);
36
+ const displayMax = Math.round(max);
37
+
37
38
  return (
38
39
  <Container
39
40
  className="rpgui-progress"
@@ -47,7 +48,7 @@ export const ProgressBar: React.FC<IBarProps> = ({
47
48
  {displayText && (
48
49
  <TextOverlay>
49
50
  <ProgressBarText>
50
- {value}/{max}
51
+ {displayValue}/{displayMax}
51
52
  </ProgressBarText>
52
53
  </TextOverlay>
53
54
  )}
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useRef } from 'react';
1
+ import React, { useCallback, useEffect, useRef } from 'react';
2
2
  import styled from 'styled-components';
3
3
  import { useOutsideClick } from '../hooks/useOutsideAlerter';
4
4
  import ModalPortal from './Abstractions/ModalPortal';
@@ -27,21 +27,23 @@ export const RelativeListMenu: React.FC<IRelativeMenuProps> = ({
27
27
 
28
28
  useOutsideClick(ref, 'relative-context-menu');
29
29
 
30
- useEffect(() => {
31
- document.addEventListener('clickOutside', event => {
30
+ const handleClickOutside = useCallback(
31
+ (event: Event) => {
32
32
  const e = event as CustomEvent;
33
-
34
33
  if (e.detail.id === 'relative-context-menu') {
35
- if (onOutsideClick) {
36
- onOutsideClick();
37
- }
34
+ onOutsideClick?.();
38
35
  }
39
- });
36
+ },
37
+ [onOutsideClick]
38
+ );
39
+
40
+ useEffect(() => {
41
+ document.addEventListener('clickOutside', handleClickOutside);
40
42
 
41
43
  return () => {
42
- document.removeEventListener('clickOutside', _e => {});
44
+ document.removeEventListener('clickOutside', handleClickOutside);
43
45
  };
44
- }, []);
46
+ }, [handleClickOutside]);
45
47
 
46
48
  return (
47
49
  <ModalPortal>
@@ -41,6 +41,9 @@ export const Shortcuts: React.FC<ShortcutsProps> = ({
41
41
  onShortcutCast
42
42
  );
43
43
 
44
+ // Use a Set to track active timeouts - automatically cleaned when they complete
45
+ const activeTimeouts = useRef<Set<ReturnType<typeof setTimeout>>>(new Set());
46
+
44
47
  const handleKeyDown = useCallback(
45
48
  (e: KeyboardEvent) => {
46
49
  if (isBlockedCastingByKeyboard) return;
@@ -51,24 +54,22 @@ export const Shortcuts: React.FC<ShortcutsProps> = ({
51
54
  shortcutsRefs.current[shortcutIndex]?.classList.add('active');
52
55
  const timeoutId = setTimeout(() => {
53
56
  shortcutsRefs.current[shortcutIndex]?.classList.remove('active');
57
+ activeTimeouts.current.delete(timeoutId);
54
58
  }, 150);
55
- // Store timeoutId for later cleanup
56
- timeoutIds.current.push((timeoutId as unknown) as number);
59
+ activeTimeouts.current.add(timeoutId);
57
60
  }
58
61
  },
59
62
  [isBlockedCastingByKeyboard, handleShortcutCast]
60
63
  );
61
64
 
62
- // Initialize a ref to store the timeout ids
63
- const timeoutIds = useRef<number[]>([]);
64
-
65
65
  useEffect(() => {
66
66
  window.addEventListener('keydown', handleKeyDown);
67
67
 
68
68
  return () => {
69
69
  window.removeEventListener('keydown', handleKeyDown);
70
- // Clear all timeouts when the component unmounts
71
- timeoutIds.current.forEach(id => clearTimeout(id));
70
+ // Clear all active timeouts when the component unmounts
71
+ activeTimeouts.current.forEach(id => clearTimeout(id));
72
+ activeTimeouts.current.clear();
72
73
  };
73
74
  }, [handleKeyDown]);
74
75
 
@@ -1,25 +1,46 @@
1
- import { useEffect, useRef, useState } from 'react';
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
2
 
3
3
  export const useShortcutCooldown = (
4
4
  onShortcutCast: (index: number) => void
5
5
  ) => {
6
6
  const [shortcutCooldown, setShortcutCooldown] = useState(0);
7
- const cooldownTimeout = useRef<NodeJS.Timeout | null>(null);
7
+ const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
8
8
 
9
- const handleShortcutCast = (index: number) => {
10
- if (shortcutCooldown <= 0) setShortcutCooldown(1.5);
11
- onShortcutCast(index);
12
- };
9
+ const clearCooldownInterval = useCallback(() => {
10
+ if (intervalRef.current) {
11
+ clearInterval(intervalRef.current);
12
+ intervalRef.current = null;
13
+ }
14
+ }, []);
13
15
 
14
- useEffect(() => {
15
- if (cooldownTimeout.current) clearTimeout(cooldownTimeout.current);
16
+ const handleShortcutCast = useCallback(
17
+ (index: number) => {
18
+ if (shortcutCooldown <= 0) {
19
+ setShortcutCooldown(1.5);
20
+ }
21
+ onShortcutCast(index);
22
+ },
23
+ [shortcutCooldown, onShortcutCast]
24
+ );
16
25
 
17
- if (shortcutCooldown > 0) {
18
- cooldownTimeout.current = setTimeout(() => {
19
- setShortcutCooldown(shortcutCooldown - 0.1);
26
+ useEffect(() => {
27
+ if (shortcutCooldown > 0 && !intervalRef.current) {
28
+ intervalRef.current = setInterval(() => {
29
+ setShortcutCooldown(prev => {
30
+ const next = prev - 0.1;
31
+ if (next <= 0) {
32
+ clearCooldownInterval();
33
+ return 0;
34
+ }
35
+ return next;
36
+ });
20
37
  }, 100);
21
38
  }
22
- }, [shortcutCooldown]);
39
+
40
+ return () => {
41
+ clearCooldownInterval();
42
+ };
43
+ }, [shortcutCooldown > 0, clearCooldownInterval]);
23
44
 
24
45
  return { shortcutCooldown, handleShortcutCast };
25
46
  };