feat: 增强机器人状态管理,新增锁定状态处理逻辑,确保机器人可见且未被锁定
This commit is contained in:
parent
db42f4a6d8
commit
d270e82c8b
@ -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,};
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user