Fix after disconnect the change of parentID bug

This commit is contained in:
2025-12-07 12:06:40 +08:00
parent a6403953ef
commit a66c70f0b7
3 changed files with 143 additions and 19 deletions

View File

@@ -136,8 +136,24 @@ int Board::getComponentID(int row, int col) const{
}
std::unordered_set<int> Board::getComponentByPieceID(int PieceID) const {
std::cout << "DEBUG: getComponentByPieceID(" << PieceID << ")" << std::endl;
// 检查该位置是否有棋子
auto [row, col] = getCoordFromID(PieceID);
if (getPieceAt(row, col) == nullptr) {
std::cout << "this postion don't have piece\n";
return std::unordered_set<int>(); // 返回空集合
}
// 检查 ComponentManager 的状态
int componentID = m_component->getComponentID(PieceID);
std::cout << "DEBUG: componentID = " << componentID << std::endl;
// 临时选中组件
m_component->selectComponentByPiece(PieceID);
auto SelectedComponent = m_component->getSelectedComponent();
// 立即清除选中状态
m_component->clearSelection();
std::cout << "DEBUG: Component size = " << SelectedComponent.size() << std::endl;
return SelectedComponent;
}