@unboxy/phaser-sdk 0.2.31 → 0.2.32
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/scene/HudRuntime.js +67 -30
- package/package.json +1 -1
package/dist/scene/HudRuntime.js
CHANGED
|
@@ -395,11 +395,32 @@ function applyOriginFromAnchor(go, side) {
|
|
|
395
395
|
go.setOrigin(ox, oy);
|
|
396
396
|
}
|
|
397
397
|
/**
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
398
|
+
* Compute the per-side origin-shift offset for a container widget. Containers
|
|
399
|
+
* don't support setOrigin, so we shift the container's position so its
|
|
400
|
+
* (centred) child visuals appear at the right place relative to the
|
|
401
|
+
* resolved anchor coord. Used both at spawn and during applyHudPatch when
|
|
402
|
+
* the anchor side changes.
|
|
401
403
|
*/
|
|
402
|
-
|
|
404
|
+
/** Default container widths/heights — must mirror the spawners' fallbacks. */
|
|
405
|
+
function defaultContainerWidth(entity) {
|
|
406
|
+
if (entity.kind === 'icon-button')
|
|
407
|
+
return entity.visual.width ?? 96;
|
|
408
|
+
if (entity.kind === 'progress-bar')
|
|
409
|
+
return entity.visual.width ?? 200;
|
|
410
|
+
if (entity.kind === 'panel')
|
|
411
|
+
return entity.visual.width ?? 200;
|
|
412
|
+
return 0;
|
|
413
|
+
}
|
|
414
|
+
function defaultContainerHeight(entity) {
|
|
415
|
+
if (entity.kind === 'icon-button')
|
|
416
|
+
return entity.visual.height ?? 48;
|
|
417
|
+
if (entity.kind === 'progress-bar')
|
|
418
|
+
return entity.visual.height ?? 16;
|
|
419
|
+
if (entity.kind === 'panel')
|
|
420
|
+
return entity.visual.height ?? 100;
|
|
421
|
+
return 0;
|
|
422
|
+
}
|
|
423
|
+
function originShiftFor(side, w, h) {
|
|
403
424
|
const map = {
|
|
404
425
|
'top-left': [0, 0],
|
|
405
426
|
'top': [0.5, 0],
|
|
@@ -412,11 +433,12 @@ function applyContainerOriginShift(container, side, w, h) {
|
|
|
412
433
|
'bottom-right': [1, 1],
|
|
413
434
|
};
|
|
414
435
|
const [ox, oy] = map[side];
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
container.
|
|
436
|
+
return { x: (0.5 - ox) * w, y: (0.5 - oy) * h };
|
|
437
|
+
}
|
|
438
|
+
function applyContainerOriginShift(container, side, w, h) {
|
|
439
|
+
const s = originShiftFor(side, w, h);
|
|
440
|
+
container.x += s.x;
|
|
441
|
+
container.y += s.y;
|
|
420
442
|
}
|
|
421
443
|
/**
|
|
422
444
|
* Compute the rendered string for a text source. Static returns the literal;
|
|
@@ -654,27 +676,42 @@ export function applyHudPatch(game, entityId, patch) {
|
|
|
654
676
|
if (typeof patch.anchor.offsetY === 'number')
|
|
655
677
|
entity.anchor.offsetY = patch.anchor.offsetY;
|
|
656
678
|
const pos = resolveAnchor(hud, entity.anchor, safeArea);
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
//
|
|
660
|
-
//
|
|
661
|
-
//
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
679
|
+
// Container-based widgets (icon-button, progress-bar, panel) have no
|
|
680
|
+
// setOrigin — they were shifted at spawn by `applyContainerOriginShift`
|
|
681
|
+
// so their centred child visuals appear at the right place. The same
|
|
682
|
+
// shift must be re-applied on every anchor change, otherwise the
|
|
683
|
+
// container ends up centred on the raw anchor coord and the visual is
|
|
684
|
+
// off by ±(w/2, h/2). Text + image have setOrigin so we use that path.
|
|
685
|
+
const isContainer = entity.kind === 'icon-button' || entity.kind === 'progress-bar' || entity.kind === 'panel';
|
|
686
|
+
if (isContainer) {
|
|
687
|
+
const visual = entity.visual;
|
|
688
|
+
const w = visual.width ?? defaultContainerWidth(entity);
|
|
689
|
+
const h = visual.height ?? defaultContainerHeight(entity);
|
|
690
|
+
const shift = originShiftFor(entity.anchor.side, w, h);
|
|
691
|
+
go.x = pos.x + shift.x;
|
|
692
|
+
go.y = pos.y + shift.y;
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
go.x = pos.x;
|
|
696
|
+
go.y = pos.y;
|
|
697
|
+
// Re-pivot the origin for setOrigin-based widgets (text, image).
|
|
698
|
+
if (typeof patch.anchor.side === 'string') {
|
|
699
|
+
const sideMap = {
|
|
700
|
+
'top-left': [0, 0],
|
|
701
|
+
'top': [0.5, 0],
|
|
702
|
+
'top-right': [1, 0],
|
|
703
|
+
'left': [0, 0.5],
|
|
704
|
+
'center': [0.5, 0.5],
|
|
705
|
+
'right': [1, 0.5],
|
|
706
|
+
'bottom-left': [0, 1],
|
|
707
|
+
'bottom': [0.5, 1],
|
|
708
|
+
'bottom-right': [1, 1],
|
|
709
|
+
};
|
|
710
|
+
const o = sideMap[patch.anchor.side];
|
|
711
|
+
if (o) {
|
|
712
|
+
const setOrigin = go.setOrigin;
|
|
713
|
+
setOrigin?.call(go, o[0], o[1]);
|
|
714
|
+
}
|
|
678
715
|
}
|
|
679
716
|
}
|
|
680
717
|
}
|