fix(editor-robot): 优化机器人状态覆盖层可见性逻辑,仅在有效位置数据时显示避免初始位置闪烁

This commit is contained in:
xudan 2025-11-28 11:10:03 +08:00
parent d0b7b7180d
commit db5b2275f7

View File

@ -321,16 +321,20 @@ export class EditorRobotService {
const pen = this.ctx.getPenById(id);
if (!pen) return;
// [关键修复] 强制同步可见性,防止因底层库时序问题导致的状态不一致。
// 在回放模式下,上游的 setValue 可能不会立即生效,导致此处的 pen.visible 仍为 false。
if (pen.visible === false) {
// [修复] 只有在机器人有有效位置数据时才设置为可见,避免在初始位置闪烁
const hasValidPosition = (pen.x !== undefined && pen.y !== undefined &&
(pen.x !== 0 || pen.y !== 0)) ||
(newPosition?.x !== undefined && newPosition?.y !== undefined &&
(newPosition.x !== 0 || newPosition.y !== 0));
// 只有在机器人有有效位置且当前不可见时,才设置为可见
if (hasValidPosition && pen.visible === false) {
this.ctx.setValue({ id, visible: true }, { render: false, history: false, doEvent: false });
}
const icon = this.getRobotStatusIcon(pen);
// 鉴于上面已经强制设置了 visible此处直接使用 true 或重新检查 pen.visible 均可。
// 为确保逻辑的健壮性,我们直接使用 true。
const robotVisible = true;
// 机器人可见性取决于是否有有效位置数据
const robotVisible = hasValidPosition;
const baseW = (pen as any).iconWidth ?? 42;
const baseH = (pen as any).iconHeight ?? 76;