Skip to content

Commit bb4509b

Browse files
committed
Update API defaults for say to match Blockly block
1 parent b4cb94f commit bb4509b

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

api/ui.js

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export function setFlockReference(ref) {
77
}
88

99
export const flockUI = {
10-
1110
UIText({ text, x, y, fontSize, color, duration, id = null } = {}) {
1211
if (!flock.scene || !flock.GUI) {
1312
return;
@@ -17,7 +16,8 @@ export const flockUI = {
1716
flock.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
1817

1918
const textBlockId =
20-
id || `textBlock_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
19+
id ||
20+
`textBlock_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
2121

2222
const maxWidth = flock.scene.getEngine().getRenderWidth();
2323
const maxHeight = flock.scene.getEngine().getRenderHeight();
@@ -31,37 +31,40 @@ export const flockUI = {
3131
flock.scene.UITexture.addControl(textBlock);
3232

3333
// Anchor control at screen top-left; don't block input.
34-
textBlock.horizontalAlignment = flock.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
35-
textBlock.verticalAlignment = flock.GUI.Control.VERTICAL_ALIGNMENT_TOP;
34+
textBlock.horizontalAlignment =
35+
flock.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
36+
textBlock.verticalAlignment = flock.GUI.Control.VERTICAL_ALIGNMENT_TOP;
3637
textBlock.textWrapping = false;
3738
textBlock.isPointerBlocker = false;
3839
// Keep text centered inside its line box.
39-
textBlock.textHorizontalAlignment = flock.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
40-
textBlock.textVerticalAlignment = flock.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
40+
textBlock.textHorizontalAlignment =
41+
flock.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
42+
textBlock.textVerticalAlignment =
43+
flock.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
4144
}
4245

4346
// Update text + style
44-
textBlock.text = text;
47+
textBlock.text = text;
4548
textBlock.color = color || "white";
4649

4750
// Font & line box
4851
const px = Number(fontSize || 24);
49-
textBlock.fontSize = px;
52+
textBlock.fontSize = px;
5053
const linePx = Math.max(1, Math.round(px * 1.2)); // 1.2× prevents ascender clipping
5154
textBlock.lineHeight = `${linePx}px`;
52-
textBlock.height = `${Math.max(linePx, px + 4)}px`;
55+
textBlock.height = `${Math.max(linePx, px + 4)}px`;
5356

5457
// Position
5558
textBlock.left = adjustedX;
56-
textBlock.top = adjustedY;
59+
textBlock.top = adjustedY;
5760

5861
// WEB FONT STABILIZER: avoid the “first update jump”
5962
if (document.fonts && document.fonts.status !== "loaded") {
6063
// Hide until fonts are ready, then force a clean measure.
6164
const prevAlpha = textBlock.alpha;
6265
textBlock.alpha = 0;
6366
document.fonts.ready.then(() => {
64-
textBlock._markAsDirty(); // re-measure with real font
67+
textBlock._markAsDirty(); // re-measure with real font
6568
textBlock.alpha = prevAlpha ?? 1;
6669
});
6770
} else {
@@ -322,7 +325,9 @@ export const flockUI = {
322325
const keyList = Array.isArray(keys) ? keys : [keys];
323326
const uniqueKeys = Array.from(
324327
new Set(
325-
keyList.filter((key) => key !== undefined && key !== null && key !== ""),
328+
keyList.filter(
329+
(key) => key !== undefined && key !== null && key !== "",
330+
),
326331
),
327332
);
328333
// Use a unique ID per button so Babylon doesn't recycle the same control
@@ -371,7 +376,11 @@ export const flockUI = {
371376
const upButton = flock.createSmallButton("△", ["w", "ArrowUp"], color);
372377
const downButton = flock.createSmallButton("▽", ["s", "ArrowDown"], color);
373378
const leftButton = flock.createSmallButton("◁", ["a", "ArrowLeft"], color);
374-
const rightButton = flock.createSmallButton("▷", ["d", "ArrowRight"], color);
379+
const rightButton = flock.createSmallButton(
380+
"▷",
381+
["d", "ArrowRight"],
382+
color,
383+
);
375384
// Add buttons to the grid
376385
grid.addControl(upButton, 0, 1); // Add to row 0, column 1
377386
grid.addControl(leftButton, 1, 0); // Add to row 1, column 0
@@ -435,19 +444,24 @@ export const flockUI = {
435444
let {
436445
text,
437446
duration,
438-
textColor = "white",
447+
textColor = "#ffffff",
439448
backgroundColor = "#000000",
440-
alpha = 0.7,
441-
size = 16,
442-
mode = "APPEND",
449+
alpha = 1,
450+
size = 24,
451+
mode = "ADD",
443452
} = options;
444453

445454
// Validate duration: must be finite and non-negative
446-
duration = (isFinite(Number(duration)) && Number(duration) >= 0) ? Number(duration) : 0;
455+
duration =
456+
isFinite(Number(duration)) && Number(duration) >= 0
457+
? Number(duration)
458+
: 0;
447459
// Validate alpha: must be finite and clamped between 0 and 1
448-
alpha = isFinite(Number(alpha)) ? Math.min(Math.max(Number(alpha), 0), 1) : 0.7;
460+
alpha = isFinite(Number(alpha))
461+
? Math.min(Math.max(Number(alpha), 0), 1)
462+
: 0.7;
449463
// Validate size: must be finite and positive
450-
size = (isFinite(Number(size)) && Number(size) > 0) ? Number(size) : 16;
464+
size = isFinite(Number(size)) && Number(size) > 0 ? Number(size) : 16;
451465

452466
if (!flock.scene) {
453467
console.error("Scene is not available.");
@@ -623,15 +637,14 @@ export const flockUI = {
623637
});
624638
}
625639
},
626-
printText({
627-
text,
628-
duration = 30,
629-
color = "white"
630-
} = {}) {
640+
printText({ text, duration = 30, color = "white" } = {}) {
631641
if (!flock.scene || !flock.stackPanel) return;
632642

633643
// Validate duration: must be finite and non-negative
634-
const safeDuration = (isFinite(Number(duration)) && Number(duration) >= 0) ? Number(duration) : 0;
644+
const safeDuration =
645+
isFinite(Number(duration)) && Number(duration) >= 0
646+
? Number(duration)
647+
: 0;
635648
duration = safeDuration;
636649

637650
console.log(text);

0 commit comments

Comments
 (0)