@rpg-engine/long-bow 0.3.82 → 0.3.83

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.
Files changed (155) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +181 -181
  3. package/dist/components/Abstractions/SlotsContainer.d.ts +2 -0
  4. package/dist/components/DraggableContainer.d.ts +2 -0
  5. package/dist/components/Equipment/EquipmentSet.d.ts +2 -0
  6. package/dist/components/Item/Inventory/ItemContainer.d.ts +3 -0
  7. package/dist/components/Item/Inventory/ItemSlot.d.ts +1 -0
  8. package/dist/components/Item/Inventory/itemContainerHelper.d.ts +1 -1
  9. package/dist/components/RelativeListMenu.d.ts +4 -0
  10. package/dist/long-bow.cjs.development.js +944 -858
  11. package/dist/long-bow.cjs.development.js.map +1 -1
  12. package/dist/long-bow.cjs.production.min.js +1 -1
  13. package/dist/long-bow.cjs.production.min.js.map +1 -1
  14. package/dist/long-bow.esm.js +830 -744
  15. package/dist/long-bow.esm.js.map +1 -1
  16. package/package.json +100 -100
  17. package/src/components/Abstractions/ModalPortal.tsx +22 -22
  18. package/src/components/Abstractions/SlotsContainer.tsx +62 -48
  19. package/src/components/Arrow/SelectArrow.tsx +69 -69
  20. package/src/components/Arrow/img/arrow01-left-clicked.png +0 -0
  21. package/src/components/Arrow/img/arrow01-left.png +0 -0
  22. package/src/components/Arrow/img/arrow01-right-clicked.png +0 -0
  23. package/src/components/Arrow/img/arrow01-right.png +0 -0
  24. package/src/components/Arrow/img/arrow02-left-clicked.png +0 -0
  25. package/src/components/Arrow/img/arrow02-left.png +0 -0
  26. package/src/components/Arrow/img/arrow02-right-clicked.png +0 -0
  27. package/src/components/Arrow/img/arrow02-right.png +0 -0
  28. package/src/components/Button.tsx +40 -40
  29. package/src/components/Character/CharacterSelection.tsx +96 -96
  30. package/src/components/CharacterStatus/CharacterStatus.tsx +120 -120
  31. package/src/components/Chat/Chat.tsx +196 -196
  32. package/src/components/Chatdeprecated/ChatDeprecated.tsx +198 -198
  33. package/src/components/CheckButton.tsx +65 -65
  34. package/src/components/CircularController/CircularController.tsx +248 -248
  35. package/src/components/CraftBook/CraftBook.tsx +241 -241
  36. package/src/components/CraftBook/MockItems.ts +77 -77
  37. package/src/components/DraggableContainer.tsx +176 -156
  38. package/src/components/Dropdown.tsx +90 -90
  39. package/src/components/DropdownSelectorContainer.tsx +42 -42
  40. package/src/components/Equipment/EquipmentSet.tsx +199 -191
  41. package/src/components/HistoryDialog.tsx +104 -104
  42. package/src/components/Input.tsx +15 -15
  43. package/src/components/Item/Cards/ItemInfo.tsx +252 -252
  44. package/src/components/Item/Cards/ItemInfoDisplay.tsx +128 -128
  45. package/src/components/Item/Cards/ItemInfoWrapper.tsx +62 -62
  46. package/src/components/Item/Cards/ItemTooltip.tsx +83 -83
  47. package/src/components/Item/Cards/MobileItemTooltip.tsx +149 -149
  48. package/src/components/Item/Inventory/ErrorBoundary.tsx +42 -42
  49. package/src/components/Item/Inventory/ItemContainer.tsx +227 -218
  50. package/src/components/Item/Inventory/ItemContainerTypes.ts +6 -6
  51. package/src/components/Item/Inventory/ItemQuantitySelector.tsx +138 -138
  52. package/src/components/Item/Inventory/ItemSlot.tsx +564 -546
  53. package/src/components/Item/Inventory/itemContainerHelper.ts +172 -156
  54. package/src/components/ListMenu.tsx +63 -63
  55. package/src/components/Multitab/Tab.tsx +66 -66
  56. package/src/components/Multitab/TabBody.tsx +13 -13
  57. package/src/components/Multitab/TabsContainer.tsx +97 -97
  58. package/src/components/NPCDialog/NPCDialog.tsx +121 -121
  59. package/src/components/NPCDialog/NPCDialogText.tsx +113 -113
  60. package/src/components/NPCDialog/NPCMultiDialog.tsx +159 -159
  61. package/src/components/NPCDialog/QuestionDialog/QuestionDialog.tsx +237 -237
  62. package/src/components/ProgressBar.tsx +92 -92
  63. package/src/components/PropertySelect/PropertySelect.tsx +106 -106
  64. package/src/components/QuestInfo/QuestInfo.tsx +233 -233
  65. package/src/components/QuestList.tsx +135 -135
  66. package/src/components/RPGUIContainer.tsx +47 -47
  67. package/src/components/RPGUIForceRenderStart.tsx +45 -45
  68. package/src/components/RPGUIRoot.tsx +14 -14
  69. package/src/components/RadioButton.tsx +53 -53
  70. package/src/components/RadioInput/RadioButton.tsx +96 -96
  71. package/src/components/RadioInput/RadioInput.tsx +102 -102
  72. package/src/components/RadioInput/instruments.ts +15 -15
  73. package/src/components/RangeSlider.tsx +78 -78
  74. package/src/components/RelativeListMenu.tsx +90 -83
  75. package/src/components/ScrollList.tsx +79 -79
  76. package/src/components/Shortcuts/Shortcuts.tsx +151 -151
  77. package/src/components/Shortcuts/ShortcutsSetter.tsx +132 -132
  78. package/src/components/Shortcuts/SingleShortcut.ts +62 -62
  79. package/src/components/SimpleProgressBar.tsx +62 -62
  80. package/src/components/SkillProgressBar.tsx +133 -133
  81. package/src/components/SkillsContainer.tsx +206 -206
  82. package/src/components/Spellbook/Spell.tsx +201 -201
  83. package/src/components/Spellbook/Spellbook.tsx +153 -153
  84. package/src/components/Spellbook/constants.ts +8 -8
  85. package/src/components/Spellbook/mockSpells.ts +60 -60
  86. package/src/components/StaticBook/StaticBook.tsx +103 -103
  87. package/src/components/TextArea.tsx +11 -11
  88. package/src/components/TimeWidget/DayNightPeriod/DayNightPeriod.tsx +35 -35
  89. package/src/components/TimeWidget/TimeWidget.tsx +65 -65
  90. package/src/components/TradingMenu/TradingItemRow.tsx +198 -198
  91. package/src/components/TradingMenu/TradingMenu.tsx +216 -216
  92. package/src/components/TradingMenu/items.mock.ts +48 -48
  93. package/src/components/Truncate.tsx +25 -25
  94. package/src/components/itemSelector/ItemSelector.tsx +136 -136
  95. package/src/components/shared/Column.tsx +16 -16
  96. package/src/components/shared/Ellipsis.tsx +65 -65
  97. package/src/components/shared/SpriteFromAtlas.tsx +104 -104
  98. package/src/components/typography/DynamicText.tsx +49 -49
  99. package/src/constants/uiColors.ts +20 -20
  100. package/src/constants/uiDevices.ts +3 -3
  101. package/src/constants/uiFonts.ts +12 -12
  102. package/src/hooks/useEventListener.ts +21 -21
  103. package/src/hooks/useOutsideAlerter.ts +25 -25
  104. package/src/index.tsx +40 -40
  105. package/src/libs/StringHelpers.ts +3 -3
  106. package/src/mocks/atlas/entities/entities.json +20215 -20215
  107. package/src/mocks/atlas/icons/icons.json +735 -735
  108. package/src/mocks/atlas/items/items.json +12086 -12086
  109. package/src/mocks/equipmentSet.mocks.ts +391 -391
  110. package/src/mocks/itemContainer.mocks.ts +563 -563
  111. package/src/mocks/skills.mocks.ts +128 -128
  112. package/src/stories/Arrow.stories.tsx +26 -26
  113. package/src/stories/Button.stories.tsx +36 -36
  114. package/src/stories/CharacterSelection.stories.tsx +45 -45
  115. package/src/stories/CharacterStatus.stories.tsx +29 -29
  116. package/src/stories/Chat.stories.tsx +187 -187
  117. package/src/stories/ChatDeprecated.stories.tsx +170 -170
  118. package/src/stories/CheckButton.stories.tsx +48 -48
  119. package/src/stories/CircullarController.stories.tsx +37 -37
  120. package/src/stories/CraftBook.stories.tsx +42 -42
  121. package/src/stories/DayNightPeriod.stories.tsx +27 -27
  122. package/src/stories/DraggableContainer.stories.tsx +28 -28
  123. package/src/stories/Dropdown.stories.tsx +46 -46
  124. package/src/stories/DropdownSelectorContainer.stories.tsx +41 -41
  125. package/src/stories/EquipmentSet.stories.tsx +65 -65
  126. package/src/stories/HistoryDialog.stories.tsx +61 -61
  127. package/src/stories/ItemContainer.stories.tsx +201 -200
  128. package/src/stories/ItemInfoDisplay.stories.tsx +33 -33
  129. package/src/stories/ItemQuantitySelector.stories.tsx +26 -26
  130. package/src/stories/ItemSelector.stories.tsx +77 -77
  131. package/src/stories/ItemTradingComponent.stories.tsx +35 -35
  132. package/src/stories/ListMenu.stories.tsx +56 -56
  133. package/src/stories/Multitab.stories.tsx +51 -51
  134. package/src/stories/NPCDialog.stories.tsx +130 -130
  135. package/src/stories/NPCMultiDialog.stories.tsx +71 -71
  136. package/src/stories/ProgressBar.stories.tsx +23 -23
  137. package/src/stories/PropertySelect.stories.tsx +40 -40
  138. package/src/stories/QuestInfo.stories.tsx +107 -107
  139. package/src/stories/QuestList.stories.tsx +82 -82
  140. package/src/stories/RPGUIContainers.stories.tsx +42 -42
  141. package/src/stories/RadioButton.stories.tsx +49 -49
  142. package/src/stories/RadioInput.stories.tsx +34 -34
  143. package/src/stories/RangeSlider.stories.tsx +64 -64
  144. package/src/stories/ScrollList.stories.tsx +85 -85
  145. package/src/stories/Shortcuts.stories.tsx +39 -39
  146. package/src/stories/SimpleProgressBar.stories.tsx +22 -22
  147. package/src/stories/SkillProgressBar.stories.tsx +34 -34
  148. package/src/stories/SkillsContainer.stories.tsx +35 -35
  149. package/src/stories/Spellbook.stories.tsx +104 -104
  150. package/src/stories/StaticBook.stories.tsx +32 -32
  151. package/src/stories/Text.stories.tsx +42 -42
  152. package/src/stories/TimeWidget.stories.tsx +27 -27
  153. package/src/stories/TradingMenu.stories.tsx +47 -47
  154. package/src/types/eventTypes.ts +4 -4
  155. package/src/types/index.d.ts +2 -2
