@rpg-engine/long-bow 0.2.89 → 0.2.91
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/Equipment/EquipmentSet.d.ts +2 -0
- package/dist/components/Item/Inventory/ItemContainer.d.ts +2 -0
- package/dist/components/Item/Inventory/ItemSlot.d.ts +2 -0
- package/dist/long-bow.cjs.development.js +35 -8
- 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 +35 -8
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Equipment/EquipmentSet.tsx +6 -0
- package/src/components/Item/Inventory/ItemContainer.tsx +6 -0
- package/src/components/Item/Inventory/ItemSlot.tsx +28 -6
- package/src/stories/EquipmentSet.stories.tsx +6 -0
- package/src/stories/ItemContainer.stories.tsx +1 -0
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '@rpg-engine/shared';
|
|
9
9
|
import React from 'react';
|
|
10
10
|
import styled from 'styled-components';
|
|
11
|
+
import { IPosition } from '../../types/eventTypes';
|
|
11
12
|
import { DraggableContainer } from '../DraggableContainer';
|
|
12
13
|
import { ItemSlot } from '../Item/Inventory/ItemSlot';
|
|
13
14
|
import { RPGUIContainerTypes } from '../RPGUIContainer';
|
|
@@ -31,6 +32,7 @@ export interface IEquipmentSetProps {
|
|
|
31
32
|
slotIndex: number,
|
|
32
33
|
itemContainerType: ItemContainerType | null
|
|
33
34
|
) => void;
|
|
35
|
+
onItemOutsideDrop?: (item: IItem, position: IPosition) => void;
|
|
34
36
|
checkIfItemCanBeMoved: () => boolean;
|
|
35
37
|
onMouseOver?: (e: any, slotIndex: number, item: IItem | null) => void;
|
|
36
38
|
onSelected?: (optionId: string) => void;
|
|
@@ -51,6 +53,7 @@ export const EquipmentSet: React.FC<IEquipmentSetProps> = ({
|
|
|
51
53
|
onItemDragEnd,
|
|
52
54
|
onItemDragStart,
|
|
53
55
|
onItemPlaceDrop,
|
|
56
|
+
onItemOutsideDrop,
|
|
54
57
|
checkIfItemCanBeMoved,
|
|
55
58
|
}) => {
|
|
56
59
|
const {
|
|
@@ -134,6 +137,9 @@ export const EquipmentSet: React.FC<IEquipmentSetProps> = ({
|
|
|
134
137
|
if (onItemPlaceDrop)
|
|
135
138
|
onItemPlaceDrop(item, slotIndex, itemContainerType);
|
|
136
139
|
}}
|
|
140
|
+
onOutsideDrop={(item, position) => {
|
|
141
|
+
if (onItemOutsideDrop) onItemOutsideDrop(item, position);
|
|
142
|
+
}}
|
|
137
143
|
atlasIMG={atlasIMG}
|
|
138
144
|
atlasJSON={atlasJSON}
|
|
139
145
|
/>
|
|
@@ -4,6 +4,7 @@ import styled from 'styled-components';
|
|
|
4
4
|
import { SlotsContainer } from '../../Abstractions/SlotsContainer';
|
|
5
5
|
import { ItemQuantitySelector } from './ItemQuantitySelector';
|
|
6
6
|
|
|
7
|
+
import { IPosition } from '../../../types/eventTypes';
|
|
7
8
|
import { ItemSlot } from './ItemSlot';
|
|
8
9
|
|
|
9
10
|
export interface IItemContainerProps {
|
|
@@ -20,6 +21,7 @@ export interface IItemContainerProps {
|
|
|
20
21
|
itemContainerType: ItemContainerType | null
|
|
21
22
|
) => void;
|
|
22
23
|
onItemDragEnd?: (quantity?: number) => void;
|
|
24
|
+
onOutsideDrop?: (item: IItem, position: IPosition) => void;
|
|
23
25
|
onItemPlaceDrop?: (
|
|
24
26
|
item: IItem | null,
|
|
25
27
|
slotIndex: number,
|
|
@@ -48,6 +50,7 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
|
|
|
48
50
|
onItemDragEnd,
|
|
49
51
|
onItemDragStart,
|
|
50
52
|
onItemPlaceDrop,
|
|
53
|
+
onOutsideDrop,
|
|
51
54
|
checkIfItemCanBeMoved,
|
|
52
55
|
initialPosition,
|
|
53
56
|
}) => {
|
|
@@ -96,6 +99,9 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
|
|
|
96
99
|
if (onItemPlaceDrop)
|
|
97
100
|
onItemPlaceDrop(item, slotIndex, itemContainerType);
|
|
98
101
|
}}
|
|
102
|
+
onOutsideDrop={(item, position) => {
|
|
103
|
+
if (onOutsideDrop) onOutsideDrop(item, position);
|
|
104
|
+
}}
|
|
99
105
|
atlasIMG={atlasIMG}
|
|
100
106
|
atlasJSON={atlasJSON}
|
|
101
107
|
/>
|
|
@@ -13,6 +13,7 @@ import Draggable from 'react-draggable';
|
|
|
13
13
|
import styled from 'styled-components';
|
|
14
14
|
import { v4 as uuidv4 } from 'uuid';
|
|
15
15
|
import { uiFonts } from '../../../constants/uiFonts';
|
|
16
|
+
import { IPosition } from '../../../types/eventTypes';
|
|
16
17
|
import { RelativeListMenu } from '../../RelativeListMenu';
|
|
17
18
|
import { Ellipsis } from '../../shared/Ellipsis';
|
|
18
19
|
import { SpriteFromAtlas } from '../../shared/SpriteFromAtlas';
|
|
@@ -59,6 +60,7 @@ interface IProps {
|
|
|
59
60
|
itemContainerType: ItemContainerType | null
|
|
60
61
|
) => void;
|
|
61
62
|
onDragEnd: (quantity?: number) => void;
|
|
63
|
+
onOutsideDrop?: (item: IItem, position: IPosition) => void;
|
|
62
64
|
checkIfItemCanBeMoved: () => boolean;
|
|
63
65
|
openQuantitySelector?: (maxQuantity: number, callback: () => void) => void;
|
|
64
66
|
onPlaceDrop: (
|
|
@@ -87,6 +89,7 @@ export const ItemSlot: React.FC<IProps> = observer(
|
|
|
87
89
|
onDragEnd,
|
|
88
90
|
onDragStart,
|
|
89
91
|
onPlaceDrop,
|
|
92
|
+
onOutsideDrop: onDrop,
|
|
90
93
|
checkIfItemCanBeMoved,
|
|
91
94
|
openQuantitySelector,
|
|
92
95
|
}) => {
|
|
@@ -96,7 +99,8 @@ export const ItemSlot: React.FC<IProps> = observer(
|
|
|
96
99
|
|
|
97
100
|
const [isFocused, setIsFocused] = useState(false);
|
|
98
101
|
const [wasDragged, setWasDragged] = useState(false);
|
|
99
|
-
const [dragPosition, setDragPosition] = useState({ x: 0, y: 0 });
|
|
102
|
+
const [dragPosition, setDragPosition] = useState<IPosition>({ x: 0, y: 0 });
|
|
103
|
+
const [dropPosition, setDropPosition] = useState<IPosition | null>(null);
|
|
100
104
|
const dragContainer = useRef<HTMLDivElement>(null);
|
|
101
105
|
|
|
102
106
|
const [contextActions, setContextActions] = useState<IContextMenuItem[]>(
|
|
@@ -111,6 +115,12 @@ export const ItemSlot: React.FC<IProps> = observer(
|
|
|
111
115
|
}
|
|
112
116
|
}, [item]);
|
|
113
117
|
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (onDrop && item && dropPosition) {
|
|
120
|
+
onDrop(item, dropPosition);
|
|
121
|
+
}
|
|
122
|
+
}, [dropPosition]);
|
|
123
|
+
|
|
114
124
|
const getStackInfo = (itemId: string, stackQty: number) => {
|
|
115
125
|
// if (itemToRender?.isStackable && itemToRender?.stackQty) {
|
|
116
126
|
|
|
@@ -269,12 +279,24 @@ export const ItemSlot: React.FC<IProps> = observer(
|
|
|
269
279
|
>
|
|
270
280
|
<Draggable
|
|
271
281
|
defaultClassName={item ? 'draggable' : 'empty-slot'}
|
|
272
|
-
onStop={() => {
|
|
273
|
-
if (
|
|
274
|
-
|
|
275
|
-
|
|
282
|
+
onStop={(e, data) => {
|
|
283
|
+
if (wasDragged && item) {
|
|
284
|
+
//@ts-ignore
|
|
285
|
+
const classes: string[] = Array.from(e.target?.classList);
|
|
286
|
+
|
|
287
|
+
const isOutsideDrop = classes.some(elm => {
|
|
288
|
+
//elm matches ItemContainer string
|
|
289
|
+
|
|
290
|
+
return elm.includes('rpgui-content');
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
if (isOutsideDrop) {
|
|
294
|
+
setDropPosition({
|
|
295
|
+
x: data.x,
|
|
296
|
+
y: data.y,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
276
299
|
|
|
277
|
-
if (wasDragged) {
|
|
278
300
|
setWasDragged(false);
|
|
279
301
|
|
|
280
302
|
const target = dragContainer.current;
|
|
@@ -9,6 +9,7 @@ import { RPGUIRoot } from '../../src/components/RPGUIRoot';
|
|
|
9
9
|
import { equipmentSetMock } from '../../src/mocks/equipmentSet.mocks';
|
|
10
10
|
import atlasJSON from '../mocks/atlas/items/items.json';
|
|
11
11
|
import atlasIMG from '../mocks/atlas/items/items.png';
|
|
12
|
+
import { IPosition } from '../types/eventTypes';
|
|
12
13
|
|
|
13
14
|
const meta: Meta = {
|
|
14
15
|
title: 'Equipment Set',
|
|
@@ -36,6 +37,10 @@ const onSelected = (payload: string) => {
|
|
|
36
37
|
console.log('dispatch', payload);
|
|
37
38
|
};
|
|
38
39
|
|
|
40
|
+
const onItemOutsideDrop = (item: IItem, position: IPosition) => {
|
|
41
|
+
console.log('dropped outside', item, position);
|
|
42
|
+
};
|
|
43
|
+
|
|
39
44
|
const Template: Story<IEquipmentSetProps> = args => (
|
|
40
45
|
<RPGUIRoot>
|
|
41
46
|
<EquipmentSet
|
|
@@ -52,6 +57,7 @@ const Template: Story<IEquipmentSetProps> = args => (
|
|
|
52
57
|
type={ItemContainerType.Equipment}
|
|
53
58
|
atlasIMG={atlasIMG}
|
|
54
59
|
atlasJSON={atlasJSON}
|
|
60
|
+
onItemOutsideDrop={onItemOutsideDrop}
|
|
55
61
|
/>
|
|
56
62
|
</RPGUIRoot>
|
|
57
63
|
);
|