feat: 更新机器人状态覆盖图标逻辑,支持新位置参数以解决异步更新延迟问题,并调整编辑服务构造函数以接收场景ID

This commit is contained in:
xudan 2025-09-23 17:54:37 +08:00
parent 9ee0cc394d
commit af9725cc33
2 changed files with 23 additions and 10 deletions

View File

@ -165,7 +165,12 @@ const monitorScene = async () => {
}
// 3. (API)
editor.value?.updateRobotStatusOverlay?.(id, false);
// 使
const newPositionForOverlay =
penUpdatePayload.x !== undefined && penUpdatePayload.y !== undefined
? { x: penUpdatePayload.x, y: penUpdatePayload.y, rotate: penUpdatePayload.rotate }
: undefined;
editor.value?.updateRobotStatusOverlay?.(id, false, newPositionForOverlay);
});
// 4. 使Meta2D
@ -259,7 +264,7 @@ const monitorScene = async () => {
//#region
onMounted(() => {
editor.value = new EditorService(container.value!);
editor.value = new EditorService(container.value!, props.sid);
// editor store
editorStore.setEditor(editor as ShallowRef<EditorService>);

View File

@ -662,8 +662,10 @@ export class EditorService extends Meta2d {
/** 保存从后台传来的所有额外字段除了已处理的robotGroups、robots、points、routes、areas之外的字段 */
#originalSceneData?: Partial<StandardScene>;
#sceneId: string;
public getSceneId(): string | undefined {
return (this.#originalSceneData as any)?.id;
return this.#sceneId;
}
/** 坐标转换方法 - 将左上角原点的坐标转换为中心点原点的坐标 */
@ -1250,8 +1252,13 @@ export class EditorService extends Meta2d {
* //
* @param id ID
* @param render
* @param newPosition
*/
public updateRobotStatusOverlay(id: string, render = false): void {
public updateRobotStatusOverlay(
id: string,
render = false,
newPosition?: { x: number; y: number; rotate: number },
): void {
const pen = this.getPenById(id);
if (!pen) return;
@ -1266,15 +1273,15 @@ export class EditorService extends Meta2d {
// 以机器人中心为基准,做一个轻微向下的偏移,并随机器人一起旋转
const rect = this.getPenRect(pen);
const wr: any = (pen as any).calculative?.worldRect;
const deg: number = (wr?.rotate ?? 0) as number;
const deg: number = newPosition?.rotate ?? pen.rotate ?? 0;
const theta = (deg * Math.PI) / 180;
const cx = rect.x + rect.width / 2;
const cy = rect.y + rect.height / 2;
// 如果有新位置,使用新位置的 x,y + 容器宽高的一半;否则用旧方法
const cx = (newPosition?.x ?? rect.x) + rect.width / 2;
const cy = (newPosition?.y ?? rect.y) + rect.height / 2;
const iconTop = (pen as any).iconTop ?? 0;
// 在本地坐标中的偏移以机器人中心为原点y向下为正
const localDx = 0;
const localDy = iconTop +16;
const localDy = iconTop + 16;
// 旋转后的偏移
const rotDx = localDx * Math.cos(theta) - localDy * Math.sin(theta);
const rotDy = localDx * Math.sin(theta) + localDy * Math.cos(theta);
@ -1743,8 +1750,9 @@ export class EditorService extends Meta2d {
* -
* @param container DOM元素
*/
constructor(container: HTMLDivElement) {
constructor(container: HTMLDivElement, sceneId: string) {
super(container, EDITOR_CONFIG);
this.#sceneId = sceneId;
// 初始化图层管理服务
this.layerManager = new LayerManagerService(this);