feat: 增强机器人状态管理,新增锁定状态处理逻辑,确保机器人可见且未被锁定

This commit is contained in:
xudan 2025-09-10 09:11:20 +08:00
parent db42f4a6d8
commit d270e82c8b
2 changed files with 37 additions and 25 deletions

View File

@ -1,4 +1,5 @@
<script setup lang="ts">
import { LockState } from '@meta2d/core';
import { message } from 'ant-design-vue';
import { isNil } from 'lodash-es';
import { computed, onMounted, onUnmounted, provide, ref, shallowRef, watch } from 'vue';
@ -121,7 +122,7 @@ const monitorScene = async () => {
const newY = y - 60;
// angle
const rotate = angle == null ? undefined : -angle + 180;
return { id, x: newX, y: newY, rotate, visible: true };
return { id, x: newX, y: newY, rotate, visible: true ,locked: LockState.None,};
}
});

View File

@ -1128,33 +1128,43 @@ export class EditorService extends Meta2d {
// 机器人初始化完成后,确保层级正确(机器人应在最顶层)
this.#ensureCorrectLayerOrder();
}
public refreshRobot(id: RobotInfo['id'], info: Partial<RobotRealtimeInfo>): void {
const pen = this.getPenById(id);
const { rotate: or, robot } = pen ?? {};
if (!robot?.type) return;
const { x: ox, y: oy } = this.getPenRect(pen!);
const { x: cx = 37, y: cy = 37, active, angle, path: points, isWaring, isFault } = info;
const x = cx - 60;
const y = cy - 60;
const rotate = angle ?? or;
const path =
points?.map((p) => ({ x: p.x - cx, y: p.y - cy })) ??
robot.path?.map((p) => ({ x: p.x + ox! - x, y: p.y + oy! - y }));
const o = { ...robot, ...omitBy({ active, path, isWaring, isFault }, isNil) };
if (isNil(active)) {
this.setValue({ id, x, y, rotate, robot: o, visible: true }, { render: true, history: false, doEvent: false });
} else {
this.setValue(
{ id, ...this.#mapRobotImage(robot.type, active), x, y, rotate, robot: o, visible: true },
{ render: true, history: false, doEvent: false },
);
}
// public refreshRobot(id: RobotInfo['id'], info: Partial<RobotRealtimeInfo>): void {
// const pen = this.getPenById(id);
// const { rotate: or, robot } = pen ?? {};
// if (!robot?.type) return;
// const { x: ox, y: oy } = this.getPenRect(pen!);
// const { x: cx = 37, y: cy = 37, active, angle, path: points, isWaring, isFault } = info;
// const x = cx - 60;
// const y = cy - 60;
// const rotate = angle ?? or;
// const path =
// points?.map((p) => ({ x: p.x - cx, y: p.y - cy })) ??
// robot.path?.map((p) => ({ x: p.x + ox! - x, y: p.y + oy! - y }));
// const o = { ...robot, ...omitBy({ active, path, isWaring, isFault }, isNil) };
// if (isNil(active)) {
// this.setValue(
// { id, x, y, rotate, robot: o, visible: true, locked: LockState.None },
// { render: true, history: false, doEvent: false }
// );
// } else {
// this.setValue(
// {
// id,
// ...this.#mapRobotImage(robot.type, active),
// x, y, rotate, robot: o,
// visible: true,
// locked: LockState.None
// },
// { render: true, history: false, doEvent: false },
// );
// }
// 机器人位置更新后,确保层级正确(机器人应在最顶层)
this.#ensureCorrectLayerOrder();
}
// }
/**
*
@ -1178,6 +1188,7 @@ export class EditorService extends Meta2d {
});
}
#mapRobotImage(
type: RobotType,
active?: boolean,