début de la classe PiecesFile

This commit is contained in:
2025-02-28 22:32:51 +01:00
parent 26f501f7e8
commit 13ee43167e
11 changed files with 143 additions and 45 deletions

62
src/Core/PiecesList.cpp Normal file
View File

@@ -0,0 +1,62 @@
#include "PiecesList.h"
#include "../Pieces/Piece.h"
#include "../Pieces/PiecesFiles.h"
#include <vector>
#include <utility>
#include <memory>
PiecesList::PiecesList() {
this->maximumLoadedSize = 0;
this->loadedPieces.clear();
this->loadedPieces.push_back(std::vector<Piece>());
this->selectedPieces.clear();
}
bool PiecesList::loadPieces(int size) {
if (size < 1) return false;
PiecesFiles piecesFiles;
std::vector<int> convexPieces;
std::vector<int> holelessPieces;
std::vector<int> otherPieces;
for (int i = this->maximumLoadedSize + 1; i <= size; i++) {
std::vector<Piece> pieces;
this->loadedPieces.push_back(pieces);
if (!piecesFiles.loadPieces(i, this->loadedPieces.at(i), convexPieces, holelessPieces, otherPieces)) {
return false;
}
else {
this->maximumLoadedSize++;
}
}
return true;
}
bool PiecesList::selectPieces(int size, int number) {
if (size < 1 || size > this->maximumLoadedSize || number >= this->loadedPieces.at(size).size()) return false;
this->selectedPieces.push_back(std::pair<int, int>(size, number));
return true;
}
std::vector<std::pair<int, int>> PiecesList::getSelectedPieces() {
return this->selectedPieces;
}
int PiecesList::getNumberOfPiecesOfOneSize(int size) {
if (size < 1 || size > this->maximumLoadedSize) return 0;
return this->loadedPieces.at(size).size();
}
std::shared_ptr<Piece> PiecesList::getPiece(int size, int number) {
if (size < 1 || size > this->maximumLoadedSize || number >= this->loadedPieces.at(size).size()) return nullptr;
return std::make_shared<Piece>(this->loadedPieces.at(size).at(number));
}