@rpg-engine/long-bow 0.7.50 → 0.7.52
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/long-bow.cjs.development.js +83 -26
- 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 +83 -26
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Item/Inventory/ItemSlot.tsx +104 -33
package/package.json
CHANGED
|
@@ -142,7 +142,11 @@ export const ItemSlot = React.memo(
|
|
|
142
142
|
const [contextActions, setContextActions] = useState<IContextMenuItem[]>(
|
|
143
143
|
[]
|
|
144
144
|
);
|
|
145
|
-
const [
|
|
145
|
+
const [touchStartTime, setTouchStartTime] = useState<number | null>(null);
|
|
146
|
+
const [
|
|
147
|
+
touchStartPosition,
|
|
148
|
+
setTouchStartPosition,
|
|
149
|
+
] = useState<IPosition | null>(null);
|
|
146
150
|
|
|
147
151
|
useEffect(() => {
|
|
148
152
|
setDragState(prev => ({
|
|
@@ -216,8 +220,40 @@ export const ItemSlot = React.memo(
|
|
|
216
220
|
// to prevent the item from being dragged again
|
|
217
221
|
target.classList.remove('react-draggable-dragging');
|
|
218
222
|
|
|
219
|
-
const
|
|
220
|
-
|
|
223
|
+
const isTouch = e.type.startsWith('touch');
|
|
224
|
+
|
|
225
|
+
if (isTouch) {
|
|
226
|
+
const touchEvent = e as TouchEvent;
|
|
227
|
+
const touch = touchEvent.changedTouches[0];
|
|
228
|
+
const touchEndTime = new Date().getTime();
|
|
229
|
+
const touchDuration = touchStartTime
|
|
230
|
+
? touchEndTime - touchStartTime
|
|
231
|
+
: 0;
|
|
232
|
+
|
|
233
|
+
// Check if it's a short tap (less than 200ms) and hasn't moved much
|
|
234
|
+
const isShortTap = touchDuration < 200;
|
|
235
|
+
const hasMovedSignificantly =
|
|
236
|
+
touchStartPosition &&
|
|
237
|
+
(Math.abs(touch.clientX - touchStartPosition.x) > 10 ||
|
|
238
|
+
Math.abs(touch.clientY - touchStartPosition.y) > 10);
|
|
239
|
+
|
|
240
|
+
if (isShortTap && !hasMovedSignificantly) {
|
|
241
|
+
// Handle as a tap/click
|
|
242
|
+
if (item) {
|
|
243
|
+
setTooltipState(prev => ({
|
|
244
|
+
...prev,
|
|
245
|
+
mobileVisible: true,
|
|
246
|
+
}));
|
|
247
|
+
onPointerDown(item.type, containerType ?? null, item);
|
|
248
|
+
}
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Threshold for considering a tap/click as a drag
|
|
254
|
+
const dragThreshold = 5; // pixels
|
|
255
|
+
const isDrag =
|
|
256
|
+
Math.abs(data.x) > dragThreshold || Math.abs(data.y) > dragThreshold;
|
|
221
257
|
|
|
222
258
|
if (dragState.wasDragged && item && !isSelectingShortcut) {
|
|
223
259
|
//@ts-ignore
|
|
@@ -270,23 +306,16 @@ export const ItemSlot = React.memo(
|
|
|
270
306
|
}));
|
|
271
307
|
}
|
|
272
308
|
}, 50);
|
|
273
|
-
} else if (item
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
309
|
+
} else if (item) {
|
|
310
|
+
if (isTouch && !isDrag) {
|
|
311
|
+
setTooltipState(prev => ({
|
|
312
|
+
...prev,
|
|
313
|
+
mobileVisible: true,
|
|
314
|
+
}));
|
|
315
|
+
} else if (
|
|
316
|
+
!isTouch &&
|
|
277
317
|
!isContextMenuDisabled &&
|
|
278
|
-
e.type === 'touchend' &&
|
|
279
318
|
!isSelectingShortcut
|
|
280
|
-
) {
|
|
281
|
-
isTouch = true;
|
|
282
|
-
setTooltipState(prev => ({ ...prev, mobileVisible: true }));
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (
|
|
286
|
-
!isContextMenuDisabled &&
|
|
287
|
-
!isSelectingShortcut &&
|
|
288
|
-
!isTouch &&
|
|
289
|
-
!dragState.wasDragged
|
|
290
319
|
) {
|
|
291
320
|
setContextMenuState(prev => ({
|
|
292
321
|
...prev,
|
|
@@ -306,8 +335,14 @@ export const ItemSlot = React.memo(
|
|
|
306
335
|
}
|
|
307
336
|
}
|
|
308
337
|
|
|
309
|
-
|
|
338
|
+
if (!isDrag || !isTouch) {
|
|
339
|
+
console.log('Calling onPointerDown');
|
|
340
|
+
onPointerDown(item.type, containerType ?? null, item);
|
|
341
|
+
}
|
|
310
342
|
}
|
|
343
|
+
|
|
344
|
+
setDragState(prev => ({ ...prev, wasDragged: false }));
|
|
345
|
+
console.log('Final dragState:', dragState);
|
|
311
346
|
};
|
|
312
347
|
|
|
313
348
|
const onDraggableStart: DraggableEventHandler = () => {
|
|
@@ -315,8 +350,6 @@ export const ItemSlot = React.memo(
|
|
|
315
350
|
return;
|
|
316
351
|
}
|
|
317
352
|
|
|
318
|
-
setDragStartTime(Date.now());
|
|
319
|
-
|
|
320
353
|
if (onDragStart && containerType) {
|
|
321
354
|
onDragStart(item, slotIndex, containerType);
|
|
322
355
|
}
|
|
@@ -339,6 +372,54 @@ export const ItemSlot = React.memo(
|
|
|
339
372
|
}
|
|
340
373
|
};
|
|
341
374
|
|
|
375
|
+
const onTouchStart = (e: React.TouchEvent) => {
|
|
376
|
+
setTouchStartTime(new Date().getTime());
|
|
377
|
+
setTouchStartPosition({
|
|
378
|
+
x: e.touches[0].clientX,
|
|
379
|
+
y: e.touches[0].clientY,
|
|
380
|
+
});
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
const onTouchEnd = (e: React.TouchEvent) => {
|
|
384
|
+
// Prevent default to stop potential unwanted behaviors
|
|
385
|
+
e.preventDefault();
|
|
386
|
+
|
|
387
|
+
const touch = e.changedTouches[0];
|
|
388
|
+
const touchEndTime = new Date().getTime();
|
|
389
|
+
const touchDuration = touchStartTime
|
|
390
|
+
? touchEndTime - touchStartTime
|
|
391
|
+
: 0;
|
|
392
|
+
|
|
393
|
+
// Check if it's a short tap (less than 200ms) and hasn't moved much
|
|
394
|
+
const isShortTap = touchDuration < 200;
|
|
395
|
+
const hasMovedSignificantly =
|
|
396
|
+
touchStartPosition &&
|
|
397
|
+
(Math.abs(touch.clientX - touchStartPosition.x) > 10 ||
|
|
398
|
+
Math.abs(touch.clientY - touchStartPosition.y) > 10);
|
|
399
|
+
|
|
400
|
+
if (isShortTap && !hasMovedSignificantly) {
|
|
401
|
+
// Handle as a tap/click
|
|
402
|
+
if (item) {
|
|
403
|
+
setTooltipState(prev => ({
|
|
404
|
+
...prev,
|
|
405
|
+
mobileVisible: true,
|
|
406
|
+
}));
|
|
407
|
+
onPointerDown(item.type, containerType ?? null, item);
|
|
408
|
+
}
|
|
409
|
+
} else {
|
|
410
|
+
// Handle as a drag end
|
|
411
|
+
const simulatedEvent = new MouseEvent('mouseup', {
|
|
412
|
+
clientX: touch.clientX,
|
|
413
|
+
clientY: touch.clientY,
|
|
414
|
+
bubbles: true,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
document
|
|
418
|
+
.elementFromPoint(touch.clientX, touch.clientY)
|
|
419
|
+
?.dispatchEvent(simulatedEvent);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
|
|
342
423
|
const bounds = getContainerBounds();
|
|
343
424
|
return (
|
|
344
425
|
<Container
|
|
@@ -351,18 +432,6 @@ export const ItemSlot = React.memo(
|
|
|
351
432
|
onPlaceDrop(data, slotIndex, containerType);
|
|
352
433
|
}
|
|
353
434
|
}}
|
|
354
|
-
onTouchEnd={e => {
|
|
355
|
-
const { clientX, clientY } = e.changedTouches[0];
|
|
356
|
-
const simulatedEvent = new MouseEvent('mouseup', {
|
|
357
|
-
clientX,
|
|
358
|
-
clientY,
|
|
359
|
-
bubbles: true,
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
document
|
|
363
|
-
.elementFromPoint(clientX, clientY)
|
|
364
|
-
?.dispatchEvent(simulatedEvent);
|
|
365
|
-
}}
|
|
366
435
|
onPointerDown={
|
|
367
436
|
onDragStart !== undefined && onDragEnd !== undefined
|
|
368
437
|
? undefined
|
|
@@ -377,6 +446,8 @@ export const ItemSlot = React.memo(
|
|
|
377
446
|
item?.type === ItemType.Tool ||
|
|
378
447
|
item?.subType === ItemSubType.Seed)
|
|
379
448
|
}
|
|
449
|
+
onTouchStart={onTouchStart}
|
|
450
|
+
onTouchEnd={onTouchEnd}
|
|
380
451
|
>
|
|
381
452
|
<Draggable
|
|
382
453
|
axis={isSelectingShortcut ? 'none' : 'both'}
|