@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.
@@ -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;
@@ -0,0 +1,2 @@
1
+ import { ICraftableItem, IItemContainer } from '@rpg-engine/shared';
2
+ export declare function calculateMaxCraftable(recipe: ICraftableItem | undefined, inventory: IItemContainer | null | undefined): number;
@@ -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
- onCraftItem(craftItemKey);
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);