Files
jminos/src/Core/PiecesList.h
2025-03-01 18:24:09 +01:00

95 lines
2.8 KiB
C++

#pragma once
#include "../Pieces/Piece.h"
#include <vector>
#include <utility>
/**
* A container for all loaded pieces to prevent loading and copying them multiple times,
* also allows for the player to select a list of pieces to be used in a game
*/
class PiecesList {
private:
int highestLoadedSize; // the highest size of pieces currently loaded
std::vector<std::vector<Piece>> loadedPieces; // every loaded pieces by size
std::vector<std::vector<int>> convexPieces; // the list of convex loaded pieces by size
std::vector<std::vector<int>> holelessPieces; // the list of holeless loaded pieces by size
std::vector<std::vector<int>> otherPieces; // the list of other loaded pieces by size
std::vector<std::pair<int, int>> selectedPieces; // the list of all currently selected pieces
public:
/**
* Initializes a list of pieces up to size 0 (so no pieces)
*/
PiecesList();
/**
* Makes the list load all pieces of the specified size
* @return If it sucessfully loaded the pieces
*/
bool loadPieces(int size);
/**
* Selects the specified piece
* @return If the piece could be selected
*/
bool selectPiece(int size, int number);
/**
* Selects all pieces of the specified size
* @return If the pieces could be selected
*/
bool selectAllPieces(int size);
/**
* Selects all convex pieces of the specified size
* @return If the pieces could be selected
*/
bool selectConvexPieces(int size);
/**
* Selects all holeless pieces of the specified size
* @return If the pieces could be selected
*/
bool selectHolelessPieces(int size);
/**
* Selects all other pieces of the specified size
* @return If the pieces could be selected
*/
bool selectOtherPieces(int size);
/**
* Unselects all previously selected pieces
*/
void unselectAll();
/**
* @return The highest loaded size of pieces
*/
int getHighestLoadedSize();
/**
* @return The number of pieces of the specified size
*/
int getNumberOfPieces(int size);
/**
* @return The indexes of all selected pieces
*/
std::vector<std::pair<int, int>> getSelectedPieces();
/**
* @return The piece corresponding to the specified index
*/
Piece getPiece(std::pair<int, int> pieceIndex);
private:
/**
* Adds empty vectors at the end of every pieces list
*/
void pushBackEmptyVectors();
};