@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
|
@@ -5,7 +5,7 @@ export interface IItemCraftSelectorProps {
|
|
|
5
5
|
atlasIMG: any;
|
|
6
6
|
onClose: () => void;
|
|
7
7
|
onSelect: (value: string) => void;
|
|
8
|
-
onCraftItem: (value: string | undefined) => void;
|
|
8
|
+
onCraftItem: (value: string | undefined, maxCraftable: number) => void;
|
|
9
9
|
craftablesItems: ICraftableItem[];
|
|
10
10
|
equipmentSet?: IEquipmentSet | null;
|
|
11
11
|
inventory?: IItemContainer | null;
|
|
@@ -28595,6 +28595,26 @@ var MinCraftingRequirementsText = /*#__PURE__*/styled__default.p.withConfig({
|
|
|
28595
28595
|
return levelIsOk ? uiColors.lightGreen : uiColors.lightGray;
|
|
28596
28596
|
});
|
|
28597
28597
|
|
|
28598
|
+
function calculateMaxCraftable(recipe, inventory) {
|
|
28599
|
+
if (!inventory || !(recipe != null && recipe.ingredients)) {
|
|
28600
|
+
return 0;
|
|
28601
|
+
}
|
|
28602
|
+
return recipe.ingredients.reduce(function (maxPossible, ingredient) {
|
|
28603
|
+
var _inventoryItem$stackQ;
|
|
28604
|
+
var inventoryItem = Object.values(inventory.slots).find(function (item) {
|
|
28605
|
+
return (item == null ? void 0 : item.key) === ingredient.key;
|
|
28606
|
+
});
|
|
28607
|
+
if (!inventoryItem) {
|
|
28608
|
+
return 0;
|
|
28609
|
+
}
|
|
28610
|
+
var possibleWithThisIngredient = Math.floor((_inventoryItem$stackQ = inventoryItem.stackQty) != null ? _inventoryItem$stackQ : 0 / ingredient.qty);
|
|
28611
|
+
if (maxPossible === -1) {
|
|
28612
|
+
return possibleWithThisIngredient;
|
|
28613
|
+
}
|
|
28614
|
+
return Math.min(maxPossible, possibleWithThisIngredient);
|
|
28615
|
+
}, -1);
|
|
28616
|
+
}
|
|
28617
|
+
|
|
28598
28618
|
var desktop = {
|
|
28599
28619
|
width: 'min(900px, 80%)',
|
|
28600
28620
|
height: 'min(700px, 80%)'
|
|
@@ -28739,7 +28759,11 @@ var CraftBook = function CraftBook(_ref) {
|
|
|
28739
28759
|
buttonType: exports.ButtonTypes.RPGUIButton,
|
|
28740
28760
|
onPointerDown: function onPointerDown() {
|
|
28741
28761
|
if (!craftItemKey || isCraftingDisabled) return;
|
|
28742
|
-
|
|
28762
|
+
var selectedItem = craftablesItems.find(function (item) {
|
|
28763
|
+
return item.key === craftItemKey;
|
|
28764
|
+
});
|
|
28765
|
+
var maxCraftable = calculateMaxCraftable(selectedItem, inventory);
|
|
28766
|
+
onCraftItem(craftItemKey, maxCraftable);
|
|
28743
28767
|
setIsCraftingDisabled(true);
|
|
28744
28768
|
setTimeout(function () {
|
|
28745
28769
|
setIsCraftingDisabled(false);
|