@rpg-engine/long-bow 0.2.85 → 0.2.87
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/DraggableContainer.d.ts +1 -0
- package/dist/components/Equipment/EquipmentSet.d.ts +4 -0
- package/dist/components/Input.d.ts +1 -0
- package/dist/components/Item/Inventory/ItemContainer.d.ts +8 -0
- package/dist/components/Item/Inventory/ItemQuantitySelector.d.ts +7 -0
- package/dist/components/Item/Inventory/ItemSlot.d.ts +5 -0
- package/dist/components/RangeSlider.d.ts +1 -0
- package/dist/long-bow.cjs.development.js +361 -75
- 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 +362 -76
- package/dist/long-bow.esm.js.map +1 -1
- package/dist/stories/ItemQuantitySelector.stories.d.ts +5 -0
- package/package.json +1 -1
- package/src/components/Abstractions/SlotsContainer.tsx +3 -0
- package/src/components/DraggableContainer.tsx +3 -0
- package/src/components/Equipment/EquipmentSet.tsx +30 -0
- package/src/components/Input.tsx +6 -2
- package/src/components/Item/Inventory/ItemContainer.tsx +92 -6
- package/src/components/Item/Inventory/ItemQuantitySelector.tsx +137 -0
- package/src/components/Item/Inventory/ItemSlot.tsx +144 -25
- package/src/components/RangeSlider.tsx +37 -14
- package/src/mocks/itemContainer.mocks.ts +1 -1
- package/src/stories/EquipmentSet.stories.tsx +4 -0
- package/src/stories/ItemContainer.stories.tsx +82 -15
- package/src/stories/ItemQuantitySelector.stories.tsx +26 -0
- package/src/stories/RangeSlider.stories.tsx +10 -9
- package/src/.DS_Store +0 -0
- package/src/components/NPCDialog/.DS_Store +0 -0
- package/src/components/NPCDialog/img/.DS_Store +0 -0
- package/src/mocks/.DS_Store +0 -0
- package/src/mocks/atlas/.DS_Store +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
-
import { _RPGUI } from './RPGUIRoot';
|
|
5
4
|
|
|
6
5
|
export enum RangeSliderType {
|
|
7
6
|
Slider = 'rpgui-slider',
|
|
@@ -14,6 +13,7 @@ export interface IRangeSliderProps {
|
|
|
14
13
|
valueMax: number;
|
|
15
14
|
width: string;
|
|
16
15
|
onChange: (value: number) => void;
|
|
16
|
+
value: number;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export const RangeSlider: React.FC<IRangeSliderProps> = ({
|
|
@@ -22,29 +22,46 @@ export const RangeSlider: React.FC<IRangeSliderProps> = ({
|
|
|
22
22
|
valueMax,
|
|
23
23
|
width,
|
|
24
24
|
onChange,
|
|
25
|
+
value,
|
|
25
26
|
}) => {
|
|
26
27
|
const sliderId = uuidv4();
|
|
27
28
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const value = _RPGUI.get_value(rpguiSlider);
|
|
29
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
30
|
+
const [left, setLeft] = useState(0);
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const calculatedWidth = containerRef.current?.clientWidth || 0;
|
|
34
|
+
setLeft(
|
|
35
|
+
Math.max(
|
|
36
|
+
((value - valueMin) / (valueMax - valueMin)) * (calculatedWidth - 35) +
|
|
37
|
+
10
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
}, [value, valueMin, valueMax]);
|
|
41
|
+
|
|
42
|
+
const typeClass = type === RangeSliderType.GoldSlider ? 'golden' : '';
|
|
34
43
|
|
|
35
44
|
return (
|
|
36
|
-
<div
|
|
45
|
+
<div
|
|
46
|
+
style={{ width: width, position: 'relative' }}
|
|
47
|
+
className={`rpgui-slider-container ${typeClass}`}
|
|
48
|
+
id={`rpgui-slider-${sliderId}`}
|
|
49
|
+
ref={containerRef}
|
|
50
|
+
>
|
|
51
|
+
<div style={{ pointerEvents: 'none' }}>
|
|
52
|
+
<div className={`rpgui-slider-track ${typeClass}`} />
|
|
53
|
+
<div className={`rpgui-slider-left-edge ${typeClass}`} />
|
|
54
|
+
<div className={`rpgui-slider-right-edge ${typeClass}`} />
|
|
55
|
+
<div className={`rpgui-slider-thumb ${typeClass}`} style={{ left }} />
|
|
56
|
+
</div>
|
|
37
57
|
<Input
|
|
38
|
-
className={
|
|
39
|
-
type === RangeSliderType.Slider
|
|
40
|
-
? RangeSliderType.Slider
|
|
41
|
-
: RangeSliderType.GoldSlider
|
|
42
|
-
}
|
|
43
58
|
type="range"
|
|
44
59
|
style={{ width: width }}
|
|
45
60
|
min={valueMin}
|
|
46
61
|
max={valueMax}
|
|
47
|
-
|
|
62
|
+
onChange={e => onChange(Number(e.target.value))}
|
|
63
|
+
value={value}
|
|
64
|
+
className="rpgui-cursor-point"
|
|
48
65
|
/>
|
|
49
66
|
</div>
|
|
50
67
|
);
|
|
@@ -52,4 +69,10 @@ export const RangeSlider: React.FC<IRangeSliderProps> = ({
|
|
|
52
69
|
|
|
53
70
|
const Input = styled.input`
|
|
54
71
|
opacity: 0;
|
|
72
|
+
position: absolute;
|
|
73
|
+
width: 100%;
|
|
74
|
+
height: 100%;
|
|
75
|
+
top: 0;
|
|
76
|
+
left: 0;
|
|
77
|
+
margin-top: -5px;
|
|
55
78
|
`;
|
|
@@ -45,6 +45,10 @@ const Template: Story<IEquipmentSetProps> = args => (
|
|
|
45
45
|
onMouseOver={onMouseOver}
|
|
46
46
|
onSelected={onSelected}
|
|
47
47
|
onItemClick={onItemClick}
|
|
48
|
+
onItemDragEnd={_quantity => {}}
|
|
49
|
+
onItemDragStart={item => console.log('drag start: ', item._id)}
|
|
50
|
+
onItemPlaceDrop={item => console.log('dropped to: ', item?._id)}
|
|
51
|
+
checkIfItemCanBeMoved={() => false}
|
|
48
52
|
type={ItemContainerType.Equipment}
|
|
49
53
|
atlasIMG={atlasIMG}
|
|
50
54
|
atlasJSON={atlasJSON}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IItem, ItemContainerType, ItemType } from '@rpg-engine/shared';
|
|
2
2
|
import { Meta, Story } from '@storybook/react';
|
|
3
|
-
import React from 'react';
|
|
3
|
+
import React, { useState } from 'react';
|
|
4
4
|
import {
|
|
5
5
|
IItemContainerProps,
|
|
6
6
|
ItemContainer,
|
|
@@ -37,19 +37,86 @@ const onItemClick = (
|
|
|
37
37
|
console.log(item, ItemType, itemContainerType, 'was clicked!');
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
// THIS IS ONLY LONG-BOW EXAMPLE FOR DRAG AND DROP
|
|
41
|
+
let dragItem: IItem | null = null;
|
|
42
|
+
let dropItem: IItem | null = null;
|
|
43
|
+
let allowedToDrop = false;
|
|
44
|
+
let dragSlot = -1;
|
|
45
|
+
let dropSlot = -1;
|
|
46
|
+
|
|
47
|
+
const Template: Story<IItemContainerProps> = () => {
|
|
48
|
+
const [itemContainer, setItemContainer] = useState(itemContainerMock);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<RPGUIRoot>
|
|
52
|
+
<ItemContainer
|
|
53
|
+
itemContainer={itemContainer}
|
|
54
|
+
onClose={() => console.log('closing item container')}
|
|
55
|
+
onMouseOver={onMouseOver}
|
|
56
|
+
onSelected={onSelected}
|
|
57
|
+
onItemClick={onItemClick}
|
|
58
|
+
checkIfItemCanBeMoved={() => allowedToDrop}
|
|
59
|
+
onItemDragEnd={quantity => {
|
|
60
|
+
// THIS IS ONLY LONG-BOW EXAMPLE FOR DRAG AND DROP
|
|
61
|
+
|
|
62
|
+
if (quantity === 0) {
|
|
63
|
+
setItemContainer({ ...itemContainer });
|
|
64
|
+
} else if (allowedToDrop && dropSlot !== -1) {
|
|
65
|
+
const newContainer = { ...itemContainer };
|
|
66
|
+
|
|
67
|
+
if (quantity && dragItem && dragItem.stackQty) {
|
|
68
|
+
newContainer.slots[dropSlot] = {
|
|
69
|
+
...dragItem,
|
|
70
|
+
stackQty: quantity + (dropItem?.stackQty || 0),
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
if (dragItem.stackQty - quantity === 0)
|
|
74
|
+
newContainer.slots[dragSlot] = null;
|
|
75
|
+
else
|
|
76
|
+
newContainer.slots[dragSlot] = {
|
|
77
|
+
...dragItem,
|
|
78
|
+
stackQty: dragItem.stackQty - quantity,
|
|
79
|
+
};
|
|
80
|
+
} else {
|
|
81
|
+
newContainer.slots[dropSlot] = dragItem;
|
|
82
|
+
newContainer.slots[dragSlot] = null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setItemContainer(newContainer);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
allowedToDrop = false;
|
|
89
|
+
dropSlot = -1;
|
|
90
|
+
dropItem = null;
|
|
91
|
+
dragItem = null;
|
|
92
|
+
}}
|
|
93
|
+
onItemDragStart={(item, slotIndex) => {
|
|
94
|
+
dragItem = item;
|
|
95
|
+
dragSlot = slotIndex;
|
|
96
|
+
}}
|
|
97
|
+
onItemPlaceDrop={(item, slotIndex) => {
|
|
98
|
+
// THIS IS ONLY LONG-BOW EXAMPLE FOR DRAG AND DROP
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
!item ||
|
|
102
|
+
(dragItem?.key === item?.key && dragSlot !== slotIndex)
|
|
103
|
+
) {
|
|
104
|
+
console.log('allow');
|
|
105
|
+
allowedToDrop = true;
|
|
106
|
+
dropSlot = slotIndex;
|
|
107
|
+
dropItem = item ? item : null;
|
|
108
|
+
} else {
|
|
109
|
+
allowedToDrop = false;
|
|
110
|
+
dropSlot = -1;
|
|
111
|
+
dropItem = null;
|
|
112
|
+
}
|
|
113
|
+
}}
|
|
114
|
+
type={ItemContainerType.Inventory}
|
|
115
|
+
atlasIMG={atlasIMG}
|
|
116
|
+
atlasJSON={atlasJSON}
|
|
117
|
+
/>
|
|
118
|
+
</RPGUIRoot>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
54
121
|
|
|
55
122
|
export const Default = Template.bind({});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Meta, Story } from '@storybook/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { RPGUIRoot } from '..';
|
|
4
|
+
import {
|
|
5
|
+
IItemQuantitySelectorProps,
|
|
6
|
+
ItemQuantitySelector,
|
|
7
|
+
} from '../components/Item/Inventory/ItemQuantitySelector';
|
|
8
|
+
|
|
9
|
+
const meta: Meta = {
|
|
10
|
+
title: 'Item Quantity Selector',
|
|
11
|
+
component: ItemQuantitySelector,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
|
|
16
|
+
const Template: Story<IItemQuantitySelectorProps> = args => (
|
|
17
|
+
<RPGUIRoot>
|
|
18
|
+
<ItemQuantitySelector {...args} />
|
|
19
|
+
</RPGUIRoot>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const Default = Template.bind({});
|
|
23
|
+
|
|
24
|
+
Default.args = {
|
|
25
|
+
quantity: 10,
|
|
26
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Meta, Story } from '@storybook/react';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
3
|
import {
|
|
4
4
|
IRangeSliderProps,
|
|
5
5
|
RangeSlider,
|
|
@@ -43,11 +43,15 @@ const meta: Meta = {
|
|
|
43
43
|
|
|
44
44
|
export default meta;
|
|
45
45
|
|
|
46
|
-
const Template: Story<IRangeSliderProps> = args =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
const Template: Story<IRangeSliderProps> = args => {
|
|
47
|
+
const [value, setValue] = useState(50);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<RPGUIRoot>
|
|
51
|
+
<RangeSlider {...args} value={value} onChange={setValue} />
|
|
52
|
+
</RPGUIRoot>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
51
55
|
|
|
52
56
|
// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test
|
|
53
57
|
// https://storybook.js.org/docs/react/workflows/unit-testing
|
|
@@ -57,7 +61,4 @@ Default.args = {
|
|
|
57
61
|
type: RangeSliderType.Slider,
|
|
58
62
|
valueMin: 0,
|
|
59
63
|
valueMax: 100,
|
|
60
|
-
onChange: n => {
|
|
61
|
-
console.log('onChange', n);
|
|
62
|
-
},
|
|
63
64
|
};
|
package/src/.DS_Store
DELETED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/mocks/.DS_Store
DELETED
|
Binary file
|
|
Binary file
|