@rpg-engine/long-bow 0.7.94 → 0.7.96

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.7.94",
3
+ "version": "0.7.96",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -20,8 +20,12 @@ import { DraggableContainer } from '../DraggableContainer';
20
20
  import { Dropdown, IOptionsProps } from '../Dropdown';
21
21
  import { RPGUIContainerTypes } from '../RPGUI/RPGUIContainer';
22
22
  import { CraftingRecipe } from './CraftingRecipe';
23
+ import { useResponsiveSize } from './hooks/useResponsiveSize';
23
24
  import { calculateMaxCraftable } from './utils/calculateMaxCraftable';
24
25
 
26
+ const MOBILE_WIDTH = '500px';
27
+ const ITEMS_PER_PAGE = 8;
28
+
25
29
  export interface IItemCraftSelectorProps {
26
30
  atlasJSON: any;
27
31
  atlasIMG: any;
@@ -41,23 +45,6 @@ export interface ShowMessage {
41
45
  index: number;
42
46
  }
43
47
 
44
- const desktop = {
45
- width: 'min(900px, 80%)',
46
- height: 'min(700px, 80%)',
47
- };
48
-
49
- const mobileLanscape = {
50
- width: '800px',
51
- height: '500px',
52
- };
53
-
54
- const mobilePortrait = {
55
- width: '500px',
56
- height: '700px',
57
- };
58
-
59
- const ITEMS_PER_PAGE = 8;
60
-
61
48
  export const CraftBook: React.FC<IItemCraftSelectorProps> = ({
62
49
  atlasIMG,
63
50
  atlasJSON,
@@ -75,7 +62,7 @@ export const CraftBook: React.FC<IItemCraftSelectorProps> = ({
75
62
  const [selectedType, setSelectedType] = useState<string>(
76
63
  savedSelectedType ?? Object.keys(ItemSubType)[0]
77
64
  );
78
- const [size, setSize] = useState<{ width: string; height: string }>();
65
+ const size = useResponsiveSize(scale);
79
66
  const [searchTerm, setSearchTerm] = useState('');
80
67
  const [isSearchVisible, setIsSearchVisible] = useState(false);
81
68
  const [isCraftingDisabled, setIsCraftingDisabled] = useState(false);
@@ -90,30 +77,6 @@ export const CraftBook: React.FC<IItemCraftSelectorProps> = ({
90
77
  setItems(craftablesItems);
91
78
  }, [craftablesItems]);
92
79
 
93
- useEffect(() => {
94
- const handleResize = (): void => {
95
- if (
96
- window.innerWidth < 500 &&
97
- size?.width !== mobilePortrait.width &&
98
- (!scale || scale < 1)
99
- ) {
100
- setSize(mobilePortrait);
101
- } else if (
102
- (!scale || scale < 1) &&
103
- size?.width !== mobileLanscape.width
104
- ) {
105
- setSize(mobileLanscape);
106
- } else if (size?.width !== desktop.width) {
107
- setSize(desktop);
108
- }
109
- };
110
- handleResize();
111
-
112
- window.addEventListener('resize', handleResize);
113
-
114
- return () => window.removeEventListener('resize', handleResize);
115
- }, [scale]);
116
-
117
80
  const togglePinItem = (itemKey: string) => {
118
81
  setPinnedItems(current =>
119
82
  current.includes(itemKey)
@@ -151,8 +114,9 @@ export const CraftBook: React.FC<IItemCraftSelectorProps> = ({
151
114
  .includes(searchTerm.toLowerCase());
152
115
  const matchesCategory =
153
116
  selectedType === 'Suggested' ||
154
- (selectedType === 'Pinned' && pinnedItems.includes(item.key)) ||
155
- item.subType === selectedType;
117
+ (selectedType === 'Pinned'
118
+ ? pinnedItems.includes(item.key)
119
+ : item.subType === selectedType);
156
120
  return matchesSearch && matchesCategory;
157
121
  });
158
122
 
@@ -274,7 +238,7 @@ export const CraftBook: React.FC<IItemCraftSelectorProps> = ({
274
238
 
275
239
  <Footer>
276
240
  <Button buttonType={ButtonTypes.RPGUIButton} onPointerDown={onClose}>
277
- Cancel
241
+ Close
278
242
  </Button>
279
243
  <Button
280
244
  disabled={!craftItemKey || isCraftingDisabled}
@@ -411,7 +375,7 @@ const RadioInputScroller = styled.div`
411
375
  gap: 16px;
412
376
  align-content: start;
413
377
 
414
- @media (max-width: ${mobilePortrait.width}) {
378
+ @media (max-width: ${MOBILE_WIDTH}) {
415
379
  grid-template-columns: 1fr;
416
380
  }
417
381
  `;
@@ -463,7 +427,7 @@ const Footer = styled.div`
463
427
  min-width: 100px;
464
428
  }
465
429
 
466
- @media (max-width: ${mobilePortrait.width}) {
430
+ @media (max-width: ${MOBILE_WIDTH}) {
467
431
  justify-content: center;
468
432
  }
469
433
  `;
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
2
2
 
3
3
  const desktop = {
4
4
  width: 'min(900px, 80%)',
5
- height: 'min(700px, 80%)',
5
+ height: 'min(auto, 80%)',
6
6
  };
7
7
 
8
8
  const mobileLanscape = {
@@ -8,23 +8,23 @@ export function calculateMaxCraftable(
8
8
  return 0;
9
9
  }
10
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
- );
11
+ return (
12
+ recipe.ingredients.reduce((maxPossible, ingredient) => {
13
+ const inventoryItem = Object.values(inventory.slots).find(
14
+ (item): item is IItem => item?.key === ingredient.key
15
+ );
15
16
 
16
- if (!inventoryItem) {
17
- return 0;
18
- }
17
+ if (!inventoryItem) {
18
+ return 0;
19
+ }
19
20
 
20
- const possibleWithThisIngredient = Math.floor(
21
- inventoryItem.stackQty ?? 0 / ingredient.qty
22
- );
21
+ const possibleWithThisIngredient = Math.floor(
22
+ (inventoryItem.stackQty ?? 0) / ingredient.qty
23
+ );
23
24
 
24
- if (maxPossible === -1) {
25
- return possibleWithThisIngredient;
26
- }
27
-
28
- return Math.min(maxPossible, possibleWithThisIngredient);
29
- }, -1);
25
+ return maxPossible === undefined
26
+ ? possibleWithThisIngredient
27
+ : Math.min(maxPossible, possibleWithThisIngredient);
28
+ }, undefined as number | undefined) ?? 0
29
+ );
30
30
  }