@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.
@@ -1,4 +1,4 @@
1
- import React, { Component, useState, useEffect, useRef, useContext, createContext, useMemo, Fragment } from 'react';
1
+ import React, { Component, useState, useEffect, useRef, useContext, createContext, useMemo, useCallback, Fragment } from 'react';
2
2
  import styled from 'styled-components';
3
3
  import { GRID_WIDTH, GRID_HEIGHT, ShortcutType, getItemTextureKeyPath, ItemContainerType, ItemType, DepotSocketEvents, ItemSocketEvents, ItemSocketEventsDisplayLabels, ActionsForInventory, ActionsForEquipmentSet, ActionsForLoot, ActionsForMapContainer, ItemRarities, ItemSubType, ItemSlotType, isMobileOrTablet, CharacterClass, getSPForLevel, getXPForLevel, PeriodOfDay, UserAccountTypes } from '@rpg-engine/shared';
4
4
  import dayjs from 'dayjs';
@@ -13982,8 +13982,8 @@ var ItemSlot = /*#__PURE__*/observer(function (_ref) {
13982
13982
  if (!item || isSelectingShortcut) {
13983
13983
  return;
13984
13984
  }
13985
- setDraggingItem(item);
13986
13985
  if (onDragStart && containerType) {
13986
+ setDraggingItem(item);
13987
13987
  onDragStart(item, slotIndex, containerType);
13988
13988
  }
13989
13989
  },
@@ -14761,10 +14761,14 @@ var useCursorPosition = function useCursorPosition(_ref) {
14761
14761
  }),
14762
14762
  position = _useState[0],
14763
14763
  setPosition = _useState[1];
14764
- var setFromEvent = function setFromEvent(e) {
14764
+ var scalePosition = useCallback(function (x, y) {
14765
+ return {
14766
+ x: (x - GRID_WIDTH / 2) / scale + GRID_WIDTH / 2,
14767
+ y: (y - GRID_HEIGHT / 2) / scale + GRID_HEIGHT / 2
14768
+ };
14769
+ }, [scale]);
14770
+ var setFromEvent = useCallback(function (e) {
14765
14771
  var x, y;
14766
- var viewportCenterX = window.innerWidth / 2 - GRID_WIDTH;
14767
- var viewportCenterY = window.innerHeight / -GRID_HEIGHT;
14768
14772
  if ('touches' in e) {
14769
14773
  x = e.touches[0].clientX;
14770
14774
  y = e.touches[0].clientY;
@@ -14772,22 +14776,30 @@ var useCursorPosition = function useCursorPosition(_ref) {
14772
14776
  x = e.clientX;
14773
14777
  y = e.clientY;
14774
14778
  }
14775
- // Adjusting for the global scale
14776
- // Assuming the element is centrally located
14779
+ var scaledPosition = scalePosition(x, y);
14780
+ setPosition(scaledPosition);
14781
+ }, [scale, scalePosition]);
14782
+ var cleanup = useCallback(function () {
14777
14783
  setPosition({
14778
- x: (x - viewportCenterX) / scale + viewportCenterX,
14779
- y: (y - viewportCenterY) / scale + viewportCenterY
14784
+ x: 0,
14785
+ y: 0
14780
14786
  });
14781
- };
14787
+ }, []);
14782
14788
  useEffect(function () {
14783
- window.addEventListener('mousemove', setFromEvent);
14784
- window.addEventListener('touchmove', setFromEvent);
14785
- console.log("SCALE IS ", scale);
14789
+ var handleEvent = function handleEvent(e) {
14790
+ return setFromEvent(e);
14791
+ };
14792
+ window.addEventListener('mousemove', handleEvent);
14793
+ window.addEventListener('touchmove', handleEvent);
14794
+ window.addEventListener('mouseup', cleanup);
14795
+ window.addEventListener('touchend', cleanup);
14786
14796
  return function () {
14787
- window.removeEventListener('mousemove', setFromEvent);
14788
- window.removeEventListener('touchmove', setFromEvent);
14797
+ window.removeEventListener('mousemove', handleEvent);
14798
+ window.removeEventListener('touchmove', handleEvent);
14799
+ window.removeEventListener('mouseup', cleanup);
14800
+ window.removeEventListener('touchend', cleanup);
14789
14801
  };
14790
- }, [scale]);
14802
+ }, [setFromEvent, cleanup]);
14791
14803
  return position;
14792
14804
  };
14793
14805
 
@@ -14808,6 +14820,9 @@ var DraggedItem = function DraggedItem(_ref) {
14808
14820
  if (!item) {
14809
14821
  return null;
14810
14822
  }
14823
+ if (x === 0 && y === 0) {
14824
+ return null;
14825
+ }
14811
14826
  var centeredX = x - OFFSET;
14812
14827
  var centeredY = y - OFFSET;
14813
14828
  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);