@blorkfield/overlay-core 0.8.6 → 0.8.7
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 +43 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +43 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1442,9 +1442,30 @@ var OverlayScene = class {
|
|
|
1442
1442
|
};
|
|
1443
1443
|
// Follow targets for follow-{key} tagged objects
|
|
1444
1444
|
this.followTargets = /* @__PURE__ */ new Map();
|
|
1445
|
-
// Delta-based grab tracking
|
|
1445
|
+
// Delta-based grab tracking
|
|
1446
1446
|
this.grabbedObjectId = null;
|
|
1447
1447
|
this.lastGrabMousePosition = null;
|
|
1448
|
+
this.grabbedWasDynamic = false;
|
|
1449
|
+
this.grabVelocity = { x: 0, y: 0 };
|
|
1450
|
+
/** Handle mouse down - start grab via programmatic API */
|
|
1451
|
+
this.handleMouseDown = (event) => {
|
|
1452
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
1453
|
+
const x = event.clientX - rect.left;
|
|
1454
|
+
const y = event.clientY - rect.top;
|
|
1455
|
+
this.followTargets.set("mouse", { x, y });
|
|
1456
|
+
this.startGrab();
|
|
1457
|
+
};
|
|
1458
|
+
/** Handle mouse move - update follow target for grabbed entity */
|
|
1459
|
+
this.handleMouseMove = (event) => {
|
|
1460
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
1461
|
+
const x = event.clientX - rect.left;
|
|
1462
|
+
const y = event.clientY - rect.top;
|
|
1463
|
+
this.followTargets.set("mouse", { x, y });
|
|
1464
|
+
};
|
|
1465
|
+
/** Handle mouse up - release grab */
|
|
1466
|
+
this.handleMouseUp = () => {
|
|
1467
|
+
this.endGrab();
|
|
1468
|
+
};
|
|
1448
1469
|
/** Handle canvas clicks for click-to-fall behavior */
|
|
1449
1470
|
this.handleCanvasClick = (event) => {
|
|
1450
1471
|
const rect = this.canvas.getBoundingClientRect();
|
|
@@ -1518,6 +1539,7 @@ var OverlayScene = class {
|
|
|
1518
1539
|
if (dx !== 0 || dy !== 0) {
|
|
1519
1540
|
import_matter_js5.default.Body.translate(entry.body, { x: dx, y: dy });
|
|
1520
1541
|
}
|
|
1542
|
+
this.grabVelocity = { x: dx * 0.5 + this.grabVelocity.x * 0.5, y: dy * 0.5 + this.grabVelocity.y * 0.5 };
|
|
1521
1543
|
this.lastGrabMousePosition = { x: mouseTarget.x, y: mouseTarget.y };
|
|
1522
1544
|
}
|
|
1523
1545
|
}
|
|
@@ -1570,6 +1592,9 @@ var OverlayScene = class {
|
|
|
1570
1592
|
import_matter_js5.default.Composite.add(this.engine.world, this.boundaries);
|
|
1571
1593
|
this.checkInitialFloorIntegrity();
|
|
1572
1594
|
this.mouse = import_matter_js5.default.Mouse.create(canvas);
|
|
1595
|
+
canvas.addEventListener("mousedown", this.handleMouseDown);
|
|
1596
|
+
canvas.addEventListener("mousemove", this.handleMouseMove);
|
|
1597
|
+
canvas.addEventListener("mouseup", this.handleMouseUp);
|
|
1573
1598
|
canvas.addEventListener("click", this.handleCanvasClick);
|
|
1574
1599
|
this.effectManager = new EffectManager(
|
|
1575
1600
|
this.config.bounds,
|
|
@@ -1992,6 +2017,9 @@ var OverlayScene = class {
|
|
|
1992
2017
|
}
|
|
1993
2018
|
destroy() {
|
|
1994
2019
|
this.stop();
|
|
2020
|
+
this.canvas.removeEventListener("mousedown", this.handleMouseDown);
|
|
2021
|
+
this.canvas.removeEventListener("mousemove", this.handleMouseMove);
|
|
2022
|
+
this.canvas.removeEventListener("mouseup", this.handleMouseUp);
|
|
1995
2023
|
this.canvas.removeEventListener("click", this.handleCanvasClick);
|
|
1996
2024
|
import_matter_js5.default.Events.off(this.render, "beforeRender", this.handleBeforeRender);
|
|
1997
2025
|
import_matter_js5.default.Events.off(this.render, "afterRender", this.handleAfterRender);
|
|
@@ -2355,6 +2383,9 @@ var OverlayScene = class {
|
|
|
2355
2383
|
if (entry && entry.tags.includes("grabable")) {
|
|
2356
2384
|
this.grabbedObjectId = entry.id;
|
|
2357
2385
|
this.lastGrabMousePosition = { x: position.x, y: position.y };
|
|
2386
|
+
this.grabVelocity = { x: 0, y: 0 };
|
|
2387
|
+
this.grabbedWasDynamic = !entry.body.isStatic;
|
|
2388
|
+
import_matter_js5.default.Body.setStatic(entry.body, true);
|
|
2358
2389
|
return entry.id;
|
|
2359
2390
|
}
|
|
2360
2391
|
}
|
|
@@ -2364,8 +2395,19 @@ var OverlayScene = class {
|
|
|
2364
2395
|
* Release any currently grabbed object.
|
|
2365
2396
|
*/
|
|
2366
2397
|
endGrab() {
|
|
2398
|
+
if (this.grabbedObjectId && this.grabbedWasDynamic) {
|
|
2399
|
+
const entry = this.objects.get(this.grabbedObjectId);
|
|
2400
|
+
if (entry) {
|
|
2401
|
+
import_matter_js5.default.Body.setStatic(entry.body, false);
|
|
2402
|
+
import_matter_js5.default.Sleeping.set(entry.body, false);
|
|
2403
|
+
import_matter_js5.default.Body.setVelocity(entry.body, this.grabVelocity);
|
|
2404
|
+
import_matter_js5.default.Body.setAngularVelocity(entry.body, 0);
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2367
2407
|
this.grabbedObjectId = null;
|
|
2368
2408
|
this.lastGrabMousePosition = null;
|
|
2409
|
+
this.grabbedWasDynamic = false;
|
|
2410
|
+
this.grabVelocity = { x: 0, y: 0 };
|
|
2369
2411
|
}
|
|
2370
2412
|
/**
|
|
2371
2413
|
* Get the ID of the currently grabbed object.
|