refactor(mission card): optimize hero position transfer logic

重构了英雄位置更新的处理逻辑,先收集所有需要转移的英雄再统一处理,同时增加了节点复用和提前隐藏旧节点的逻辑,避免多英雄位置更新时的数据冲突和节点占用问题。
This commit is contained in:
panw
2026-05-13 17:31:08 +08:00
parent d72e161150
commit a332b8f2c9

View File

@@ -966,14 +966,21 @@ export class MissionCardComp extends CCComp {
}
// 2. 然后再处理所有存活英雄的位置转移和信息刷新
// 如果有多个英雄在同一帧发生位置变动,可能会出现目标节点暂时被其他还没更新的英雄占用的情况,
// 为了防止数据互相覆盖,我们先将需要转移的英雄收集起来。
// 如果有多个英雄在同一帧发生位置变动,我们需要统一处理
const needTransfer: Array<{eid: number, expectedNodeIndex: number}> = [];
this.heroInfoItems.forEach((item, eid) => {
// 检查英雄是否改变了位置 (lane 或 lane_index 发生了变化)
const expectedNodeIndex = item.model.lane_index * 3 + item.model.lane + 1;
if (item.comp.node_index !== expectedNodeIndex) {
needTransfer.push({eid, expectedNodeIndex});
// 如果位置变了,需要转移到新的节点上
const newComp = this.cachedHInfoComps.get(expectedNodeIndex);
if (newComp) {
needTransfer.push({eid, expectedNodeIndex});
// 将原来的节点释放,以供其他可能换到这个位置的英雄使用
item.node.active = false;
}
} else {
this.updateHeroInfoPanel(item);
}
@@ -986,8 +993,6 @@ export class MissionCardComp extends CCComp {
const newComp = this.cachedHInfoComps.get(transfer.expectedNodeIndex);
if (newComp) {
// 隐藏旧节点
item.node.active = false;
// 转移到新节点
item.comp = newComp;
item.node = newComp.node;