@rpg-engine/long-bow 0.5.24 → 0.5.26
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/Item/Inventory/DraggedItem.d.ts +2 -1
- package/dist/components/shared/ScalableContainer.d.ts +7 -0
- package/dist/constants/uiBreakpoints.d.ts +2 -0
- package/dist/hooks/useCursorPosition.d.ts +5 -5
- package/dist/long-bow.cjs.development.js +27 -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 +27 -14
- package/dist/long-bow.esm.js.map +1 -1
- package/dist/stories/ItemContainer.stories.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/Equipment/EquipmentSet.tsx +1 -1
- package/src/components/Item/Inventory/DraggedItem.tsx +5 -1
- package/src/components/Item/Inventory/ItemContainer.tsx +1 -1
- package/src/components/Spellbook/constants.ts +1 -1
- package/src/components/shared/ScalableContainer.tsx +22 -0
- package/src/constants/uiBreakpoints.ts +3 -0
- package/src/hooks/useCursorPosition.ts +25 -9
- package/src/stories/ItemContainer.stories.tsx +94 -70
|
@@ -5,6 +5,8 @@ declare const meta: Meta;
|
|
|
5
5
|
export default meta;
|
|
6
6
|
interface ITemplateProps {
|
|
7
7
|
type: ItemContainerType;
|
|
8
|
+
scale?: number;
|
|
8
9
|
}
|
|
9
10
|
export declare const Inventory: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, IItemContainerProps & ITemplateProps>;
|
|
11
|
+
export declare const InventoryScaledDown: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, IItemContainerProps & ITemplateProps>;
|
|
10
12
|
export declare const Depot: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, IItemContainerProps & ITemplateProps>;
|
package/package.json
CHANGED
|
@@ -162,7 +162,7 @@ export const EquipmentSet: React.FC<IEquipmentSetProps> = ({
|
|
|
162
162
|
|
|
163
163
|
return (
|
|
164
164
|
<DraggingProvider>
|
|
165
|
-
<DraggedItem atlasIMG={atlasIMG} atlasJSON={atlasJSON} />
|
|
165
|
+
<DraggedItem atlasIMG={atlasIMG} atlasJSON={atlasJSON} scale={scale} />
|
|
166
166
|
<DraggableContainer
|
|
167
167
|
title={'Equipments'}
|
|
168
168
|
type={RPGUIContainerTypes.Framed}
|
|
@@ -12,14 +12,18 @@ const OFFSET = CONTAINER_SIZE / 2;
|
|
|
12
12
|
interface IProps {
|
|
13
13
|
atlasJSON: any;
|
|
14
14
|
atlasIMG: any;
|
|
15
|
+
scale?: number;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export const DraggedItem = ({
|
|
18
19
|
atlasJSON,
|
|
19
20
|
atlasIMG,
|
|
21
|
+
scale,
|
|
20
22
|
}: IProps): JSX.Element | null => {
|
|
21
23
|
const { item } = useDragging();
|
|
22
|
-
const { x, y } = useCursorPosition(
|
|
24
|
+
const { x, y } = useCursorPosition({
|
|
25
|
+
scale,
|
|
26
|
+
});
|
|
23
27
|
|
|
24
28
|
if (!item) {
|
|
25
29
|
return null;
|
|
@@ -159,7 +159,7 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
|
|
|
159
159
|
|
|
160
160
|
return (
|
|
161
161
|
<DraggingProvider>
|
|
162
|
-
<DraggedItem atlasIMG={atlasIMG} atlasJSON={atlasJSON} />
|
|
162
|
+
<DraggedItem atlasIMG={atlasIMG} atlasJSON={atlasJSON} scale={scale} />
|
|
163
163
|
<SlotsContainer
|
|
164
164
|
title={itemContainer.name || 'Container'}
|
|
165
165
|
onClose={onClose}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
import { UI_BREAKPOINT_MOBILE } from '../../constants/uiBreakpoints';
|
|
3
|
+
|
|
4
|
+
interface IScalableContainerProps {
|
|
5
|
+
scale?: number;
|
|
6
|
+
centralize?: boolean;
|
|
7
|
+
breakPoint?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const ScalableContainer = styled.div<IScalableContainerProps>`
|
|
11
|
+
${({ centralize = true }) =>
|
|
12
|
+
centralize &&
|
|
13
|
+
css`
|
|
14
|
+
display: flex;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
align-items: center;
|
|
17
|
+
`}
|
|
18
|
+
|
|
19
|
+
@media (max-width: ${({ breakPoint }) => breakPoint ?? UI_BREAKPOINT_MOBILE}) {
|
|
20
|
+
transform: scale(${({ scale }) => scale ?? 0.75});
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
@@ -1,30 +1,46 @@
|
|
|
1
|
+
import { GRID_HEIGHT, GRID_WIDTH } from '@rpg-engine/shared';
|
|
1
2
|
import { useEffect, useState } from 'react';
|
|
3
|
+
import { IPosition } from '../types/eventTypes';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
5
|
+
interface ICursorPositionProps {
|
|
6
|
+
scale?: number;
|
|
7
|
+
}
|
|
7
8
|
|
|
8
|
-
export const useCursorPosition = ():
|
|
9
|
-
const [position, setPosition] = useState<
|
|
9
|
+
export const useCursorPosition = ({ scale = 1 }: ICursorPositionProps): IPosition => {
|
|
10
|
+
const [position, setPosition] = useState<IPosition>({ x: 0, y: 0 });
|
|
10
11
|
|
|
11
12
|
const setFromEvent = (e: MouseEvent | TouchEvent) => {
|
|
13
|
+
let x, y;
|
|
14
|
+
const viewportCenterX = window.innerWidth / 2 - GRID_WIDTH;
|
|
15
|
+
const viewportCenterY = window.innerHeight / - GRID_HEIGHT;
|
|
16
|
+
|
|
12
17
|
if ('touches' in e) {
|
|
13
|
-
|
|
18
|
+
x = e.touches[0].clientX;
|
|
19
|
+
y = e.touches[0].clientY;
|
|
14
20
|
} else {
|
|
15
|
-
|
|
21
|
+
x = e.clientX;
|
|
22
|
+
y = e.clientY;
|
|
16
23
|
}
|
|
24
|
+
|
|
25
|
+
// Adjusting for the global scale
|
|
26
|
+
// Assuming the element is centrally located
|
|
27
|
+
setPosition({
|
|
28
|
+
x: (x - viewportCenterX) / scale + viewportCenterX,
|
|
29
|
+
y: (y - viewportCenterY) / scale + viewportCenterY
|
|
30
|
+
});
|
|
17
31
|
};
|
|
18
32
|
|
|
19
33
|
useEffect(() => {
|
|
20
34
|
window.addEventListener('mousemove', setFromEvent);
|
|
21
35
|
window.addEventListener('touchmove', setFromEvent);
|
|
22
36
|
|
|
37
|
+
console.log("SCALE IS ", scale)
|
|
38
|
+
|
|
23
39
|
return () => {
|
|
24
40
|
window.removeEventListener('mousemove', setFromEvent);
|
|
25
41
|
window.removeEventListener('touchmove', setFromEvent);
|
|
26
42
|
};
|
|
27
|
-
}, []);
|
|
43
|
+
}, [scale]);
|
|
28
44
|
|
|
29
45
|
return position;
|
|
30
46
|
};
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
import { RPGUIRoot } from '../../src/components/RPGUIRoot';
|
|
9
9
|
import { equipmentSetMock } from '../../src/mocks/equipmentSet.mocks';
|
|
10
10
|
import { itemContainerMock } from '../../src/mocks/itemContainer.mocks';
|
|
11
|
+
import { ScalableContainer } from '../components/shared/ScalableContainer';
|
|
12
|
+
import { UI_BREAKPOINT_SMALL_LAPTOP } from '../constants/uiBreakpoints';
|
|
11
13
|
import { useShortcuts } from '../hooks/useShortcuts';
|
|
12
14
|
import atlasJSON from '../mocks/atlas/items/items.json';
|
|
13
15
|
import atlasIMG from '../mocks/atlas/items/items.png';
|
|
@@ -48,9 +50,13 @@ let dropSlot = -1;
|
|
|
48
50
|
|
|
49
51
|
interface ITemplateProps {
|
|
50
52
|
type: ItemContainerType;
|
|
53
|
+
scale?: number;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
const Template: Story<IItemContainerProps & ITemplateProps> = ({
|
|
56
|
+
const Template: Story<IItemContainerProps & ITemplateProps> = ({
|
|
57
|
+
type,
|
|
58
|
+
scale,
|
|
59
|
+
}) => {
|
|
54
60
|
const mock = itemContainerMock({ name: type });
|
|
55
61
|
|
|
56
62
|
const [itemContainer, setItemContainer] = useState(mock);
|
|
@@ -59,81 +65,93 @@ const Template: Story<IItemContainerProps & ITemplateProps> = ({ type }) => {
|
|
|
59
65
|
itemContainer: mock,
|
|
60
66
|
});
|
|
61
67
|
|
|
62
|
-
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
const coreItemContainer = (
|
|
69
|
+
<ItemContainer
|
|
70
|
+
itemContainer={itemContainer}
|
|
71
|
+
onClose={() => console.log('closing item container')}
|
|
72
|
+
onMouseOver={onMouseOver}
|
|
73
|
+
onSelected={onSelected}
|
|
74
|
+
onItemClick={onItemClick}
|
|
75
|
+
checkIfItemCanBeMoved={() => allowedToDrop}
|
|
76
|
+
onItemDragEnd={quantity => {
|
|
77
|
+
// THIS IS ONLY LONG-BOW EXAMPLE FOR DRAG AND DROP
|
|
78
|
+
|
|
79
|
+
if (quantity === 0) {
|
|
80
|
+
setItemContainer({ ...itemContainer });
|
|
81
|
+
} else if (allowedToDrop && dropSlot !== -1) {
|
|
82
|
+
const newContainer = { ...itemContainer };
|
|
83
|
+
|
|
84
|
+
if (quantity && dragItem && dragItem.stackQty) {
|
|
85
|
+
newContainer.slots[dropSlot] = {
|
|
86
|
+
...dragItem,
|
|
87
|
+
stackQty: quantity + (dropItem?.stackQty || 0),
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
if (dragItem.stackQty - quantity === 0)
|
|
91
|
+
newContainer.slots[dragSlot] = null;
|
|
92
|
+
else
|
|
93
|
+
newContainer.slots[dragSlot] = {
|
|
81
94
|
...dragItem,
|
|
82
|
-
stackQty:
|
|
95
|
+
stackQty: dragItem.stackQty - quantity,
|
|
83
96
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
else
|
|
88
|
-
newContainer.slots[dragSlot] = {
|
|
89
|
-
...dragItem,
|
|
90
|
-
stackQty: dragItem.stackQty - quantity,
|
|
91
|
-
};
|
|
92
|
-
} else {
|
|
93
|
-
newContainer.slots[dropSlot] = dragItem;
|
|
94
|
-
newContainer.slots[dragSlot] = null;
|
|
95
|
-
}
|
|
96
|
-
setTimeout(() => {
|
|
97
|
-
setItemContainer(newContainer);
|
|
98
|
-
}, 100);
|
|
97
|
+
} else {
|
|
98
|
+
newContainer.slots[dropSlot] = dragItem;
|
|
99
|
+
newContainer.slots[dragSlot] = null;
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
setItemContainer(newContainer);
|
|
103
|
+
}, 100);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
allowedToDrop = false;
|
|
107
|
+
dropSlot = -1;
|
|
108
|
+
dropItem = null;
|
|
109
|
+
dragItem = null;
|
|
110
|
+
}}
|
|
111
|
+
onItemDragStart={(item, slotIndex) => {
|
|
112
|
+
dragItem = item;
|
|
113
|
+
dragSlot = slotIndex;
|
|
114
|
+
}}
|
|
115
|
+
onItemPlaceDrop={(item, slotIndex) => {
|
|
116
|
+
// THIS IS ONLY LONG-BOW EXAMPLE FOR DRAG AND DROP
|
|
117
|
+
|
|
118
|
+
if (!item || (dragItem?.key === item?.key && dragSlot !== slotIndex)) {
|
|
119
|
+
console.log('allow');
|
|
120
|
+
allowedToDrop = true;
|
|
121
|
+
dropSlot = slotIndex;
|
|
122
|
+
dropItem = item ? item : null;
|
|
123
|
+
} else {
|
|
101
124
|
allowedToDrop = false;
|
|
102
125
|
dropSlot = -1;
|
|
103
126
|
dropItem = null;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
setItemShortcut={setItemShortcut}
|
|
133
|
-
removeShortcut={removeShortcut}
|
|
134
|
-
equipmentSet={equipmentSetMock}
|
|
135
|
-
isDepotSystem
|
|
136
|
-
/>
|
|
127
|
+
}
|
|
128
|
+
}}
|
|
129
|
+
onOutsideDrop={(item, pos) => console.log('drop', item, pos)}
|
|
130
|
+
type={type}
|
|
131
|
+
atlasIMG={atlasIMG}
|
|
132
|
+
atlasJSON={atlasJSON}
|
|
133
|
+
shortcuts={shortcuts}
|
|
134
|
+
setItemShortcut={setItemShortcut}
|
|
135
|
+
removeShortcut={removeShortcut}
|
|
136
|
+
equipmentSet={equipmentSetMock}
|
|
137
|
+
isDepotSystem
|
|
138
|
+
scale={scale}
|
|
139
|
+
/>
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<RPGUIRoot>
|
|
144
|
+
{scale ? (
|
|
145
|
+
<ScalableContainer
|
|
146
|
+
scale={scale}
|
|
147
|
+
centralize={false}
|
|
148
|
+
breakPoint={UI_BREAKPOINT_SMALL_LAPTOP}
|
|
149
|
+
>
|
|
150
|
+
{coreItemContainer}
|
|
151
|
+
</ScalableContainer>
|
|
152
|
+
) : (
|
|
153
|
+
coreItemContainer
|
|
154
|
+
)}
|
|
137
155
|
</RPGUIRoot>
|
|
138
156
|
);
|
|
139
157
|
};
|
|
@@ -143,6 +161,12 @@ Inventory.args = {
|
|
|
143
161
|
type: ItemContainerType.Inventory,
|
|
144
162
|
};
|
|
145
163
|
|
|
164
|
+
export const InventoryScaledDown = Template.bind({});
|
|
165
|
+
InventoryScaledDown.args = {
|
|
166
|
+
type: ItemContainerType.Inventory,
|
|
167
|
+
scale: 0.8,
|
|
168
|
+
};
|
|
169
|
+
|
|
146
170
|
export const Depot = Template.bind({});
|
|
147
171
|
Depot.args = {
|
|
148
172
|
type: ItemContainerType.Depot,
|