@rpg-engine/long-bow 0.7.89 → 0.7.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/CraftBook/CraftBook.d.ts +1 -1
- package/dist/components/CraftBook/utils/calculateMaxCraftable.d.ts +2 -0
- package/dist/long-bow.cjs.development.js +50 -6
- 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 +50 -6
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/CraftBook/CraftBook.tsx +55 -4
- 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%)'
|
|
@@ -28628,9 +28648,12 @@ var CraftBook = function CraftBook(_ref) {
|
|
|
28628
28648
|
var _useState3 = React.useState(),
|
|
28629
28649
|
size = _useState3[0],
|
|
28630
28650
|
setSize = _useState3[1];
|
|
28631
|
-
var _useState4 = React.useState(
|
|
28632
|
-
|
|
28633
|
-
|
|
28651
|
+
var _useState4 = React.useState(''),
|
|
28652
|
+
searchTerm = _useState4[0],
|
|
28653
|
+
setSearchTerm = _useState4[1];
|
|
28654
|
+
var _useState5 = React.useState(false),
|
|
28655
|
+
isCraftingDisabled = _useState5[0],
|
|
28656
|
+
setIsCraftingDisabled = _useState5[1];
|
|
28634
28657
|
React.useEffect(function () {
|
|
28635
28658
|
var handleResize = function handleResize() {
|
|
28636
28659
|
if (window.innerWidth < 500 && (size == null ? void 0 : size.width) !== mobilePortrait.width && (!scale || scale < 1)) {
|
|
@@ -28696,6 +28719,11 @@ var CraftBook = function CraftBook(_ref) {
|
|
|
28696
28719
|
}, row);
|
|
28697
28720
|
});
|
|
28698
28721
|
};
|
|
28722
|
+
var filteredCraftableItems = craftablesItems == null ? void 0 : craftablesItems.filter(function (item) {
|
|
28723
|
+
var matchesSearch = item.name.toLowerCase().includes(searchTerm.toLowerCase());
|
|
28724
|
+
var matchesCategory = selectedType === 'Suggested' || item.type === selectedType;
|
|
28725
|
+
return matchesSearch && matchesCategory;
|
|
28726
|
+
});
|
|
28699
28727
|
if (!size) return null;
|
|
28700
28728
|
return React__default.createElement(DraggableContainer, {
|
|
28701
28729
|
type: exports.RPGUIContainerTypes.Framed,
|
|
@@ -28712,13 +28740,21 @@ var CraftBook = function CraftBook(_ref) {
|
|
|
28712
28740
|
style: {
|
|
28713
28741
|
width: '100%'
|
|
28714
28742
|
}
|
|
28715
|
-
}, React__default.createElement(Title$2, null, "Craftbook"), React__default.createElement(Subtitle, null, "Select an item to craft"), React__default.createElement("
|
|
28743
|
+
}, React__default.createElement(Title$2, null, "Craftbook"), React__default.createElement(Subtitle, null, "Select an item to craft"), React__default.createElement(SearchContainer$1, null, React__default.createElement("input", {
|
|
28744
|
+
type: "text",
|
|
28745
|
+
className: "rpgui-input",
|
|
28746
|
+
placeholder: "Search items...",
|
|
28747
|
+
value: searchTerm,
|
|
28748
|
+
onChange: function onChange(e) {
|
|
28749
|
+
return setSearchTerm(e.target.value);
|
|
28750
|
+
}
|
|
28751
|
+
})), React__default.createElement("hr", {
|
|
28716
28752
|
className: "golden"
|
|
28717
28753
|
})), React__default.createElement(ContentContainer, null, React__default.createElement(ItemTypes, {
|
|
28718
28754
|
className: "inputRadioCraftBook"
|
|
28719
28755
|
}, renderItemTypes()), React__default.createElement(RadioInputScroller, {
|
|
28720
28756
|
className: "inputRadioCraftBook"
|
|
28721
|
-
},
|
|
28757
|
+
}, filteredCraftableItems == null ? void 0 : filteredCraftableItems.map(function (item) {
|
|
28722
28758
|
return React__default.createElement(CraftingRecipe, {
|
|
28723
28759
|
key: item.key,
|
|
28724
28760
|
atlasIMG: atlasIMG,
|
|
@@ -28739,7 +28775,11 @@ var CraftBook = function CraftBook(_ref) {
|
|
|
28739
28775
|
buttonType: exports.ButtonTypes.RPGUIButton,
|
|
28740
28776
|
onPointerDown: function onPointerDown() {
|
|
28741
28777
|
if (!craftItemKey || isCraftingDisabled) return;
|
|
28742
|
-
|
|
28778
|
+
var selectedItem = craftablesItems.find(function (item) {
|
|
28779
|
+
return item.key === craftItemKey;
|
|
28780
|
+
});
|
|
28781
|
+
var maxCraftable = calculateMaxCraftable(selectedItem, inventory);
|
|
28782
|
+
onCraftItem(craftItemKey, maxCraftable);
|
|
28743
28783
|
setIsCraftingDisabled(true);
|
|
28744
28784
|
setTimeout(function () {
|
|
28745
28785
|
setIsCraftingDisabled(false);
|
|
@@ -28775,6 +28815,10 @@ var ItemTypes = /*#__PURE__*/styled__default.div.withConfig({
|
|
|
28775
28815
|
displayName: "CraftBook__ItemTypes",
|
|
28776
28816
|
componentId: "sc-19q95ue-6"
|
|
28777
28817
|
})(["display:flex;overflow-y:scroll;overflow-x:hidden;width:max-content;flex-direction:column;padding-right:5px;@media (max-width:", "){overflow-x:scroll;overflow-y:hidden;padding-right:0;width:100%;}"], mobilePortrait.width);
|
|
28818
|
+
var SearchContainer$1 = /*#__PURE__*/styled__default.div.withConfig({
|
|
28819
|
+
displayName: "CraftBook__SearchContainer",
|
|
28820
|
+
componentId: "sc-19q95ue-7"
|
|
28821
|
+
})(["margin:8px 0;padding:0 16px;input{width:100%;font-size:0.8rem;padding:8px 12px;background-color:rgba(0,0,0,0.3);border:none;color:white;border-radius:4px;&::placeholder{color:rgba(255,255,255,0.5);}&:focus{outline:none;background-color:rgba(0,0,0,0.4);}}"]);
|
|
28778
28822
|
|
|
28779
28823
|
var Dropdown = function Dropdown(_ref) {
|
|
28780
28824
|
var options = _ref.options,
|