@rpg-engine/long-bow 0.5.21 → 0.5.22
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/components/Abstractions/SlotsContainer.d.ts +1 -0
- package/dist/components/Item/Inventory/DraggedItem.d.ts +7 -0
- package/dist/components/Item/Inventory/ItemSlotQty/ItemSlotQty.d.ts +9 -0
- package/dist/components/Item/Inventory/ItemSlotRenderer.d.ts +11 -0
- package/dist/components/Item/Inventory/ItemSlotTooltips.d.ts +24 -0
- package/dist/components/Item/Inventory/context/DraggingContext.d.ts +11 -0
- package/dist/hooks/useMousePosition.d.ts +6 -0
- package/dist/long-bow.cjs.development.js +342 -177
- 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 +343 -178
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Abstractions/SlotsContainer.tsx +3 -1
- package/src/components/Equipment/EquipmentSet.tsx +24 -19
- package/src/components/Item/Inventory/DraggedItem.tsx +107 -0
- package/src/components/Item/Inventory/ItemContainer.tsx +6 -3
- package/src/components/Item/Inventory/ItemQuantitySelectorModal.tsx +0 -0
- package/src/components/Item/Inventory/ItemSlot.tsx +50 -211
- package/src/components/Item/Inventory/ItemSlotQty/ItemSlotQty.tsx +70 -0
- package/src/components/Item/Inventory/ItemSlotRenderer.tsx +92 -0
- package/src/components/Item/Inventory/ItemSlotTooltips.tsx +93 -0
- package/src/components/Item/Inventory/context/DraggingContext.tsx +26 -0
- package/src/hooks/useMousePosition.ts +49 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IItem,
|
|
3
|
+
ItemContainerType,
|
|
4
|
+
ItemSlotType,
|
|
5
|
+
getItemTextureKeyPath,
|
|
6
|
+
} from '@rpg-engine/shared';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
9
|
+
import { SpriteFromAtlas } from '../../shared/SpriteFromAtlas';
|
|
10
|
+
import { ErrorBoundary } from './ErrorBoundary';
|
|
11
|
+
import { EquipmentSlotSpriteByType } from './ItemSlot';
|
|
12
|
+
import { onRenderStackInfo } from './ItemSlotQty/ItemSlotQty';
|
|
13
|
+
|
|
14
|
+
interface IProps {
|
|
15
|
+
containerType: ItemContainerType | null | undefined;
|
|
16
|
+
atlasJSON: any;
|
|
17
|
+
atlasIMG: any;
|
|
18
|
+
slotSpriteMask: ItemSlotType | null | undefined;
|
|
19
|
+
item: IItem | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const ItemSlotRenderer: React.FC<IProps> = ({
|
|
23
|
+
containerType,
|
|
24
|
+
atlasJSON,
|
|
25
|
+
atlasIMG,
|
|
26
|
+
slotSpriteMask,
|
|
27
|
+
item,
|
|
28
|
+
}) => {
|
|
29
|
+
const renderItem = (itemToRender: IItem | null) => {
|
|
30
|
+
if (!itemToRender?.texturePath) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<ErrorBoundary key={itemToRender._id}>
|
|
36
|
+
<SpriteFromAtlas
|
|
37
|
+
atlasIMG={atlasIMG}
|
|
38
|
+
atlasJSON={atlasJSON}
|
|
39
|
+
spriteKey={getItemTextureKeyPath(
|
|
40
|
+
{
|
|
41
|
+
key: itemToRender.texturePath,
|
|
42
|
+
texturePath: itemToRender.texturePath,
|
|
43
|
+
stackQty: itemToRender.stackQty || 1,
|
|
44
|
+
isStackable: itemToRender.isStackable,
|
|
45
|
+
},
|
|
46
|
+
atlasJSON
|
|
47
|
+
)}
|
|
48
|
+
imgScale={3}
|
|
49
|
+
imgClassname="sprite-from-atlas-img--item"
|
|
50
|
+
/>
|
|
51
|
+
{onRenderStackInfo(itemToRender._id, itemToRender.stackQty ?? 0)}
|
|
52
|
+
</ErrorBoundary>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const renderEquipment = (itemToRender: IItem | null) => {
|
|
57
|
+
if (
|
|
58
|
+
!itemToRender?.texturePath ||
|
|
59
|
+
!itemToRender.allowedEquipSlotType?.includes(slotSpriteMask!)
|
|
60
|
+
) {
|
|
61
|
+
return (
|
|
62
|
+
<ErrorBoundary key={uuidv4()}>
|
|
63
|
+
<SpriteFromAtlas
|
|
64
|
+
key={uuidv4()}
|
|
65
|
+
atlasIMG={atlasIMG}
|
|
66
|
+
atlasJSON={atlasJSON}
|
|
67
|
+
spriteKey={EquipmentSlotSpriteByType[slotSpriteMask!]}
|
|
68
|
+
imgScale={3}
|
|
69
|
+
grayScale={true}
|
|
70
|
+
opacity={0.4}
|
|
71
|
+
imgClassname="sprite-from-atlas-img--item"
|
|
72
|
+
/>
|
|
73
|
+
</ErrorBoundary>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return renderItem(itemToRender);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const onRenderSlot = (itemToRender: IItem | null) => {
|
|
81
|
+
switch (containerType) {
|
|
82
|
+
case ItemContainerType.Equipment:
|
|
83
|
+
return renderEquipment(itemToRender);
|
|
84
|
+
case ItemContainerType.Inventory:
|
|
85
|
+
return renderItem(itemToRender);
|
|
86
|
+
default:
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return <>{onRenderSlot(item)}</>;
|
|
92
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { IEquipmentSet, IItem } from '@rpg-engine/shared';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { IPosition } from '../../../types/eventTypes';
|
|
4
|
+
import { RelativeListMenu } from '../../RelativeListMenu';
|
|
5
|
+
import { ItemTooltip } from '../Cards/ItemTooltip';
|
|
6
|
+
import { MobileItemTooltip } from '../Cards/MobileItemTooltip';
|
|
7
|
+
import { IContextMenuItem } from './itemContainerHelper';
|
|
8
|
+
|
|
9
|
+
interface IProps {
|
|
10
|
+
isTooltipVisible: boolean;
|
|
11
|
+
isFocused: boolean;
|
|
12
|
+
isContextMenuVisible: boolean;
|
|
13
|
+
isContextMenuDisabled: boolean;
|
|
14
|
+
item: IItem | null;
|
|
15
|
+
isTooltipMobileVisible: boolean;
|
|
16
|
+
contextActions: IContextMenuItem[];
|
|
17
|
+
contextMenuPosition: IPosition;
|
|
18
|
+
dragScale: number | undefined;
|
|
19
|
+
setIsContextMenuVisible: (visible: boolean) => void;
|
|
20
|
+
setIsTooltipMobileVisible: (visible: boolean) => void;
|
|
21
|
+
setIsTooltipVisible: (visible: boolean) => void;
|
|
22
|
+
onSelected?: (optionId: string, item: IItem) => void;
|
|
23
|
+
atlasIMG: any;
|
|
24
|
+
atlasJSON: any;
|
|
25
|
+
equipmentSet?: IEquipmentSet | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const ItemSlotToolTips = ({
|
|
29
|
+
isTooltipVisible,
|
|
30
|
+
isFocused,
|
|
31
|
+
isContextMenuVisible,
|
|
32
|
+
isContextMenuDisabled,
|
|
33
|
+
item,
|
|
34
|
+
contextActions,
|
|
35
|
+
contextMenuPosition,
|
|
36
|
+
dragScale,
|
|
37
|
+
setIsContextMenuVisible,
|
|
38
|
+
setIsTooltipMobileVisible,
|
|
39
|
+
isTooltipMobileVisible,
|
|
40
|
+
onSelected,
|
|
41
|
+
atlasIMG,
|
|
42
|
+
atlasJSON,
|
|
43
|
+
equipmentSet,
|
|
44
|
+
}: IProps): JSX.Element => {
|
|
45
|
+
return (
|
|
46
|
+
<>
|
|
47
|
+
{isTooltipVisible && item && !isFocused && (
|
|
48
|
+
<ItemTooltip
|
|
49
|
+
item={item}
|
|
50
|
+
atlasIMG={atlasIMG}
|
|
51
|
+
atlasJSON={atlasJSON}
|
|
52
|
+
equipmentSet={equipmentSet}
|
|
53
|
+
/>
|
|
54
|
+
)}
|
|
55
|
+
|
|
56
|
+
{isTooltipMobileVisible && item && (
|
|
57
|
+
<MobileItemTooltip
|
|
58
|
+
item={item}
|
|
59
|
+
atlasIMG={atlasIMG}
|
|
60
|
+
atlasJSON={atlasJSON}
|
|
61
|
+
equipmentSet={equipmentSet}
|
|
62
|
+
closeTooltip={() => {
|
|
63
|
+
setIsTooltipMobileVisible(false);
|
|
64
|
+
}}
|
|
65
|
+
scale={dragScale}
|
|
66
|
+
options={contextActions}
|
|
67
|
+
onSelected={(optionId: string) => {
|
|
68
|
+
setIsContextMenuVisible(false);
|
|
69
|
+
if (item) {
|
|
70
|
+
onSelected?.(optionId, item);
|
|
71
|
+
}
|
|
72
|
+
}}
|
|
73
|
+
/>
|
|
74
|
+
)}
|
|
75
|
+
|
|
76
|
+
{!isContextMenuDisabled && isContextMenuVisible && contextActions && (
|
|
77
|
+
<RelativeListMenu
|
|
78
|
+
options={contextActions}
|
|
79
|
+
onSelected={(optionId: string) => {
|
|
80
|
+
setIsContextMenuVisible(false);
|
|
81
|
+
if (item) {
|
|
82
|
+
onSelected?.(optionId, item);
|
|
83
|
+
}
|
|
84
|
+
}}
|
|
85
|
+
onOutsideClick={() => {
|
|
86
|
+
setIsContextMenuVisible(false);
|
|
87
|
+
}}
|
|
88
|
+
pos={contextMenuPosition}
|
|
89
|
+
/>
|
|
90
|
+
)}
|
|
91
|
+
</>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IItem } from '@rpg-engine/shared';
|
|
2
|
+
import React, { createContext, useContext, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
const DraggingContext = createContext<{
|
|
5
|
+
item: IItem | null;
|
|
6
|
+
setDraggingItem: React.Dispatch<React.SetStateAction<IItem | null>>;
|
|
7
|
+
}>({
|
|
8
|
+
item: null,
|
|
9
|
+
setDraggingItem: () => {},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const useDragging = () => useContext(DraggingContext);
|
|
13
|
+
|
|
14
|
+
interface IProps {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const DraggingProvider = ({ children }: IProps) => {
|
|
19
|
+
const [item, setDraggingItem] = useState<IItem | null>(null);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<DraggingContext.Provider value={{ item, setDraggingItem }}>
|
|
23
|
+
{children}
|
|
24
|
+
</DraggingContext.Provider>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
interface ICursorPosition {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const useCursorPosition = (): ICursorPosition => {
|
|
9
|
+
const [cursorPosition, setCursorPosition] = useState<ICursorPosition>({ x: 0, y: 0 });
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
let animationFrameId: number;
|
|
13
|
+
|
|
14
|
+
const updateCursorPosition = (x: number, y: number) => {
|
|
15
|
+
// Cancel the previous frame request
|
|
16
|
+
cancelAnimationFrame(animationFrameId);
|
|
17
|
+
|
|
18
|
+
// Request a new frame
|
|
19
|
+
animationFrameId = requestAnimationFrame(() => {
|
|
20
|
+
setCursorPosition({ x, y });
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const handleMouseMove = (event: MouseEvent) => {
|
|
25
|
+
updateCursorPosition(event.clientX, event.clientY);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const handleTouchMove = (event: TouchEvent) => {
|
|
29
|
+
// Prevent default touch behavior (like scrolling)
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
if (event.touches.length > 0) {
|
|
32
|
+
const touch = event.touches[0];
|
|
33
|
+
updateCursorPosition(touch.clientX, touch.clientY);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
window.addEventListener('mousemove', handleMouseMove);
|
|
38
|
+
window.addEventListener('touchmove', handleTouchMove, { passive: false });
|
|
39
|
+
|
|
40
|
+
// Cleanup function
|
|
41
|
+
return () => {
|
|
42
|
+
window.removeEventListener('mousemove', handleMouseMove);
|
|
43
|
+
window.removeEventListener('touchmove', handleTouchMove);
|
|
44
|
+
cancelAnimationFrame(animationFrameId);
|
|
45
|
+
};
|
|
46
|
+
}, []);
|
|
47
|
+
|
|
48
|
+
return cursorPosition;
|
|
49
|
+
};
|