Compare commits
2 Commits
d5ac79559e
...
46ebb88ef2
| Author | SHA1 | Date | |
|---|---|---|---|
| 46ebb88ef2 | |||
| de14978b01 |
@@ -55,5 +55,5 @@ The settings file has the following format:
|
|||||||
- For every single piece, use 1 byte for (the size + encoding that it is a single piece),
|
- For every single piece, use 1 byte for (the size + encoding that it is a single piece),
|
||||||
and 3 bytes to store the number of the piece (allows number up to 16M, size 15 has 6M pieces).
|
and 3 bytes to store the number of the piece (allows number up to 16M, size 15 has 6M pieces).
|
||||||
|
|
||||||
The current file format version is 10.
|
The current file format version is 11.
|
||||||
If the file starts with a number lower than that, it will be regenerated upon launching the game.
|
If the file starts with a number lower than that, it will be regenerated upon launching the game.
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ PiecesList::PiecesList() {
|
|||||||
|
|
||||||
bool PiecesList::loadPieces(int size) {
|
bool PiecesList::loadPieces(int size) {
|
||||||
if (size < 1) return false;
|
if (size < 1) return false;
|
||||||
|
if (size <= this->highestLoadedSize) return true;
|
||||||
|
|
||||||
PiecesFiles piecesFiles;
|
PiecesFiles piecesFiles;
|
||||||
for (int i = this->highestLoadedSize + 1; i <= size; i++) {
|
for (int i = this->highestLoadedSize + 1; i <= size; i++) {
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ GamePiecesAppMenu::GamePiecesAppMenu(std::shared_ptr<MenuStack> menuStack, std::
|
|||||||
for (int i = 1; i <= this->settings->getMaximumPiecesSize(); i++) {
|
for (int i = 1; i <= this->settings->getMaximumPiecesSize(); i++) {
|
||||||
this->playerCursor.addRow(i + 1, this->settings->getMenu().readPiecesList().getNumberOfPieces(i) + 4);
|
this->playerCursor.addRow(i + 1, this->settings->getMenu().readPiecesList().getNumberOfPieces(i) + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->settings->getMaximumPiecesSize() < GENERATED_PIECES_SIZE) {
|
||||||
|
this->playerCursor.addRow(this->settings->getMaximumPiecesSize() + 2, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamePiecesAppMenu::computeFrame() {
|
void GamePiecesAppMenu::computeFrame() {
|
||||||
@@ -30,7 +34,20 @@ void GamePiecesAppMenu::computeFrame() {
|
|||||||
if (this->playerCursor.getPosition().y == 0) {
|
if (this->playerCursor.getPosition().y == 0) {
|
||||||
this->menuStack->push(std::make_shared<GameDistributionAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
this->menuStack->push(std::make_shared<GameDistributionAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||||
}
|
}
|
||||||
if (this->playerCursor.getPosition().y > 1) {
|
|
||||||
|
if (this->playerCursor.getPosition().y == (this->settings->getMaximumPiecesSize() + 2)) {
|
||||||
|
int newMaxSize = this->settings->getMaximumPiecesSize() + 1;
|
||||||
|
this->settings->loadPieces(newMaxSize);
|
||||||
|
|
||||||
|
this->playerCursor.removeRow(newMaxSize + 1);
|
||||||
|
this->playerCursor.addRow(newMaxSize + 1, this->settings->getMenu().readPiecesList().getNumberOfPieces(newMaxSize) + 4);
|
||||||
|
this->playerCursor.goToPosition({0u, newMaxSize + 1u});
|
||||||
|
|
||||||
|
if (newMaxSize < GENERATED_PIECES_SIZE) {
|
||||||
|
this->playerCursor.addRow(newMaxSize + 2, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this->playerCursor.getPosition().y > 1) {
|
||||||
if (this->playerCursor.getPosition().x >= 4) {
|
if (this->playerCursor.getPosition().x >= 4) {
|
||||||
this->settings->selectPieces(createSinglePieceType(this->playerCursor.getPosition().y - 1), this->playerCursor.getPosition().x - 4);
|
this->settings->selectPieces(createSinglePieceType(this->playerCursor.getPosition().y - 1), this->playerCursor.getPosition().x - 4);
|
||||||
}
|
}
|
||||||
@@ -78,7 +95,8 @@ void GamePiecesAppMenu::drawFrame() const {
|
|||||||
this->drawSelectedPiecesRow(15.f);
|
this->drawSelectedPiecesRow(15.f);
|
||||||
|
|
||||||
bool drawFromFirstElem = (this->playerCursor.getPosition().y == 1);
|
bool drawFromFirstElem = (this->playerCursor.getPosition().y == 1);
|
||||||
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, this->settings->getMaximumPiecesSize() - 2);
|
bool addExtraLine = (this->settings->getMaximumPiecesSize() < GENERATED_PIECES_SIZE);
|
||||||
|
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, this->settings->getMaximumPiecesSize() - 2 + (addExtraLine ? 1 : 0));
|
||||||
this->drawRow(firstElem, 25.f, drawFromFirstElem);
|
this->drawRow(firstElem, 25.f, drawFromFirstElem);
|
||||||
this->drawRow(firstElem + 1, 35.f, drawFromFirstElem);
|
this->drawRow(firstElem + 1, 35.f, drawFromFirstElem);
|
||||||
this->drawRow(firstElem + 2, 45.f, drawFromFirstElem);
|
this->drawRow(firstElem + 2, 45.f, drawFromFirstElem);
|
||||||
@@ -112,6 +130,7 @@ void GamePiecesAppMenu::drawSelectedPiecesRow(float yPos) const {
|
|||||||
|
|
||||||
int pieceSize = getSizeOfPieces(pieceType);
|
int pieceSize = getSizeOfPieces(pieceType);
|
||||||
if (pieceSize > 0) {
|
if (pieceSize > 0) {
|
||||||
|
if (!(pieceSize > this->settings->getMaximumPiecesSize())) {
|
||||||
const Piece& piece = this->settings->getMenu().readPiecesList().lookAtPiece({pieceSize, value});
|
const Piece& piece = this->settings->getMenu().readPiecesList().lookAtPiece({pieceSize, value});
|
||||||
int cellSize = (8 * this->settings->getWindowSizeMultiplier()) / (piece.getLength());
|
int cellSize = (8 * this->settings->getWindowSizeMultiplier()) / (piece.getLength());
|
||||||
sf::FloatRect piecePosition(sf::Vector2f(xProgress, yPos - 4.f) * (float) this->settings->getWindowSizeMultiplier(), sf::Vector2f(8 , 8) * (float) this->settings->getWindowSizeMultiplier());
|
sf::FloatRect piecePosition(sf::Vector2f(xProgress, yPos - 4.f) * (float) this->settings->getWindowSizeMultiplier(), sf::Vector2f(8 , 8) * (float) this->settings->getWindowSizeMultiplier());
|
||||||
@@ -119,15 +138,51 @@ void GamePiecesAppMenu::drawSelectedPiecesRow(float yPos) const {
|
|||||||
xProgress += (1.f + 8.f);
|
xProgress += (1.f + 8.f);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
this->placeText(text, {}, "ERROR_UNSUPPORTED", xProgress, yPos, {});
|
||||||
|
xProgress += (1.f + (text.getGlobalBounds().size.x / this->settings->getWindowSizeMultiplier()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!(value > this->settings->getMaximumPiecesSize())) {
|
||||||
this->placeText(text, {}, ((first) ? "" : " ") + getPiecesTypeName(pieceType) + "_" + std::to_string(value), xProgress, yPos, {});
|
this->placeText(text, {}, ((first) ? "" : " ") + getPiecesTypeName(pieceType) + "_" + std::to_string(value), xProgress, yPos, {});
|
||||||
xProgress += (1.f + (text.getGlobalBounds().size.x / this->settings->getWindowSizeMultiplier()));
|
xProgress += (1.f + (text.getGlobalBounds().size.x / this->settings->getWindowSizeMultiplier()));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
this->placeText(text, {}, "ERROR_UNSUPPORTED", xProgress, yPos, {});
|
||||||
|
xProgress += (1.f + (text.getGlobalBounds().size.x / this->settings->getWindowSizeMultiplier()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
elem++;
|
elem++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamePiecesAppMenu::drawRow(int piecesSize, float yPos, bool drawFromFirstElem) const {
|
void GamePiecesAppMenu::drawRow(int piecesSize, float yPos, bool drawFromFirstElem) const {
|
||||||
|
if (piecesSize > this->settings->getMaximumPiecesSize()) {
|
||||||
|
sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2);
|
||||||
|
text.setOutlineThickness(this->settings->getWindowSizeMultiplier() / 2);
|
||||||
|
if (this->playerCursor.getPosition().y == (piecesSize + 1)) {
|
||||||
|
text.setOutlineColor({255, 255, 255});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
text.setOutlineColor({0, 0, 0});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string sizeString = "LOAD SIZE " + std::to_string(piecesSize) + "? ";
|
||||||
|
if (piecesSize <= 10) {
|
||||||
|
text.setFillColor({0, 255, 0});
|
||||||
|
this->placeText(text, {}, sizeString + "(LOW LOAD TIME)", 1.f, yPos, {});
|
||||||
|
}
|
||||||
|
else if (piecesSize <= 13) {
|
||||||
|
text.setFillColor({255, 255, 0});
|
||||||
|
this->placeText(text, {}, sizeString + "(MEDIUM LOAD TIME)", 1.f, yPos, {});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
text.setFillColor({255, 0, 0});
|
||||||
|
this->placeText(text, {}, sizeString + "(LONG LOAD TIME)", 1.f, yPos, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
int numberOfPieces = this->settings->getMenu().readPiecesList().getNumberOfPieces(piecesSize);
|
int numberOfPieces = this->settings->getMenu().readPiecesList().getNumberOfPieces(piecesSize);
|
||||||
int firstElem = (drawFromFirstElem) ? -4 : std::max(((int) this->playerCursor.getPosition().x) - 7, -4);
|
int firstElem = (drawFromFirstElem) ? -4 : std::max(((int) this->playerCursor.getPosition().x) - 7, -4);
|
||||||
|
|
||||||
@@ -155,6 +210,7 @@ void GamePiecesAppMenu::drawRow(int piecesSize, float yPos, bool drawFromFirstEl
|
|||||||
this->drawPiece(piece, cellSize, piecePosition, this->playerCursor.getPosition() == sf::Vector2u{i + firstElem + 4u, piecesSize + 1u});
|
this->drawPiece(piece, cellSize, piecePosition, this->playerCursor.getPosition() == sf::Vector2u{i + firstElem + 4u, piecesSize + 1u});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamePiecesAppMenu::drawPiece(const Piece& piece, int cellSize, const sf::FloatRect& piecePosition, bool selected) const {
|
void GamePiecesAppMenu::drawPiece(const Piece& piece, int cellSize, const sf::FloatRect& piecePosition, bool selected) const {
|
||||||
|
|||||||
@@ -6,14 +6,15 @@
|
|||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <algorithm>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
StartUpAppMenu::StartUpAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
StartUpAppMenu::StartUpAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
||||||
AppMenu(menuStack, settings, renderWindow),
|
AppMenu(menuStack, settings, renderWindow),
|
||||||
playerCursor({LOADED_PIECES_SIZE + 1}) {
|
playerCursor({GENERATED_PIECES_SIZE + 1}) {
|
||||||
|
|
||||||
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
|
this->playerCursor.goToPosition({(unsigned int) std::clamp(this->settings->getMaximumPiecesSize(), MINIMUM_PIECES_SIZE, GENERATED_PIECES_SIZE), 0u});
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartUpAppMenu::computeFrame() {
|
void StartUpAppMenu::computeFrame() {
|
||||||
@@ -22,7 +23,7 @@ void StartUpAppMenu::computeFrame() {
|
|||||||
|
|
||||||
if (this->playerCursor.getPosition().x < MINIMUM_PIECES_SIZE) {
|
if (this->playerCursor.getPosition().x < MINIMUM_PIECES_SIZE) {
|
||||||
if (this->playerCursor.movedLeft()) {
|
if (this->playerCursor.movedLeft()) {
|
||||||
this->playerCursor.goToPosition({LOADED_PIECES_SIZE, 0});
|
this->playerCursor.goToPosition({GENERATED_PIECES_SIZE, 0});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
|
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
|
||||||
@@ -30,7 +31,7 @@ void StartUpAppMenu::computeFrame() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this->enterReleased) {
|
if (this->enterReleased) {
|
||||||
*this->settings = Settings(this->playerCursor.getPosition().x);
|
this->settings->loadSettingsFromFile(true, {this->playerCursor.getPosition().x});
|
||||||
this->menuStack->pop();
|
this->menuStack->pop();
|
||||||
|
|
||||||
if (this->settings->hasLoadedPieces()) {
|
if (this->settings->hasLoadedPieces()) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND);
|
|||||||
|
|
||||||
|
|
||||||
GraphApp::GraphApp() {
|
GraphApp::GraphApp() {
|
||||||
this->settings = std::make_shared<Settings>(0);
|
this->settings = std::make_shared<Settings>(false);
|
||||||
this->menuStack = std::make_shared<MenuStack>();
|
this->menuStack = std::make_shared<MenuStack>();
|
||||||
this->renderWindow = std::make_shared<sf::RenderWindow>();
|
this->renderWindow = std::make_shared<sf::RenderWindow>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "PiecesType.h"
|
#include "PiecesType.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <optional>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
@@ -17,20 +18,21 @@ static const int DISTRIBUTION_MAX = 20;
|
|||||||
|
|
||||||
|
|
||||||
Settings::Settings(bool loadPieces) {
|
Settings::Settings(bool loadPieces) {
|
||||||
|
this->keybinds.clear();
|
||||||
this->keybinds.reserve(NUMBER_OF_KEYBINDS);
|
this->keybinds.reserve(NUMBER_OF_KEYBINDS);
|
||||||
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
||||||
this->keybinds.emplace_back(i);
|
this->keybinds.emplace_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->loadSettingsFromFile(loadPieces);
|
this->loadSettingsFromFile(loadPieces, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::loadPieces(int maximumPiecesSizeRequest) {
|
void Settings::loadPieces(int maximumPiecesSizeRequest) {
|
||||||
if (maximumPiecesSizeRequest < MINIMUM_PIECES_SIZE) {
|
if (maximumPiecesSizeRequest < MINIMUM_PIECES_SIZE) {
|
||||||
maximumPiecesSizeRequest = MINIMUM_PIECES_SIZE;
|
maximumPiecesSizeRequest = MINIMUM_PIECES_SIZE;
|
||||||
}
|
}
|
||||||
else if (maximumPiecesSizeRequest > LOADED_PIECES_SIZE || maximumPiecesSizeRequest > MAXIMUM_PIECES_SIZE) {
|
else if (maximumPiecesSizeRequest > GENERATED_PIECES_SIZE || maximumPiecesSizeRequest > MAXIMUM_PIECES_SIZE) {
|
||||||
maximumPiecesSizeRequest = LOADED_PIECES_SIZE;
|
maximumPiecesSizeRequest = GENERATED_PIECES_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool succeeded = true;
|
bool succeeded = true;
|
||||||
@@ -40,12 +42,13 @@ bool Settings::loadPieces(int maximumPiecesSizeRequest) {
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->maximumPiecesSize = (succeeded) ? maximumPiecesSizeRequest : 0;
|
if (succeeded) {
|
||||||
return succeeded;
|
this->maximumPiecesSize = maximumPiecesSizeRequest;
|
||||||
|
}
|
||||||
|
this->loadedPieces = succeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::loadSettingsFromFile(bool loadPieces) {
|
void Settings::loadSettingsFromFile(bool loadPieces, std::optional<int> maximumPiecesSizeRequest) {
|
||||||
std::ifstream settingsFile("data/config/settings.bin", std::ios::binary);
|
std::ifstream settingsFile("data/config/settings.bin", std::ios::binary);
|
||||||
char byte;
|
char byte;
|
||||||
|
|
||||||
@@ -54,8 +57,15 @@ void Settings::loadSettingsFromFile(bool loadPieces) {
|
|||||||
|
|
||||||
// maximum pieces size
|
// maximum pieces size
|
||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
|
this->maximumPiecesSize = byte;
|
||||||
|
|
||||||
if (loadPieces) {
|
if (loadPieces) {
|
||||||
this->loadedPieces = this->loadPieces(byte);
|
if (maximumPiecesSizeRequest.has_value()) {
|
||||||
|
this->loadPieces(maximumPiecesSizeRequest.value());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->loadPieces(byte);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->loadedPieces = false;
|
this->loadedPieces = false;
|
||||||
@@ -124,20 +134,17 @@ void Settings::loadSettingsFromFile(bool loadPieces) {
|
|||||||
if (getSizeOfPieces(PiecesType(pieceType)) == 0) {
|
if (getSizeOfPieces(PiecesType(pieceType)) == 0) {
|
||||||
settingsFile.get(pieceSize);
|
settingsFile.get(pieceSize);
|
||||||
|
|
||||||
if (!(pieceSize > this->maximumPiecesSize)) {
|
|
||||||
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceSize);
|
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceSize);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
if (!(getSizeOfPieces(PiecesType(pieceType)) > this->maximumPiecesSize)) {
|
|
||||||
settingsFile.get(lowByte);
|
settingsFile.get(lowByte);
|
||||||
settingsFile.get(midByte);
|
settingsFile.get(midByte);
|
||||||
settingsFile.get(highByte);
|
settingsFile.get(highByte);
|
||||||
|
|
||||||
int pieceNumber = ((unsigned char) lowByte) + ((unsigned char) midByte << 8) + ((unsigned char) highByte << 16);
|
int pieceNumber = ((unsigned char) lowByte) + ((unsigned char) midByte << 8) + ((unsigned char) highByte << 16);
|
||||||
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceNumber);
|
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this->confirmSelectedPieces();
|
this->confirmSelectedPieces();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -309,25 +316,33 @@ void Settings::confirmSelectedPieces() {
|
|||||||
|
|
||||||
this->menu.getPiecesList().unselectAll();
|
this->menu.getPiecesList().unselectAll();
|
||||||
|
|
||||||
if (this->getSelectedPieces().size() == 0) {
|
bool selectedNone = true;
|
||||||
this->selectedPieces.push_back(DEFAULT_SELECTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& [type, value] : this->selectedPieces) {
|
for (const auto& [type, value] : this->selectedPieces) {
|
||||||
int size = getSizeOfPieces(type);
|
int size = getSizeOfPieces(type);
|
||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
|
if (!(value > this->maximumPiecesSize)) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CONVEX_PIECES : {this->menu.getPiecesList().selectConvexPieces(value); break;}
|
case CONVEX_PIECES : {this->menu.getPiecesList().selectConvexPieces(value); break;}
|
||||||
case HOLELESS_PIECES : {this->menu.getPiecesList().selectHolelessPieces(value); break;}
|
case HOLELESS_PIECES : {this->menu.getPiecesList().selectHolelessPieces(value); break;}
|
||||||
case OTHER_PIECES : {this->menu.getPiecesList().selectOtherPieces(value); break;}
|
case OTHER_PIECES : {this->menu.getPiecesList().selectOtherPieces(value); break;}
|
||||||
case ALL_PIECES : {this->menu.getPiecesList().selectAllPieces(value); break;}
|
case ALL_PIECES : {this->menu.getPiecesList().selectAllPieces(value); break;}
|
||||||
}
|
}
|
||||||
|
selectedNone = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (!(getSizeOfPieces(type) > this->maximumPiecesSize)) {
|
||||||
this->menu.getPiecesList().selectPiece(size, value);
|
this->menu.getPiecesList().selectPiece(size, value);
|
||||||
|
selectedNone = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedNone) {
|
||||||
|
this->selectedPieces.push_back(DEFAULT_SELECTION);
|
||||||
|
this->confirmSelectedPieces();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::increaseDistribution(int size) {
|
bool Settings::increaseDistribution(int size) {
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
#include "PiecesType.h"
|
#include "PiecesType.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <optional>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
static const int CURRENT_FILE_FORMAT_VERSION = 10;
|
static const int CURRENT_FILE_FORMAT_VERSION = 11;
|
||||||
|
|
||||||
static const int MAXIMUM_BOARD_WIDTH = 40;
|
static const int MAXIMUM_BOARD_WIDTH = 40;
|
||||||
static const int MAXIMUM_BOARD_HEIGHT = 40;
|
static const int MAXIMUM_BOARD_HEIGHT = 40;
|
||||||
@@ -15,11 +16,11 @@ static const int MAXIMUM_BOARD_HEIGHT = 40;
|
|||||||
static const int MINIMUM_PIECES_SIZE = 4;
|
static const int MINIMUM_PIECES_SIZE = 4;
|
||||||
static const int MAXIMUM_PIECES_SIZE = 15;
|
static const int MAXIMUM_PIECES_SIZE = 15;
|
||||||
|
|
||||||
//#define __JMINOS_RELEASE__
|
#define __JMINOS_RELEASE__
|
||||||
#ifdef __JMINOS_RELEASE__
|
#ifdef __JMINOS_RELEASE__
|
||||||
static const int LOADED_PIECES_SIZE = 15;
|
static const int GENERATED_PIECES_SIZE = 15;
|
||||||
#else
|
#else
|
||||||
static const int LOADED_PIECES_SIZE = 10;
|
static const int GENERATED_PIECES_SIZE = 10;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const std::pair<PiecesType, int> DEFAULT_SELECTION = {ALL_PIECES, MINIMUM_PIECES_SIZE};
|
static const std::pair<PiecesType, int> DEFAULT_SELECTION = {ALL_PIECES, MINIMUM_PIECES_SIZE};
|
||||||
@@ -41,11 +42,9 @@ class Settings {
|
|||||||
public:
|
public:
|
||||||
Settings(bool loadPieces);
|
Settings(bool loadPieces);
|
||||||
|
|
||||||
private:
|
void loadPieces(int maximumPiecesSizeRequest);
|
||||||
bool loadPieces(int maximumPiecesSizeRequest);
|
|
||||||
|
|
||||||
public:
|
void loadSettingsFromFile(bool loadPieces, std::optional<int> maximumPiecesSizeRequest);
|
||||||
void loadSettingsFromFile(bool loadPieces = true);
|
|
||||||
|
|
||||||
void saveSettingsToFile() const;
|
void saveSettingsToFile() const;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ int main() {
|
|||||||
std::srand(std::time(NULL));
|
std::srand(std::time(NULL));
|
||||||
|
|
||||||
PiecesFiles pf;
|
PiecesFiles pf;
|
||||||
for (int i = 1; i <= LOADED_PIECES_SIZE; i++) {
|
for (int i = 1; i <= GENERATED_PIECES_SIZE; i++) {
|
||||||
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
|
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
|
||||||
std::cout << "pieces files for size " << i << " not found, generating..." << std::endl;
|
std::cout << "pieces files for size " << i << " not found, generating..." << std::endl;
|
||||||
pf.savePieces(i);
|
pf.savePieces(i);
|
||||||
@@ -30,7 +30,11 @@ int main() {
|
|||||||
|
|
||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
if ((unsigned char) byte < CURRENT_FILE_FORMAT_VERSION) {
|
if ((unsigned char) byte < CURRENT_FILE_FORMAT_VERSION) {
|
||||||
|
std::cout << "files format changed, regenerating..." << std::endl;
|
||||||
resetSettingsFile();
|
resetSettingsFile();
|
||||||
|
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
||||||
|
resetKeybindFile(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user