@rpg-engine/long-bow 0.5.26 → 0.5.27

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.
@@ -13987,8 +13987,8 @@ var ItemSlot = /*#__PURE__*/mobxReactLite.observer(function (_ref) {
13987
13987
  if (!item || isSelectingShortcut) {
13988
13988
  return;
13989
13989
  }
13990
- setDraggingItem(item);
13991
13990
  if (onDragStart && containerType) {
13991
+ setDraggingItem(item);
13992
13992
  onDragStart(item, slotIndex, containerType);
13993
13993
  }
13994
13994
  },
@@ -14766,10 +14766,14 @@ var useCursorPosition = function useCursorPosition(_ref) {
14766
14766
  }),
14767
14767
  position = _useState[0],
14768
14768
  setPosition = _useState[1];
14769
- var setFromEvent = function setFromEvent(e) {
14769
+ var scalePosition = React.useCallback(function (x, y) {
14770
+ return {
14771
+ x: (x - shared.GRID_WIDTH / 2) / scale + shared.GRID_WIDTH / 2,
14772
+ y: (y - shared.GRID_HEIGHT / 2) / scale + shared.GRID_HEIGHT / 2
14773
+ };
14774
+ }, [scale]);
14775
+ var setFromEvent = React.useCallback(function (e) {
14770
14776
  var x, y;
14771
- var viewportCenterX = window.innerWidth / 2 - shared.GRID_WIDTH;
14772
- var viewportCenterY = window.innerHeight / -shared.GRID_HEIGHT;
14773
14777
  if ('touches' in e) {
14774
14778
  x = e.touches[0].clientX;
14775
14779
  y = e.touches[0].clientY;
@@ -14777,22 +14781,30 @@ var useCursorPosition = function useCursorPosition(_ref) {
14777
14781
  x = e.clientX;
14778
14782
  y = e.clientY;
14779
14783
  }
14780
- // Adjusting for the global scale
14781
- // Assuming the element is centrally located
14784
+ var scaledPosition = scalePosition(x, y);
14785
+ setPosition(scaledPosition);
14786
+ }, [scale, scalePosition]);
14787
+ var cleanup = React.useCallback(function () {
14782
14788
  setPosition({
14783
- x: (x - viewportCenterX) / scale + viewportCenterX,
14784
- y: (y - viewportCenterY) / scale + viewportCenterY
14789
+ x: 0,
14790
+ y: 0
14785
14791
  });
14786
- };
14792
+ }, []);
14787
14793
  React.useEffect(function () {
14788
- window.addEventListener('mousemove', setFromEvent);
14789
- window.addEventListener('touchmove', setFromEvent);
14790
- console.log("SCALE IS ", scale);
14794
+ var handleEvent = function handleEvent(e) {
14795
+ return setFromEvent(e);
14796
+ };
14797
+ window.addEventListener('mousemove', handleEvent);
14798
+ window.addEventListener('touchmove', handleEvent);
14799
+ window.addEventListener('mouseup', cleanup);
14800
+ window.addEventListener('touchend', cleanup);
14791
14801
  return function () {
14792
- window.removeEventListener('mousemove', setFromEvent);
14793
- window.removeEventListener('touchmove', setFromEvent);
14802
+ window.removeEventListener('mousemove', handleEvent);
14803
+ window.removeEventListener('touchmove', handleEvent);
14804
+ window.removeEventListener('mouseup', cleanup);
14805
+ window.removeEventListener('touchend', cleanup);
14794
14806
  };
14795
- }, [scale]);
14807
+ }, [setFromEvent, cleanup]);
14796
14808
  return position;
14797
14809
  };
14798
14810
 
@@ -14813,6 +14825,9 @@ var DraggedItem = function DraggedItem(_ref) {
14813
14825
  if (!item) {
14814
14826
  return null;
14815
14827
  }
14828
+ if (x === 0 && y === 0) {
14829
+ return null;
14830
+ }
14816
14831
  var centeredX = x - OFFSET;
14817
14832
  var centeredY = y - OFFSET;
14818
14833
  var stackInfo = onRenderStackInfo((_item$_id = item == null ? void 0 : item._id) != null ? _item$_id : '', (_item$stackQty = item == null ? void 0 : item.stackQty) != null ? _item$stackQty : 0);