@rpg-engine/long-bow 0.7.88 → 0.7.90
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/CraftBook/CraftBook.d.ts +1 -1
- package/dist/components/CraftBook/utils/calculateMaxCraftable.d.ts +2 -0
- package/dist/long-bow.cjs.development.js +25 -1
- 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 +25 -1
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/CraftBook/CraftBook.tsx +11 -2
- package/src/components/CraftBook/utils/calculateMaxCraftable.ts +30 -0
- package/src/stories/Features/craftbook/CraftBook.stories.tsx +6 -5
package/package.json
CHANGED
|
@@ -13,13 +13,14 @@ import { DraggableContainer } from '../DraggableContainer';
|
|
|
13
13
|
import { InputRadio } from '../InputRadio';
|
|
14
14
|
import { RPGUIContainerTypes } from '../RPGUI/RPGUIContainer';
|
|
15
15
|
import { CraftingRecipe } from './CraftingRecipe';
|
|
16
|
+
import { calculateMaxCraftable } from './utils/calculateMaxCraftable';
|
|
16
17
|
|
|
17
18
|
export interface IItemCraftSelectorProps {
|
|
18
19
|
atlasJSON: any;
|
|
19
20
|
atlasIMG: any;
|
|
20
21
|
onClose: () => void;
|
|
21
22
|
onSelect: (value: string) => void;
|
|
22
|
-
onCraftItem: (value: string | undefined) => void;
|
|
23
|
+
onCraftItem: (value: string | undefined, maxCraftable: number) => void;
|
|
23
24
|
craftablesItems: ICraftableItem[];
|
|
24
25
|
equipmentSet?: IEquipmentSet | null;
|
|
25
26
|
inventory?: IItemContainer | null;
|
|
@@ -203,7 +204,15 @@ export const CraftBook: React.FC<IItemCraftSelectorProps> = ({
|
|
|
203
204
|
onPointerDown={() => {
|
|
204
205
|
if (!craftItemKey || isCraftingDisabled) return;
|
|
205
206
|
|
|
206
|
-
|
|
207
|
+
const selectedItem = craftablesItems.find(
|
|
208
|
+
item => item.key === craftItemKey
|
|
209
|
+
);
|
|
210
|
+
const maxCraftable = calculateMaxCraftable(
|
|
211
|
+
selectedItem,
|
|
212
|
+
inventory
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
onCraftItem(craftItemKey, maxCraftable);
|
|
207
216
|
setIsCraftingDisabled(true);
|
|
208
217
|
|
|
209
218
|
setTimeout(() => {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ICraftableItem, IItem, IItemContainer } from '@rpg-engine/shared';
|
|
2
|
+
|
|
3
|
+
export function calculateMaxCraftable(
|
|
4
|
+
recipe: ICraftableItem | undefined,
|
|
5
|
+
inventory: IItemContainer | null | undefined
|
|
6
|
+
): number {
|
|
7
|
+
if (!inventory || !recipe?.ingredients) {
|
|
8
|
+
return 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return recipe.ingredients.reduce((maxPossible, ingredient) => {
|
|
12
|
+
const inventoryItem = Object.values(inventory.slots).find(
|
|
13
|
+
(item): item is IItem => item?.key === ingredient.key
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
if (!inventoryItem) {
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const possibleWithThisIngredient = Math.floor(
|
|
21
|
+
inventoryItem.stackQty ?? 0 / ingredient.qty
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
if (maxPossible === -1) {
|
|
25
|
+
return possibleWithThisIngredient;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return Math.min(maxPossible, possibleWithThisIngredient);
|
|
29
|
+
}, -1);
|
|
30
|
+
}
|
|
@@ -22,7 +22,12 @@ const Template: Story = args => (
|
|
|
22
22
|
onSelect={onSelect}
|
|
23
23
|
onClose={() => console.log('closing Equipment Set Container')}
|
|
24
24
|
craftablesItems={craftableItems}
|
|
25
|
-
onCraftItem={
|
|
25
|
+
onCraftItem={(value, maxCraftable) => {
|
|
26
|
+
console.log('Crafting:', {
|
|
27
|
+
itemKey: value,
|
|
28
|
+
maxCraftable: maxCraftable,
|
|
29
|
+
});
|
|
30
|
+
}}
|
|
26
31
|
equipmentSet={equipmentSetMock}
|
|
27
32
|
{...args}
|
|
28
33
|
/>
|
|
@@ -31,10 +36,6 @@ const Template: Story = args => (
|
|
|
31
36
|
|
|
32
37
|
export const Default = Template.bind({});
|
|
33
38
|
|
|
34
|
-
const onCraftItem = (value: string | undefined) => {
|
|
35
|
-
console.log('Craft', value);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
39
|
const onSelect = (value: string) => {
|
|
39
40
|
console.log('Story package', value);
|
|
40
41
|
};
|