@rpg-engine/long-bow 0.7.70 → 0.7.72

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 (25) hide show
  1. package/dist/components/Item/Inventory/ItemSlot.d.ts +5 -18
  2. package/dist/components/Item/Inventory/ItemSlotTooltips.d.ts +12 -1
  3. package/dist/components/Item/Inventory/context/DraggingContext.d.ts +11 -0
  4. package/dist/hooks/useCursorPosition.d.ts +1 -1
  5. package/dist/long-bow.cjs.development.js +573 -661
  6. package/dist/long-bow.cjs.development.js.map +1 -1
  7. package/dist/long-bow.cjs.production.min.js +1 -1
  8. package/dist/long-bow.cjs.production.min.js.map +1 -1
  9. package/dist/long-bow.esm.js +575 -663
  10. package/dist/long-bow.esm.js.map +1 -1
  11. package/package.json +2 -3
  12. package/src/components/Equipment/EquipmentSet.tsx +29 -61
  13. package/src/components/Item/Inventory/DraggedItem.tsx +2 -2
  14. package/src/components/Item/Inventory/ItemContainer.tsx +44 -68
  15. package/src/components/Item/Inventory/ItemSlot.tsx +451 -239
  16. package/src/components/Item/Inventory/ItemSlotTooltips.tsx +46 -48
  17. package/src/components/Item/Inventory/context/DraggingContext.tsx +26 -0
  18. package/src/hooks/useCursorPosition.ts +20 -29
  19. package/src/stories/UI/containers/ItemContainer.stories.tsx +3 -30
  20. package/dist/components/Item/Inventory/context/ItemSlotDraggingContext.d.ts +0 -26
  21. package/dist/components/Item/Inventory/context/ItemSlotTooltipContext.d.ts +0 -28
  22. package/dist/components/Item/Inventory/hooks/useItemSlotDragAndDrop.d.ts +0 -39
  23. package/src/components/Item/Inventory/context/ItemSlotDraggingContext.tsx +0 -52
  24. package/src/components/Item/Inventory/context/ItemSlotTooltipContext.tsx +0 -95
  25. package/src/components/Item/Inventory/hooks/useItemSlotDragAndDrop.ts +0 -248
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.7.70",
3
+ "version": "0.7.72",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -30,8 +30,7 @@
30
30
  "storybook": "start-storybook -p 6006",
31
31
  "build-storybook": "build-storybook",
32
32
  "configure": "./environment/download-credentials.sh",
33
- "update:shared-deps": "yarn add @rpg-engine/shared",
34
- "prepublish": "yarn tsc"
33
+ "update:shared-deps": "yarn add @rpg-engine/shared"
35
34
  },
