@blorkfield/overlay-core 0.11.0 → 0.11.2
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 +45 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -513,6 +513,17 @@ function createBodyFromVertices(id, x, y, vertices, renderOptions) {
|
|
|
513
513
|
render: renderOptions
|
|
514
514
|
});
|
|
515
515
|
import_matter_js2.default.Body.setPosition(body, { x, y });
|
|
516
|
+
if (!body.parts.every((part) => part.vertices && part.vertices.length >= 3)) {
|
|
517
|
+
logger.warn(LOG_PREFIX2, `fromVertices produced degenerate parts, falling back to circle`, { id });
|
|
518
|
+
return import_matter_js2.default.Bodies.circle(x, y, DEFAULT_RADIUS, {
|
|
519
|
+
restitution: 0.3,
|
|
520
|
+
friction: 0.1,
|
|
521
|
+
frictionAir: 0.01,
|
|
522
|
+
density: 5e-3,
|
|
523
|
+
label: `entity:${id}`,
|
|
524
|
+
render: renderOptions
|
|
525
|
+
});
|
|
526
|
+
}
|
|
516
527
|
return body;
|
|
517
528
|
}
|
|
518
529
|
function createBoundariesWithFloorConfig(bounds, floorConfig) {
|
|
@@ -704,11 +715,26 @@ async function createBoxObstacleWithInfo(id, config, isStatic = true) {
|
|
|
704
715
|
}
|
|
705
716
|
}
|
|
706
717
|
});
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
718
|
+
if (!body.parts.every((part) => part.vertices && part.vertices.length >= 3)) {
|
|
719
|
+
logger.warn(LOG_PREFIX2, `fromVertices produced degenerate obstacle, falling back to rectangle`, { id });
|
|
720
|
+
body = import_matter_js2.default.Bodies.rectangle(config.x, config.y, scaledWidth, scaledHeight, {
|
|
721
|
+
isStatic,
|
|
722
|
+
label: `obstacle:${id}`,
|
|
723
|
+
render: {
|
|
724
|
+
sprite: {
|
|
725
|
+
texture: config.imageUrl,
|
|
726
|
+
xScale: spriteScale,
|
|
727
|
+
yScale: spriteScale
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
} else {
|
|
732
|
+
const spriteOffsetX = (config.x - body.position.x) / scaledWidth;
|
|
733
|
+
const spriteOffsetY = (config.y - body.position.y) / scaledHeight;
|
|
734
|
+
if (body.render.sprite) {
|
|
735
|
+
body.render.sprite.xOffset = 0.5 + spriteOffsetX;
|
|
736
|
+
body.render.sprite.yOffset = 0.5 + spriteOffsetY;
|
|
737
|
+
}
|
|
712
738
|
}
|
|
713
739
|
} else {
|
|
714
740
|
body = import_matter_js2.default.Bodies.rectangle(config.x, config.y, scaledWidth, scaledHeight, {
|
|
@@ -757,6 +783,10 @@ async function createObstacleAsync(id, config, isStatic = true) {
|
|
|
757
783
|
}
|
|
758
784
|
});
|
|
759
785
|
import_matter_js2.default.Body.setPosition(body, { x: config.x, y: config.y });
|
|
786
|
+
if (!body.parts.every((part) => part.vertices && part.vertices.length >= 3)) {
|
|
787
|
+
logger.warn(LOG_PREFIX2, `Image obstacle fromVertices degenerate, falling back to rectangle`, { id });
|
|
788
|
+
return createObstacle(id, config, isStatic);
|
|
789
|
+
}
|
|
760
790
|
return body;
|
|
761
791
|
}
|
|
762
792
|
logger.warn(LOG_PREFIX2, `Image obstacle shape extraction failed, falling back to rectangle`, { id });
|
|
@@ -3134,11 +3164,12 @@ var OverlayScene = class {
|
|
|
3134
3164
|
maxDimension = Math.max(maxDimension, dims.width, dims.height);
|
|
3135
3165
|
}
|
|
3136
3166
|
if (maxDimension === 0) maxDimension = 100;
|
|
3167
|
+
const spaceWidth = letterSize / 3;
|
|
3137
3168
|
const calculateLineWidth = (line) => {
|
|
3138
3169
|
let width = 0;
|
|
3139
3170
|
for (const char of line) {
|
|
3140
3171
|
if (char === " ") {
|
|
3141
|
-
width +=
|
|
3172
|
+
width += spaceWidth;
|
|
3142
3173
|
} else if (/^[A-Za-z0-9]$/.test(char)) {
|
|
3143
3174
|
const dims = charDimensions.get(char);
|
|
3144
3175
|
if (dims) {
|
|
@@ -3196,7 +3227,6 @@ var OverlayScene = class {
|
|
|
3196
3227
|
for (let i = 0; i < chars.length; i++) {
|
|
3197
3228
|
const char = chars[i];
|
|
3198
3229
|
if (char === " ") {
|
|
3199
|
-
const spaceWidth = config.letterSpacing ?? letterSize;
|
|
3200
3230
|
currentX += spaceWidth;
|
|
3201
3231
|
globalCharIndex++;
|
|
3202
3232
|
if (inWord) {
|
|
@@ -3473,13 +3503,20 @@ var OverlayScene = class {
|
|
|
3473
3503
|
x: currentX + v.x,
|
|
3474
3504
|
y: currentY + v.y
|
|
3475
3505
|
}));
|
|
3476
|
-
|
|
3506
|
+
let body = import_matter_js5.default.Bodies.fromVertices(glyphCenterX, glyphCenterY, [worldVertices], {
|
|
3477
3507
|
isStatic,
|
|
3478
3508
|
label: `obstacle:${id}`,
|
|
3479
3509
|
render: {
|
|
3480
3510
|
visible: false
|
|
3481
3511
|
}
|
|
3482
3512
|
});
|
|
3513
|
+
if (!body.parts.every((part) => part.vertices && part.vertices.length >= 3)) {
|
|
3514
|
+
body = import_matter_js5.default.Bodies.rectangle(glyphCenterX, glyphCenterY, Math.max(glyphWidth, 1), Math.max(Math.abs(glyphHeight), 1), {
|
|
3515
|
+
isStatic,
|
|
3516
|
+
label: `obstacle:${id}`,
|
|
3517
|
+
render: { visible: false }
|
|
3518
|
+
});
|
|
3519
|
+
}
|
|
3483
3520
|
const offsetX = currentX - body.position.x;
|
|
3484
3521
|
const offsetY = currentY - body.position.y;
|
|
3485
3522
|
let pressureThreshold;
|