@@ -1,83 +1,90 @@
1
- import React, { useEffect, useRef } from 'react';
2
- import styled from 'styled-components';
3
- import { useOutsideClick } from '../hooks/useOutsideAlerter';
4
-
5
- interface IListMenuOption {
6
- id: string;
7
- text: string;
8
- }
9
-
10
- export interface IRelativeMenuProps {
11
- options: IListMenuOption[];
12
- onSelected: (selectedOptionId: string) => void;
13
- fontSize?: number;
14
- onOutsideClick?: () => void;
15
- }
16
-
17
- export const RelativeListMenu: React.FC<IRelativeMenuProps> = ({
18
- options,
19
- onSelected,
20
- onOutsideClick,
21
- fontSize = 0.8,
22
- }) => {
23
- const ref = useRef(null);
24
-
25
- useOutsideClick(ref, 'relative-context-menu');
26
-
27
- useEffect(() => {
28
- document.addEventListener('clickOutside', event => {
29
- const e = event as CustomEvent;
30
-
31
- if (e.detail.id === 'relative-context-menu') {
32
- if (onOutsideClick) {
33
- onOutsideClick();
34
- }
35
- }
36
- });
37
-
38
- return () => {
39
- document.removeEventListener('clickOutside', _e => {});
40
- };
41
- }, []);
42
-
43
- return (
44
- <Container fontSize={fontSize} ref={ref}>
45
- <ul className="rpgui-list-imp" style={{ overflow: 'hidden' }}>
46
- {options.map((params, index) => (
47
- <ListElement
48
- key={params?.id || index}
49
- onPointerDown={() => {
50
- onSelected(params?.id);
51
- }}
52
- >
53
- {params?.text || 'No text'}
54
- </ListElement>
55
- ))}
56
- </ul>
57
- </Container>
58
- );
59
- };
60
-
61
- interface IContainerProps {
62
- fontSize?: number;
63
- }
64
-
65
- const Container = styled.div<IContainerProps>`
66
- position: absolute;
67
- top: 1rem;
68
- left: 4rem;
69
-
70
- display: flex;
71
- flex-direction: column;
72
- width: max-content;
73
- justify-content: start;
74
- align-items: flex-start;
75
-
76
- li {
77
- font-size: ${props => props.fontSize}em;
78
- }
79
- `;
80
-
81
- const ListElement = styled.li`
82
- margin-right: 0.5rem;
83
- `;
1
+ import React, { useEffect, useRef } from 'react';
2
+ import styled from 'styled-components';
3
+ import { useOutsideClick } from '../hooks/useOutsideAlerter';
4
+ import ModalPortal from './Abstractions/ModalPortal';
5
+
6
+ interface IListMenuOption {
7
+ id: string;
8
+ text: string;
9
+ }
10
+
11
+ export interface IRelativeMenuProps {
12
+ options: IListMenuOption[];
13
+ onSelected: (selectedOptionId: string) => void;
14
+ fontSize?: number;
15
+ onOutsideClick?: () => void;
16
+ pos: { x: number; y: number };
17
+ }
18
+
19
+ export const RelativeListMenu: React.FC<IRelativeMenuProps> = ({
20
+ options,
21
+ onSelected,
22
+ onOutsideClick,
23
+ fontSize = 0.8,
24
+ pos,
25
+ }) => {
26
+ const ref = useRef(null);
27
+
28
+ useOutsideClick(ref, 'relative-context-menu');
29
+
30
+ useEffect(() => {
31
+ document.addEventListener('clickOutside', event => {
32
+ const e = event as CustomEvent;
33
+
34
+ if (e.detail.id === 'relative-context-menu') {
35
+ if (onOutsideClick) {
36
+ onOutsideClick();
37
+ }
38
+ }
39
+ });
40
+
41
+ return () => {
42
+ document.removeEventListener('clickOutside', _e => {});
43
+ };
44
+ }, []);
45
+
46
+ return (
47
+ <ModalPortal>
48
+ <Container fontSize={fontSize} ref={ref} {...pos}>
49
+ <ul className="rpgui-list-imp" style={{ overflow: 'hidden' }}>
50
+ {options.map((params, index) => (
51
+ <ListElement
52
+ key={params?.id || index}
53
+ onPointerDown={() => {
54
+ onSelected(params?.id);
55
+ }}
56
+ >
57
+ {params?.text || 'No text'}
58
+ </ListElement>
59
+ ))}
60
+ </ul>
61
+ </Container>
62
+ </ModalPortal>
63
+ );
64
+ };
65
+
66
+ interface IContainerProps {
67
+ fontSize?: number;
68
+ x: number;
69
+ y: number;
70
+ }
71
+
72
+ const Container = styled.div<IContainerProps>`
73
+ position: absolute;
74
+ top: ${props => props.y}px;
75
+ left: ${props => props.x}px;
76
+
77
+ display: flex;
78
+ flex-direction: column;
79
+ width: max-content;
80
+ justify-content: start;
81
+ align-items: flex-start;
82
+
83
+ li {
84
+ font-size: ${props => props.fontSize}em;
85
+ }
86
+ `;
87
+
88
+ const ListElement = styled.li`
89
+ margin-right: 0.5rem;
90
+ `;
@@ -1,79 +1,79 @@
1
- import React from 'react';
2
- import styled from 'styled-components';
3
- import { v4 as uuidv4 } from 'uuid';
4
- import { uiFonts } from '../constants/uiFonts';
5
- import { DraggableContainer } from './DraggableContainer';
6
-
7
- interface IListMenuOption {
8
- id: string;
9
- text: string;
10
- }
11
-
12
- export interface IListMenuProps {
13
- x: number;
14
- y: number;
15
- options: IListMenuOption[];
16
- onSelected: (selectedOptionId: string) => void;
17
- fontSize?: number;
18
- title: string;
19
- }
20
-
21
- export const ListMenu: React.FC<IListMenuProps> = ({
22
- options,
23
- onSelected,
24
- title,
25
- }) => {
26
- return (
27
- <ScrollListContainer title={title}>
28
- <SkillSplitDiv>
29
- <hr className="golden" />
30
- </SkillSplitDiv>
31
-
32
- <ListContainer className="rpgui-list-imp">
33
- {options.map(params => (
34
- <ListElement
35
- key={uuidv4()}
36
- onPointerDown={() => {
37
- onSelected(params?.id);
38
- }}
39
- >
40
- {params?.text || 'No text'}
41
- </ListElement>
42
- ))}
43
- </ListContainer>
44
- </ScrollListContainer>
45
- );
46
- };
47
-
48
- const ScrollListContainer = styled(DraggableContainer)`
49
- border: 1px solid black;
50
- width: 400px;
51
- height: 400px;
52
- .DraggableContainer__TitleContainer-sc-184mpyl-2 {
53
- width: auto;
54
- height: auto;
55
- }
56
- `;
57
-
58
- const SkillSplitDiv = styled.div`
59
- width: 100%;
60
- margin-bottom: 10px;
61
- hr {
62
- margin: 0px;
63
- padding: 0px;
64
- }
65
- p {
66
- margin-bottom: 0px;
67
- }
68
- `;
69
-
70
- const ListContainer = styled.ul`
71
- border: none;
72
- width: 400px;
73
- height: 250px;
74
- overflow-y: scroll;
75
- `;
76
- const ListElement = styled.li`
77
- margin-right: 0.5rem;
78
- font-size: ${uiFonts.size.small};
79
- `;
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { v4 as uuidv4 } from 'uuid';
4
+ import { uiFonts } from '../constants/uiFonts';
5
+ import { DraggableContainer } from './DraggableContainer';
6
+
7
+ interface IListMenuOption {
8
+ id: string;
9
+ text: string;
10
+ }
11
+
12
+ export interface IListMenuProps {
13
+ x: number;
14
+ y: number;
15
+ options: IListMenuOption[];
16
+ onSelected: (selectedOptionId: string) => void;
17
+ fontSize?: number;
18
+ title: string;
19
+ }
20
+
21
+ export const ListMenu: React.FC<IListMenuProps> = ({
22
+ options,
23
+ onSelected,
24
+ title,
25
+ }) => {
26
+ return (
27
+ <ScrollListContainer title={title}>
28
+ <SkillSplitDiv>
29
+ <hr className="golden" />
30
+ </SkillSplitDiv>
31
+
32
+ <ListContainer className="rpgui-list-imp">
33
+ {options.map(params => (
34
+ <ListElement
35
+ key={uuidv4()}
36
+ onPointerDown={() => {
37
+ onSelected(params?.id);
38
+ }}
39
+ >
40
+ {params?.text || 'No text'}
41
+ </ListElement>
42
+ ))}
43
+ </ListContainer>
44
+ </ScrollListContainer>
45
+ );
46
+ };
47
+
48
+ const ScrollListContainer = styled(DraggableContainer)`
49
+ border: 1px solid black;
50
+ width: 400px;
51
+ height: 400px;
52
+ .DraggableContainer__TitleContainer-sc-184mpyl-2 {
53
+ width: auto;
54
+ height: auto;
55
+ }
56
+ `;
57
+
58
+ const SkillSplitDiv = styled.div`
59
+ width: 100%;
60
+ margin-bottom: 10px;
61
+ hr {
62
+ margin: 0px;
63
+ padding: 0px;
64
+ }
65
+ p {
66
+ margin-bottom: 0px;
67
+ }
68
+ `;
69
+
70
+ const ListContainer = styled.ul`
71
+ border: none;
72
+ width: 400px;
73
+ height: 250px;
74
+ overflow-y: scroll;
75
+ `;
76
+ const ListElement = styled.li`
77
+ margin-right: 0.5rem;
78
+ font-size: ${uiFonts.size.small};
79
+ `;
@@ -1,151 +1,151 @@
1
- import {
2
- getItemTextureKeyPath,
3
- IItem,
4
- IItemContainer,
5
- IRawSpell,
6
- IShortcut,
7
- ShortcutType,
8
- } from '@rpg-engine/shared';
9
- import React, { useEffect, useRef } from 'react';
10
- import styled from 'styled-components';
11
- import { uiColors } from '../../constants/uiColors';
12
- import { SpriteFromAtlas } from '../shared/SpriteFromAtlas';
13
- import { SingleShortcut } from './SingleShortcut';
14
-
15
- export type ShortcutsProps = {
16
- shortcuts: IShortcut[];
17
- onShortcutCast: (index: number) => void;
18
- mana: number;
19
- isBlockedCastingByKeyboard?: boolean;
20
- inventory?: IItemContainer | null;
21
- atlasJSON: any;
22
- atlasIMG: any;
23
- };
24
-
25
- export const Shortcuts: React.FC<ShortcutsProps> = ({
26
- shortcuts,
27
- onShortcutCast,
28
- mana,
29
- isBlockedCastingByKeyboard = false,
30
- atlasJSON,
31
- atlasIMG,
32
- inventory,
33
- }) => {
34
- const shortcutsRefs = useRef<HTMLButtonElement[]>([]);
35
-
36
- useEffect(() => {
37
- const handleKeyDown = (e: KeyboardEvent) => {
38
- if (isBlockedCastingByKeyboard) return;
39
-
40
- const shortcutIndex = Number(e.key) - 1;
41
- if (shortcutIndex >= 0 && shortcutIndex <= 5) {
42
- onShortcutCast(shortcutIndex);
43
- shortcutsRefs.current[shortcutIndex]?.classList.add('active');
44
- setTimeout(() => {
45
- shortcutsRefs.current[shortcutIndex]?.classList.remove('active');
46
- }, 150);
47
- }
48
- };
49
-
50
- window.addEventListener('keydown', handleKeyDown);
51
-
52
- return () => {
53
- window.removeEventListener('keydown', handleKeyDown);
54
- };
55
- }, [shortcuts, isBlockedCastingByKeyboard]);
56
-
57
- return (
58
- <List>
59
- {Array.from({ length: 6 }).map((_, i) => {
60
- if (shortcuts[i]?.type === ShortcutType.Item) {
61
- const payload = shortcuts[i]?.payload as IItem | undefined;
62
-
63
- let itemsFromEquipment: (IItem | undefined | null)[] = [];
64
-
65
- if (inventory) {
66
- Object.keys(inventory.slots).forEach(i => {
67
- const index = parseInt(i);
68
-
69
- if (inventory.slots[index]?.key === payload?.key) {
70
- itemsFromEquipment.push(inventory.slots[index]);
71
- }
72
- });
73
- }
74
-
75
- const totalQty = itemsFromEquipment.reduce(
76
- (acc, item) => acc + (item?.stackQty || 1),
77
- 0
78
- );
79
-
80
- return (
81
- <StyledShortcut
82
- key={i}
83
- onPointerDown={onShortcutCast.bind(null, i)}
84
- disabled={false}
85
- ref={el => {
86
- if (el) shortcutsRefs.current[i] = el;
87
- }}
88
- >
89
- {payload && (
90
- <SpriteFromAtlas
91
- atlasIMG={atlasIMG}
92
- atlasJSON={atlasJSON}
93
- spriteKey={getItemTextureKeyPath(
94
- {
95
- key: payload.texturePath,
96
- texturePath: payload.texturePath,
97
- stackQty: payload.stackQty || 1,
98
- },
99
- atlasJSON
100
- )}
101
- width={32}
102
- height={32}
103
- />
104
- )}
105
- <span className="qty">{totalQty}</span>
106
- <span className="keyboard">{i + 1}</span>
107
- </StyledShortcut>
108
- );
109
- }
110
-
111
- const payload = shortcuts[i]?.payload as IRawSpell | undefined;
112
-
113
- return (
114
- <StyledShortcut
115
- key={i}
116
- onPointerDown={onShortcutCast.bind(null, i)}
117
- disabled={mana < (payload?.manaCost ?? 0)}
118
- ref={el => {
119
- if (el) shortcutsRefs.current[i] = el;
120
- }}
121
- >
122
- <span className="mana">{payload && payload.manaCost}</span>
123
- <span className="magicWords">
124
- {payload?.magicWords.split(' ').map(word => word[0])}
125
- </span>
126
- <span className="keyboard">{i + 1}</span>
127
- </StyledShortcut>
128
- );
129
- })}
130
- </List>
131
- );
132
- };
133
-
134
- const StyledShortcut = styled(SingleShortcut)`
135
- transition: all 0.15s;
136
-
137
- &.active {
138
- background-color: ${uiColors.gray};
139
- border-color: ${uiColors.yellow};
140
- }
141
- `;
142
-
143
- const List = styled.p`
144
- width: 100%;
145
- display: flex;
146
- align-items: center;
147
- justify-content: center;
148
- gap: 0.5rem;
149
- box-sizing: border-box;
150
- margin: 0 !important;
151
- `;
1
+ import {
2
+ getItemTextureKeyPath,
3
+ IItem,
4
+ IItemContainer,
5
+ IRawSpell,
6
+ IShortcut,
7
+ ShortcutType,
8
+ } from '@rpg-engine/shared';
9
+ import React, { useEffect, useRef } from 'react';
10
+ import styled from 'styled-components';
11
+ import { uiColors } from '../../constants/uiColors';
12
+ import { SpriteFromAtlas } from '../shared/SpriteFromAtlas';
13
+ import { SingleShortcut } from './SingleShortcut';
14
+
15
+ export type ShortcutsProps = {
16
+ shortcuts: IShortcut[];
17
+ onShortcutCast: (index: number) => void;
18
+ mana: number;
19
+ isBlockedCastingByKeyboard?: boolean;
20
+ inventory?: IItemContainer | null;
21
+ atlasJSON: any;
22
+ atlasIMG: any;
23
+ };
24
+
25
+ export const Shortcuts: React.FC<ShortcutsProps> = ({
26
+ shortcuts,
27
+ onShortcutCast,
28
+ mana,
29
+ isBlockedCastingByKeyboard = false,
30
+ atlasJSON,
31
+ atlasIMG,
32
+ inventory,
33
+ }) => {
34
+ const shortcutsRefs = useRef<HTMLButtonElement[]>([]);
35
+
36
+ useEffect(() => {
37
+ const handleKeyDown = (e: KeyboardEvent) => {
38
+ if (isBlockedCastingByKeyboard) return;
39
+
40
+ const shortcutIndex = Number(e.key) - 1;
41
+ if (shortcutIndex >= 0 && shortcutIndex <= 5) {
42
+ onShortcutCast(shortcutIndex);
43
+ shortcutsRefs.current[shortcutIndex]?.classList.add('active');
44
+ setTimeout(() => {
45
+ shortcutsRefs.current[shortcutIndex]?.classList.remove('active');
46
+ }, 150);
47
+ }
48
+ };
49
+
50
+ window.addEventListener('keydown', handleKeyDown);
51
+
52
+ return () => {
53
+ window.removeEventListener('keydown', handleKeyDown);
54
+ };
55
+ }, [shortcuts, isBlockedCastingByKeyboard]);
56
+
57
+ return (
58
+ <List>
59
+ {Array.from({ length: 6 }).map((_, i) => {
60
+ if (shortcuts[i]?.type === ShortcutType.Item) {
61
+ const payload = shortcuts[i]?.payload as IItem | undefined;
62
+
63
+ let itemsFromEquipment: (IItem | undefined | null)[] = [];
64
+
65
+ if (inventory) {
66
+ Object.keys(inventory.slots).forEach(i => {
67
+ const index = parseInt(i);
68
+
69
+ if (inventory.slots[index]?.key === payload?.key) {
70
+ itemsFromEquipment.push(inventory.slots[index]);
71
+ }
72
+ });
73
+ }
74
+
75
+ const totalQty = itemsFromEquipment.reduce(
76
+ (acc, item) => acc + (item?.stackQty || 1),
77
+ 0
78
+ );
79
+
80
+ return (
81
+ <StyledShortcut
82
+ key={i}
83
+ onPointerDown={onShortcutCast.bind(null, i)}
84
+ disabled={false}
85
+ ref={el => {
86
+ if (el) shortcutsRefs.current[i] = el;
87
+ }}
88
+ >
89
+ {payload && (
90
+ <SpriteFromAtlas
91
+ atlasIMG={atlasIMG}
92
+ atlasJSON={atlasJSON}
93
+ spriteKey={getItemTextureKeyPath(
94
+ {
95
+ key: payload.texturePath,
96
+ texturePath: payload.texturePath,
97
+ stackQty: payload.stackQty || 1,
98
+ },
99
+ atlasJSON
100
+ )}
101
+ width={32}
102
+ height={32}
103
+ />
104
+ )}
105
+ <span className="qty">{totalQty}</span>
106
+ <span className="keyboard">{i + 1}</span>
107
+ </StyledShortcut>
108
+ );
109
+ }
110
+
111
+ const payload = shortcuts[i]?.payload as IRawSpell | undefined;
112
+
113
+ return (
114
+ <StyledShortcut
115
+ key={i}
116
+ onPointerDown={onShortcutCast.bind(null, i)}
117
+ disabled={mana < (payload?.manaCost ?? 0)}
118
+ ref={el => {
119
+ if (el) shortcutsRefs.current[i] = el;
120
+ }}
121
+ >
122
+ <span className="mana">{payload && payload.manaCost}</span>
123
+ <span className="magicWords">
124
+ {payload?.magicWords.split(' ').map(word => word[0])}
125
+ </span>
126
+ <span className="keyboard">{i + 1}</span>
127
+ </StyledShortcut>
128
+ );
129
+ })}
130
+ </List>
131
+ );
132
+ };
133
+
134
+ const StyledShortcut = styled(SingleShortcut)`
135
+ transition: all 0.15s;
136
+
137
+ &.active {
138
+ background-color: ${uiColors.gray};
139
+ border-color: ${uiColors.yellow};
140
+ }
141
+ `;
142
+
143
+ const List = styled.p`
144
+ width: 100%;
145
+ display: flex;
146
+ align-items: center;
147
+ justify-content: center;
148
+ gap: 0.5rem;
149
+ box-sizing: border-box;
150
+ margin: 0 !important;
151
+ `;