refactor(elevator): 移除开发环境调试日志和已注释的无效清理函数以精简代码
This commit is contained in:
parent
1294a437b4
commit
d975357f04
@ -570,11 +570,6 @@ onMounted(async () => {
|
|||||||
const stateIndex = elevatorMockTick % elevatorStates.length;
|
const stateIndex = elevatorMockTick % elevatorStates.length;
|
||||||
const state = elevatorStates[stateIndex];
|
const state = elevatorStates[stateIndex];
|
||||||
|
|
||||||
console.log(`[开发环境] 电梯状态变化 #${elevatorMockTick}:`, {
|
|
||||||
floor: state.floor,
|
|
||||||
direction: ['未知', '停止', '向上', '向下'][state.direction],
|
|
||||||
doorStatus: ['未知', '关', '开关门中', '开'][state.doorStatus]
|
|
||||||
});
|
|
||||||
|
|
||||||
elevatorStore.handleElevatorWebSocketData({
|
elevatorStore.handleElevatorWebSocketData({
|
||||||
id: '1998661793706377218',
|
id: '1998661793706377218',
|
||||||
|
|||||||
@ -50,7 +50,7 @@ export const useElevatorStore = defineStore('elevator', () => {
|
|||||||
// 动画相关状态
|
// 动画相关状态
|
||||||
const movingElevators = ref<Set<string>>(new Set());
|
const movingElevators = ref<Set<string>>(new Set());
|
||||||
const animationFrameId = ref<number | null>(null);
|
const animationFrameId = ref<number | null>(null);
|
||||||
const frameCount = ref(0); // 调试用帧计数器
|
const frameCount = ref(0); // 帧计数器
|
||||||
|
|
||||||
// ========== 方法 ==========
|
// ========== 方法 ==========
|
||||||
|
|
||||||
@ -65,25 +65,6 @@ export const useElevatorStore = defineStore('elevator', () => {
|
|||||||
console.log('🛗 电梯Store: 编辑器服务已设置,等待场景加载后构建映射');
|
console.log('🛗 电梯Store: 编辑器服务已设置,等待场景加载后构建映射');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 清理无效的运动电梯(连接断开或方向非运动状态)
|
|
||||||
*/
|
|
||||||
const cleanupInvalidMovingElevators = () => {
|
|
||||||
let hasChanges = false;
|
|
||||||
|
|
||||||
for (const deviceId of movingElevators.value) {
|
|
||||||
const elevatorData = elevators.value.get(deviceId);
|
|
||||||
// 如果电梯数据不存在、连接断开、或方向不是运动状态,则移除
|
|
||||||
if (!elevatorData || !elevatorData.isConnected ||
|
|
||||||
(elevatorData.elevatorDirection !== 2 && elevatorData.elevatorDirection !== 3)) {
|
|
||||||
movingElevators.value.delete(deviceId);
|
|
||||||
hasChanges = true;
|
|
||||||
console.log(`🛗 清理无效运动电梯: ${deviceId}, 连接: ${elevatorData?.isConnected}, 方向: ${elevatorData?.elevatorDirection}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasChanges;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动动画循环(如果尚未启动)
|
* 启动动画循环(如果尚未启动)
|
||||||
@ -95,24 +76,24 @@ export const useElevatorStore = defineStore('elevator', () => {
|
|||||||
frameCount.value++;
|
frameCount.value++;
|
||||||
if (editorService.value) {
|
if (editorService.value) {
|
||||||
// 清理无效的运动电梯
|
// 清理无效的运动电梯
|
||||||
const hadInvalid = cleanupInvalidMovingElevators();
|
// const hadInvalid = cleanupInvalidMovingElevators();
|
||||||
|
|
||||||
if (movingElevators.value.size > 0) {
|
if (movingElevators.value.size > 0) {
|
||||||
// 有运动电梯,触发渲染
|
// 有运动电梯,触发渲染
|
||||||
editorService.value.render();
|
editorService.value.render();
|
||||||
|
|
||||||
// 每60帧打印一次调试信息
|
// 每60帧打印一次调试信息(已禁用)
|
||||||
if (frameCount.value % 60 === 0) {
|
// if (frameCount.value % 60 === 0) {
|
||||||
console.log(`🛗 动画循环运行中,帧: ${frameCount.value}, 运动电梯: ${movingElevators.value.size}`);
|
// console.log(`🛗 动画循环运行中,帧: ${frameCount.value}, 运动电梯: ${movingElevators.value.size}`);
|
||||||
}
|
// }
|
||||||
|
|
||||||
animationFrameId.value = requestAnimationFrame(loop);
|
animationFrameId.value = requestAnimationFrame(loop);
|
||||||
} else {
|
} else {
|
||||||
// 无运动电梯,停止循环
|
// 无运动电梯,停止循环
|
||||||
if (hadInvalid) {
|
// if (hadInvalid) {
|
||||||
console.log('🛗 所有运动电梯已无效,停止动画循环');
|
// console.log('🛗 所有运动电梯已无效,停止动画循环');
|
||||||
}
|
// }
|
||||||
console.log(`🛗 停止电梯动画循环,总帧数: ${frameCount.value}`);
|
// console.log(`🛗 停止电梯动画循环,总帧数: ${frameCount.value}`);
|
||||||
animationFrameId.value = null;
|
animationFrameId.value = null;
|
||||||
frameCount.value = 0;
|
frameCount.value = 0;
|
||||||
}
|
}
|
||||||
@ -122,7 +103,7 @@ export const useElevatorStore = defineStore('elevator', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
animationFrameId.value = requestAnimationFrame(loop);
|
animationFrameId.value = requestAnimationFrame(loop);
|
||||||
console.log('🛗 启动电梯动画循环');
|
// console.log('🛗 启动电梯动画循环');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,10 +130,10 @@ export const useElevatorStore = defineStore('elevator', () => {
|
|||||||
if (isMoving && !wasMoving) {
|
if (isMoving && !wasMoving) {
|
||||||
movingElevators.value.add(deviceId);
|
movingElevators.value.add(deviceId);
|
||||||
startAnimationLoop();
|
startAnimationLoop();
|
||||||
console.log(`🛗 添加运动电梯: ${deviceId}, 方向: ${elevatorData.elevatorDirection}`);
|
// console.log(`🛗 添加运动电梯: ${deviceId}, 方向: ${elevatorData.elevatorDirection}`);
|
||||||
} else if (!isMoving && wasMoving) {
|
} else if (!isMoving && wasMoving) {
|
||||||
movingElevators.value.delete(deviceId);
|
movingElevators.value.delete(deviceId);
|
||||||
console.log(`🛗 移除运动电梯: ${deviceId}, 原因: ${elevatorData ? '连接断开或方向改变' : '数据不存在'}`);
|
// console.log(`🛗 移除运动电梯: ${deviceId}, 原因: ${elevatorData ? '连接断开或方向改变' : '数据不存在'}`);
|
||||||
if (movingElevators.value.size === 0) {
|
if (movingElevators.value.size === 0) {
|
||||||
stopAnimationLoop();
|
stopAnimationLoop();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user