@blorkfield/overlay-core 0.8.1 → 0.8.3
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/README.md +46 -0
- package/dist/index.cjs +4 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -6
- package/dist/index.d.ts +0 -6
- package/dist/index.js +4 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -312,6 +312,52 @@ const tagged = scene.getObjectIdsByTag('falling');
|
|
|
312
312
|
const allTags = scene.getAllTags();
|
|
313
313
|
```
|
|
314
314
|
|
|
315
|
+
## Mouse Position and Grab API
|
|
316
|
+
|
|
317
|
+
For scenarios where mouse input comes from an external source (e.g., system-wide mouse capture via WebSocket), you can programmatically control mouse position and grab/release behavior. This is useful when the canvas is positioned with an offset from the screen origin.
|
|
318
|
+
|
|
319
|
+
### Setting Mouse Position
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
// Apply your offset and set the adjusted position
|
|
323
|
+
const canvasX = screenMouseX - canvasOffsetX;
|
|
324
|
+
const canvasY = screenMouseY - canvasOffsetY;
|
|
325
|
+
scene.setFollowTarget('mouse', canvasX, canvasY);
|
|
326
|
+
|
|
327
|
+
// This position is now used for:
|
|
328
|
+
// - Objects with 'follow' tag (they move toward this position)
|
|
329
|
+
// - Programmatic grab detection via startGrab()
|
|
330
|
+
// - MouseConstraint during drag (grabbed objects follow this position)
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
The offset calculation is your responsibility - overlay-core uses whatever position you provide.
|
|
334
|
+
|
|
335
|
+
### Programmatic Grab/Release
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
// Grab object at current mouse position (only 'grabable' tagged objects)
|
|
339
|
+
const grabbedId = scene.startGrab();
|
|
340
|
+
if (grabbedId) {
|
|
341
|
+
console.log(`Grabbed: ${grabbedId}`);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Update mouse position while dragging - object follows automatically
|
|
345
|
+
scene.setFollowTarget('mouse', newX, newY);
|
|
346
|
+
|
|
347
|
+
// Release the grabbed object
|
|
348
|
+
scene.endGrab();
|
|
349
|
+
|
|
350
|
+
// Check what's currently grabbed
|
|
351
|
+
const currentGrab = scene.getGrabbedObject(); // Returns ID or null
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
| Method | Returns | Description |
|
|
355
|
+
|--------|---------|-------------|
|
|
356
|
+
| `setFollowTarget('mouse', x, y)` | void | Set mouse position for follow behavior and grab detection |
|
|
357
|
+
| `startGrab()` | string \| null | Grab object at current mouse position, returns object ID |
|
|
358
|
+
| `endGrab()` | void | Release any currently grabbed object |
|
|
359
|
+
| `getGrabbedObject()` | string \| null | Get ID of currently grabbed object |
|
|
360
|
+
|
|
315
361
|
## Configuration
|
|
316
362
|
|
|
317
363
|
### Scene Config
|
package/dist/index.cjs
CHANGED
|
@@ -2327,14 +2327,6 @@ var OverlayScene = class {
|
|
|
2327
2327
|
}
|
|
2328
2328
|
return Array.from(tagsSet).sort();
|
|
2329
2329
|
}
|
|
2330
|
-
/**
|
|
2331
|
-
* Set the mouse position for follow behavior.
|
|
2332
|
-
* This overrides the browser mouse position for the 'follow' and 'follow-mouse' tags.
|
|
2333
|
-
* @deprecated Use setFollowTarget('mouse', x, y) instead
|
|
2334
|
-
*/
|
|
2335
|
-
setMousePosition(x, y) {
|
|
2336
|
-
this.setFollowTarget("mouse", x, y);
|
|
2337
|
-
}
|
|
2338
2330
|
/**
|
|
2339
2331
|
* Set a follow target position. Objects with 'follow-{key}' tag will
|
|
2340
2332
|
* automatically move toward this target each frame.
|
|
@@ -2384,6 +2376,7 @@ var OverlayScene = class {
|
|
|
2384
2376
|
for (const body of bodies) {
|
|
2385
2377
|
const entry = this.findObjectByBody(body);
|
|
2386
2378
|
if (entry && entry.tags.includes("grabable")) {
|
|
2379
|
+
this.mouse.button = 0;
|
|
2387
2380
|
this.mouseConstraint.constraint.bodyB = entry.body;
|
|
2388
2381
|
this.mouseConstraint.constraint.pointB = {
|
|
2389
2382
|
x: position.x - entry.body.position.x,
|
|
@@ -2401,6 +2394,9 @@ var OverlayScene = class {
|
|
|
2401
2394
|
if (this.mouseConstraint) {
|
|
2402
2395
|
this.mouseConstraint.constraint.bodyB = null;
|
|
2403
2396
|
}
|
|
2397
|
+
if (this.mouse) {
|
|
2398
|
+
this.mouse.button = -1;
|
|
2399
|
+
}
|
|
2404
2400
|
}
|
|
2405
2401
|
/**
|
|
2406
2402
|
* Get the ID of the currently grabbed object.
|