36
35
  "peerDependencies": {
37
36
  "react": ">=16"
@@ -2,7 +2,6 @@ import {
2
2
  IEquipmentSet,
3
3
  IItem,
4
4
  IItemContainer,
5
- isMobile,
6
5
  ItemContainerType,
7
6
  ItemSlotType,
8
7
  ItemType,
@@ -11,17 +10,9 @@ import React from 'react';
11
10
  import styled from 'styled-components';
12
11
  import { IPosition } from '../../types/eventTypes';
13
12
  import { DraggableContainer } from '../DraggableContainer';
14
- import {
15
- ItemSlotDraggingProvider,
16
- useItemSlotDragging,
17
- } from '../Item/Inventory/context/ItemSlotDraggingContext';
18
- import {
19
- ItemSlotTooltipProvider,
20
- useItemSlotTooltip,
21
- } from '../Item/Inventory/context/ItemSlotTooltipContext';
22
13
  import DraggedItem from '../Item/Inventory/DraggedItem';
23
14
  import { ItemSlot } from '../Item/Inventory/ItemSlot';
24
- import { ItemSlotToolTips } from '../Item/Inventory/ItemSlotTooltips';
15
+ import { DraggingProvider } from '../Item/Inventory/context/DraggingContext';
25
16
  import { RPGUIContainerTypes } from '../RPGUI/RPGUIContainer';
26
17
 
27
18
  export interface IEquipmentSetProps {
@@ -61,6 +52,7 @@ export const EquipmentSet: React.FC<IEquipmentSetProps> = ({
61
52
  equipmentSet,
62
53
  onClose,
63
54
  onMouseOver,
55
+ onSelected,
64
56
  onItemClick,
65
57
  atlasIMG,
66
58
  atlasJSON,
@@ -69,11 +61,11 @@ export const EquipmentSet: React.FC<IEquipmentSetProps> = ({
69
61
  onItemPlaceDrop,
70
62
  onItemOutsideDrop,
71
63
  checkIfItemCanBeMoved,
64
+ checkIfItemShouldDragEnd,
72
65
  scale,
73
66
  initialPosition,
74
67
  onPositionChangeEnd,
75
68
  onPositionChangeStart,
76
- onSelected,
77
69
  }) => {
78
70
  const {
79
71
  neck,
@@ -114,10 +106,6 @@ export const EquipmentSet: React.FC<IEquipmentSetProps> = ({
114
106
  ItemSlotType.Accessory,
115
107
  ];
116
108
 
117
- const { dragState } = useItemSlotDragging();
118
-
119
- const { updateItemDetails } = useItemSlotTooltip();
120
-
121
109
  const onRenderEquipmentSlotRange = (start: number, end: number) => {
122
110
  const equipmentRange = equipmentData.slice(start, end);
123
111
  const slotMaksRange = equipmentMaskSlots.slice(start, end);
@@ -141,6 +129,9 @@ export const EquipmentSet: React.FC<IEquipmentSetProps> = ({
141
129
  onPointerDown={(itemType, ContainerType) => {
142
130
  if (onItemClick) onItemClick(itemType, item, ContainerType);
143
131
  }}
132
+ onSelected={(optionId: string) => {
133
+ if (onSelected) onSelected(optionId);
134
+ }}
144
135
  onDragStart={(item, slotIndex, itemContainerType) => {
145
136
  if (!item) {
146
137
  return;
@@ -154,6 +145,7 @@ export const EquipmentSet: React.FC<IEquipmentSetProps> = ({
154
145
  }}
155
146
  dragScale={scale}
156
147
  checkIfItemCanBeMoved={checkIfItemCanBeMoved}
148
+ checkIfItemShouldDragEnd={checkIfItemShouldDragEnd}
157
149
  onPlaceDrop={(item, slotIndex, itemContainerType) => {
158
150
  if (onItemPlaceDrop)
159
151
  onItemPlaceDrop(item, slotIndex, itemContainerType);
@@ -169,52 +161,28 @@ export const EquipmentSet: React.FC<IEquipmentSetProps> = ({
169
161
  };
170
162
 
171
163
  return (
172
- <ItemSlotDraggingProvider>
173
- <ItemSlotTooltipProvider>
174
- <DraggedItem atlasIMG={atlasIMG} atlasJSON={atlasJSON} scale={scale} />
175
- <DraggableContainer
176
- title={'Equipments'}
177
- type={RPGUIContainerTypes.Framed}
178
- onCloseButton={() => {
179
- if (onClose) onClose();
180
- }}
181
- width="330px"
182
- cancelDrag=".equipment-container-body"
183
- scale={scale}
184
- initialPosition={initialPosition}
185
- onPositionChangeEnd={onPositionChangeEnd}
186
- onPositionChangeStart={onPositionChangeStart}
187
- >
188
- <EquipmentSetContainer className="equipment-container-body">
189
- <EquipmentColumn>
190
- {onRenderEquipmentSlotRange(0, 3)}
191
- </EquipmentColumn>
192
- <EquipmentColumn>
193
- {onRenderEquipmentSlotRange(3, 7)}
194
- </EquipmentColumn>
195
- <EquipmentColumn>
196
- {onRenderEquipmentSlotRange(7, 10)}
197
- </EquipmentColumn>
198
- </EquipmentSetContainer>
199
- </DraggableContainer>
200
-
201
- <ItemSlotToolTips
202
- isFocused={dragState.isFocused}
203
- isContextMenuDisabled={isMobile()}
204
- dragScale={scale}
205
- onSelected={(optionId: string, item: IItem) => {
206
- updateItemDetails({
207
- item,
208
- contextMenu: { visible: false },
209
- });
210
- if (onSelected) onSelected(optionId);
211
- }}
212
- atlasIMG={atlasIMG}
213
- atlasJSON={atlasJSON}
214
- equipmentSet={equipmentSet}
215
- />
216
- </ItemSlotTooltipProvider>
217
- </ItemSlotDraggingProvider>
164
+ <DraggingProvider>
165
+ <DraggedItem atlasIMG={atlasIMG} atlasJSON={atlasJSON} scale={scale} />
166
+ <DraggableContainer
167
+ title={'Equipments'}
168
+ type={RPGUIContainerTypes.Framed}
169
+ onCloseButton={() => {
170
+ if (onClose) onClose();
171
+ }}
172
+ width="330px"
173
+ cancelDrag=".equipment-container-body"
174
+ scale={scale}
175
+ initialPosition={initialPosition}
176
+ onPositionChangeEnd={onPositionChangeEnd}
177
+ onPositionChangeStart={onPositionChangeStart}
178
+ >
179
+ <EquipmentSetContainer className="equipment-container-body">
180
+ <EquipmentColumn>{onRenderEquipmentSlotRange(0, 3)}</EquipmentColumn>
181
+ <EquipmentColumn>{onRenderEquipmentSlotRange(3, 7)}</EquipmentColumn>
182
+ <EquipmentColumn>{onRenderEquipmentSlotRange(7, 10)}</EquipmentColumn>
183
+ </EquipmentSetContainer>
184
+ </DraggableContainer>
185
+ </DraggingProvider>
218
186
  );
219
187
  };
220
188
 
@@ -4,7 +4,7 @@ import styled from 'styled-components';
4
4
  import { useCursorPosition } from '../../../hooks/useCursorPosition';
5
5
  import { SpriteFromAtlas } from '../../shared/SpriteFromAtlas';
6
6
  import { onRenderStackInfo } from './ItemSlotQty/ItemSlotQty';
7
- import { useItemSlotDragging } from './context/ItemSlotDraggingContext';
7
+ import { useDragging } from './context/DraggingContext';
8
8
 
9
9
  const CONTAINER_SIZE = 32;
10
10
  const OFFSET = CONTAINER_SIZE / 2;
@@ -20,7 +20,7 @@ export const DraggedItem = ({
20
20
  atlasIMG,
21
21
  scale,
22
22
  }: IProps): JSX.Element | null => {
23
- const { item } = useItemSlotDragging();
23
+ const { item } = useDragging();
24
24
 
25
25
  const { x, y } = useCursorPosition({
26
26
  scale,
@@ -14,18 +14,10 @@ import { SlotsContainer } from '../../Abstractions/SlotsContainer';
14
14
  import { useScrollOnDrag } from '../../../hooks/useScrollOnDrag';
15
15
  import { IPosition } from '../../../types/eventTypes';
16
16
  import { ShortcutsSetter } from '../../Shortcuts/ShortcutsSetter';
17
- import {
18
- ItemSlotDraggingProvider,
19
- useItemSlotDragging,
20
- } from './context/ItemSlotDraggingContext';
21
- import {
22
- ItemSlotTooltipProvider,
23
- useItemSlotTooltip,
24
- } from './context/ItemSlotTooltipContext';
25
17
  import { DraggedItem } from './DraggedItem';
26
18
  import { ItemQuantitySelectorModal } from './ItemQuantitySelectorModal';
27
19
  import { ItemSlot } from './ItemSlot';
28
- import { ItemSlotToolTips } from './ItemSlotTooltips';
20
+ import { DraggingProvider } from './context/DraggingContext';
29
21
 
30
22
  export interface IItemContainerProps {
31
23
  itemContainer: IItemContainer;
@@ -95,6 +87,7 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
95
87
  onOutsideDrop,
96
88
  checkIfItemCanBeMoved,
97
89
  initialPosition,
90
+ checkIfItemShouldDragEnd,
98
91
  scale,
99
92
  shortcuts,
100
93
  setItemShortcut,
@@ -189,10 +182,14 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
189
182
  onItemClick(item, itemType, containerType);
190
183
  }
191
184
  }}
185
+ onSelected={(optionId: string, item: IItem) => {
186
+ if (onSelected) onSelected(optionId, item);
187
+ }}
192
188
  onDragStart={onDragStart}
193
189
  onDragEnd={onDragEnd}
194
190
  dragScale={scale}
195
191
  checkIfItemCanBeMoved={checkIfItemCanBeMoved}
192
+ checkIfItemShouldDragEnd={checkIfItemShouldDragEnd}
196
193
  openQuantitySelector={(maxQuantity, callback) => {
197
194
  setQuantitySelect({
198
195
  isOpen: true,
@@ -221,6 +218,7 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
221
218
  atlasIMG={atlasIMG}
222
219
  atlasJSON={atlasJSON}
223
220
  isSelectingShortcut={settingShortcutIndex !== -1}
221
+ equipmentSet={equipmentSet}
224
222
  setItemShortcut={
225
223
  type === ItemContainerType.Inventory ? handleSetShortcut : undefined
226
224
  }
@@ -231,69 +229,47 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
231
229
  return slots;
232
230
  };
233
231
 
234
- const { updateItemDetails } = useItemSlotTooltip();
235
- const { dragState } = useItemSlotDragging();
236
-
237
232
  return (
238
- <ItemSlotDraggingProvider>
239
- <ItemSlotTooltipProvider>
240
- <DraggedItem atlasIMG={atlasIMG} atlasJSON={atlasJSON} scale={scale} />
241
- <SlotsContainer
242
- title={itemContainer.name || 'Container'}
243
- onClose={onClose}
244
- initialPosition={initialPosition}
245
- scale={scale}
246
- onPositionChangeEnd={onPositionChangeEnd}
247
- onPositionChangeStart={onPositionChangeStart}
233
+ <DraggingProvider>
234
+ <DraggedItem atlasIMG={atlasIMG} atlasJSON={atlasJSON} scale={scale} />
235
+ <SlotsContainer
236
+ title={itemContainer.name || 'Container'}
237
+ onClose={onClose}
238
+ initialPosition={initialPosition}
239
+ scale={scale}
240
+ onPositionChangeEnd={onPositionChangeEnd}
241
+ onPositionChangeStart={onPositionChangeStart}
242
+ isFullScreen={isFullScreen}
243
+ opacity={opacity}
244
+ >
245
+ {type === ItemContainerType.Inventory &&
246
+ shortcuts &&
247
+ removeShortcut && (
248
+ <ShortcutsSetter
249
+ setSettingShortcutIndex={setSettingShortcutIndex}
250
+ settingShortcutIndex={settingShortcutIndex}
251
+ shortcuts={shortcuts}
252
+ removeShortcut={removeShortcut}
253
+ atlasIMG={atlasIMG}
254
+ atlasJSON={atlasJSON}
255
+ />
256
+ )}
257
+ <ItemsContainer
258
+ className="item-container-body"
259
+ ref={containerRef}
260
+ isScrollable={itemContainer.slotQty > MIN_SLOTS_FOR_SCROLL}
248
261
  isFullScreen={isFullScreen}
249
- opacity={opacity}
250
262
  >
251
- {type === ItemContainerType.Inventory &&
252
- shortcuts &&
253
- removeShortcut && (
254
- <ShortcutsSetter
255
- setSettingShortcutIndex={setSettingShortcutIndex}
256
- settingShortcutIndex={settingShortcutIndex}
257
- shortcuts={shortcuts}
258
- removeShortcut={removeShortcut}
259
- atlasIMG={atlasIMG}
260
- atlasJSON={atlasJSON}
261
- />
262
- )}
263
- <ItemsContainer
264
- className="item-container-body"
265
- ref={containerRef}
266
- isScrollable={itemContainer.slotQty > MIN_SLOTS_FOR_SCROLL}
267
- isFullScreen={isFullScreen}
268
- >
269
- {onRenderSlots()}
270
- </ItemsContainer>
271
- </SlotsContainer>
272
-
273
- <ItemSlotToolTips
274
- isFocused={dragState.isFocused}
275
- isContextMenuDisabled={disableContextMenu}
276
- dragScale={scale}
277
- onSelected={(optionId: string, item: IItem) => {
278
- updateItemDetails({
279
- item,
280
- contextMenu: { visible: false },
281
- });
282
- if (onSelected) onSelected(optionId, item);
283
- }}
284
- atlasIMG={atlasIMG}
285
- atlasJSON={atlasJSON}
286
- equipmentSet={equipmentSet}
263
+ {onRenderSlots()}
264
+ </ItemsContainer>
265
+ </SlotsContainer>
266
+ {quantitySelect.isOpen && (
267
+ <ItemQuantitySelectorModal
268
+ quantitySelect={quantitySelect}
269
+ setQuantitySelect={setQuantitySelect}
287
270
  />
288
-
289
- {quantitySelect.isOpen && (
290
- <ItemQuantitySelectorModal
291
- quantitySelect={quantitySelect}
292
- setQuantitySelect={setQuantitySelect}
293
- />
294
- )}
295
- </ItemSlotTooltipProvider>
296
- </ItemSlotDraggingProvider>
271
+ )}
272
+ </DraggingProvider>
297
273
  );
298
274
  };
299
275