@blorkfield/overlay-core 0.8.0 → 0.8.1

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/index.cjs CHANGED
@@ -2344,6 +2344,12 @@ var OverlayScene = class {
2344
2344
  */
2345
2345
  setFollowTarget(key, x, y) {
2346
2346
  this.followTargets.set(key, { x, y });
2347
+ if (key === "mouse" && this.mouse) {
2348
+ this.mouse.position.x = x;
2349
+ this.mouse.position.y = y;
2350
+ this.mouse.absolute.x = x;
2351
+ this.mouse.absolute.y = y;
2352
+ }
2347
2353
  }
2348
2354
  /**
2349
2355
  * Remove a follow target. Objects with the corresponding tag will stop following.
@@ -2359,6 +2365,52 @@ var OverlayScene = class {
2359
2365
  getFollowTargetKeys() {
2360
2366
  return Array.from(this.followTargets.keys());
2361
2367
  }
2368
+ // ==================== GRAB/DRAG METHODS ====================
2369
+ /**
2370
+ * Programmatically grab an object at the current mouse position.
2371
+ * Uses the externally set mouse position (via setFollowTarget('mouse', x, y))
2372
+ * or the native canvas mouse position if no external position is set.
2373
+ * Only objects with the 'grabable' tag can be grabbed.
2374
+ * @returns The ID of the grabbed object, or null if no grabable object at position
2375
+ */
2376
+ startGrab() {
2377
+ if (!this.mouseConstraint || !this.mouse) return null;
2378
+ const mouseTarget = this.followTargets.get("mouse");
2379
+ const position = mouseTarget ?? { x: this.mouse.position.x, y: this.mouse.position.y };
2380
+ const bodies = import_matter_js5.default.Query.point(
2381
+ import_matter_js5.default.Composite.allBodies(this.engine.world),
2382
+ position
2383
+ );
2384
+ for (const body of bodies) {
2385
+ const entry = this.findObjectByBody(body);
2386
+ if (entry && entry.tags.includes("grabable")) {
2387
+ this.mouseConstraint.constraint.bodyB = entry.body;
2388
+ this.mouseConstraint.constraint.pointB = {
2389
+ x: position.x - entry.body.position.x,
2390
+ y: position.y - entry.body.position.y
2391
+ };
2392
+ return entry.id;
2393
+ }
2394
+ }
2395
+ return null;
2396
+ }
2397
+ /**
2398
+ * Release any currently grabbed object.
2399
+ */
2400
+ endGrab() {
2401
+ if (this.mouseConstraint) {
2402
+ this.mouseConstraint.constraint.bodyB = null;
2403
+ }
2404
+ }
2405
+ /**
2406
+ * Get the ID of the currently grabbed object.
2407
+ * @returns The ID of the grabbed object, or null if nothing is grabbed
2408
+ */
2409
+ getGrabbedObject() {
2410
+ if (!this.mouseConstraint?.constraint.bodyB) return null;
2411
+ const entry = this.findObjectByBody(this.mouseConstraint.constraint.bodyB);
2412
+ return entry?.id ?? null;
2413
+ }
2362
2414
  // ==================== PHYSICS MANIPULATION METHODS ====================
2363
2415
  /**
2364
2416
  * Apply a force to an object.