added distribution modes
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
static const sf::Vector2u BASE_WINDOW_SIZE = {80, 50};
|
||||
static const int WINDOW_SIZE_MULTIPLIERS[] = {4, 6, 10, 14, 20, 30, 40};
|
||||
static const int WINDOW_SIZE_LAST_MODE = (sizeof(WINDOW_SIZE_MULTIPLIERS) / sizeof(int)) - 1;
|
||||
static const int START_TIMER_MAX = 4;
|
||||
static const int DISTRIBUTION_MAX = 10;
|
||||
|
||||
|
||||
Settings::Settings() {
|
||||
@@ -67,13 +69,20 @@ void Settings::loadSettingsFromFile() {
|
||||
|
||||
// piece distribution
|
||||
settingsFile.get(byte);
|
||||
//TODO
|
||||
if (byte == 2) {
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
this->menu.getPiecesList().setDistributionMode(PiecesDistributionMode(byte));
|
||||
|
||||
this->distributions.clear();
|
||||
this->distributions.push_back(0);
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
if (byte == CUSTOM) {
|
||||
settingsFile.get(byte);
|
||||
//TODO
|
||||
this->distributions.push_back(i);
|
||||
}
|
||||
else {
|
||||
this->distributions.push_back(1);
|
||||
}
|
||||
}
|
||||
this->confirmDistribution();
|
||||
|
||||
// selected pieces
|
||||
char pieceType;
|
||||
@@ -131,9 +140,16 @@ void Settings::saveSettingsToFile() const {
|
||||
settingsFile.write(&byte, 1);
|
||||
|
||||
// piece distribution
|
||||
//TODO
|
||||
byte = this->menu.readPiecesList().getDistributionMode();
|
||||
settingsFile.write(&byte, 1);
|
||||
|
||||
if (this->menu.readPiecesList().getDistributionMode() == CUSTOM) {
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
byte = this->distributions.at(i);
|
||||
settingsFile.write(&byte, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// selected pieces
|
||||
for (const auto& [type, value] : this->selectedPieces) {
|
||||
byte = type;
|
||||
@@ -189,7 +205,7 @@ void Settings::changeVideoMode(sf::RenderWindow& window) const {
|
||||
}
|
||||
|
||||
bool Settings::lengthenStartTimer() {
|
||||
if (this->startTimerLength < 4) {
|
||||
if (this->startTimerLength < START_TIMER_MAX) {
|
||||
this->startTimerLength++;
|
||||
return true;
|
||||
}
|
||||
@@ -240,6 +256,36 @@ void Settings::confirmSelectedPieces() {
|
||||
}
|
||||
}
|
||||
|
||||
bool Settings::setDistributionMode (PiecesDistributionMode distributionMode) {
|
||||
return this->menu.getPiecesList().setDistributionMode(distributionMode);
|
||||
}
|
||||
|
||||
bool Settings::increaseDistribution(int size) {
|
||||
if (size < 1 || size > MAXIMUM_PIECES_SIZE) return false;
|
||||
|
||||
if (this->distributions.at(size) < DISTRIBUTION_MAX) {
|
||||
this->distributions.at(size)++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Settings::decreaseDistribution(int size) {
|
||||
if (size < 1 || size > MAXIMUM_PIECES_SIZE) return false;
|
||||
|
||||
if (this->distributions.at(size) > 0) {
|
||||
this->distributions.at(size)--;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Settings::confirmDistribution() {
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
this->menu.getPiecesList().changeCustomDistribution(i, (double) this->distributions.at(i) / (DISTRIBUTION_MAX + 0.001));
|
||||
}
|
||||
}
|
||||
|
||||
Menu& Settings::getMenu() {
|
||||
return this->menu;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user