variable max polyo size

This commit is contained in:
2025-03-31 14:12:36 +02:00
parent 6bff555cbc
commit 1a95765877
9 changed files with 87 additions and 35 deletions

View File

@@ -12,7 +12,7 @@ GameDistributionAppMenu::GameDistributionAppMenu(std::shared_ptr<MenuStack> menu
AppMenu(menuStack, settings, renderWindow), AppMenu(menuStack, settings, renderWindow),
playerCursor({1}) { playerCursor({1}) {
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) { for (int i = 1; i <= this->settings->getMaximumPiecesSize(); i++) {
this->playerCursor.addRow(i, 1); this->playerCursor.addRow(i, 1);
} }
} }
@@ -65,7 +65,7 @@ void GameDistributionAppMenu::drawFrame() const {
const DistributionMode distributionMode = this->settings->getMenu().readPiecesList().getDistributionMode(); const DistributionMode distributionMode = this->settings->getMenu().readPiecesList().getDistributionMode();
const std::vector<int>& distributions = this->settings->getDistributions(); const std::vector<int>& distributions = this->settings->getDistributions();
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 1, 0, MAXIMUM_PIECES_SIZE - 3); int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 1, 0, this->settings->getMaximumPiecesSize() - 3);
if (firstElem == 0) { if (firstElem == 0) {
this->placeText(text, this->playerCursor, "< DISTRIBUTION MODE: " + getPiecesDistributionName(distributionMode) + " >", 5.f, 15.f, sf::Vector2u{0, 0}); this->placeText(text, this->playerCursor, "< DISTRIBUTION MODE: " + getPiecesDistributionName(distributionMode) + " >", 5.f, 15.f, sf::Vector2u{0, 0});
} }

View File

@@ -13,7 +13,7 @@ GamePiecesAppMenu::GamePiecesAppMenu(std::shared_ptr<MenuStack> menuStack, std::
AppMenu(menuStack, settings, renderWindow), AppMenu(menuStack, settings, renderWindow),
playerCursor({1, (unsigned int) this->settings->getSelectedPieces().size() + 1u}) { playerCursor({1, (unsigned int) this->settings->getSelectedPieces().size() + 1u}) {
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; 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);
} }
} }
@@ -53,11 +53,7 @@ void GamePiecesAppMenu::computeFrame() {
} }
} }
else { else {
if (this->settings->getSelectedPieces().size() == 0) {
this->settings->selectPieces(ALL_PIECES, 4);
}
this->settings->confirmSelectedPieces(); this->settings->confirmSelectedPieces();
this->menuStack->pop(); this->menuStack->pop();
} }
} }
@@ -82,7 +78,7 @@ 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, MAXIMUM_PIECES_SIZE - 2); int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, this->settings->getMaximumPiecesSize() - 2);
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);

View File

@@ -11,8 +11,8 @@
static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND); static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND);
GraphApp::GraphApp() { GraphApp::GraphApp(int maximumPiecesSize) {
this->settings = std::make_shared<Settings>(); this->settings = std::make_shared<Settings>(maximumPiecesSize);
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>();
} }

View File

@@ -15,7 +15,7 @@ class GraphApp {
std::shared_ptr<sf::RenderWindow> renderWindow; std::shared_ptr<sf::RenderWindow> renderWindow;
public: public:
GraphApp(); GraphApp(int maximumPiecesSize);
void run(); void run();
}; };

View File

@@ -14,8 +14,9 @@ static const int START_TIMER_MAX = 4;
static const int DISTRIBUTION_MAX = 10; static const int DISTRIBUTION_MAX = 10;
Settings::Settings() { Settings::Settings(int maximumPiecesSize) {
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) { this->maximumPiecesSize = maximumPiecesSize;
for (int i = 1; i <= this->maximumPiecesSize; i++) {
this->menu.getPiecesList().loadPieces(i); this->menu.getPiecesList().loadPieces(i);
} }
@@ -81,7 +82,7 @@ void Settings::loadSettingsFromFile() {
// selected pieces // selected pieces
char pieceType; char pieceType;
char pieceValue; char pieceSize;
char lowByte; char lowByte;
char midByte; char midByte;
char highByte; char highByte;
@@ -91,10 +92,14 @@ void Settings::loadSettingsFromFile() {
if (settingsFile.eof()) break; if (settingsFile.eof()) break;
if (getSizeOfPieces(PiecesType(pieceType)) == 0) { if (getSizeOfPieces(PiecesType(pieceType)) == 0) {
settingsFile.get(pieceValue); settingsFile.get(pieceSize);
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceValue);
if (!(pieceSize > this->maximumPiecesSize)) {
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);
@@ -102,6 +107,7 @@ void Settings::loadSettingsFromFile() {
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceNumber); this->selectedPieces.emplace_back(PiecesType(pieceType), pieceNumber);
} }
} }
}
this->confirmSelectedPieces(); this->confirmSelectedPieces();
} }
@@ -253,6 +259,10 @@ void Settings::unselectPieces(int index) {
void Settings::confirmSelectedPieces() { void Settings::confirmSelectedPieces() {
this->menu.getPiecesList().unselectAll(); this->menu.getPiecesList().unselectAll();
if (this->getSelectedPieces().size() == 0) {
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);
@@ -265,15 +275,13 @@ void Settings::confirmSelectedPieces() {
} }
} }
else { else {
if (size > MAXIMUM_PIECES_SIZE) return;
this->menu.getPiecesList().selectPiece(size, value); this->menu.getPiecesList().selectPiece(size, value);
} }
} }
} }
bool Settings::increaseDistribution(int size) { bool Settings::increaseDistribution(int size) {
if (size < 1 || size > MAXIMUM_PIECES_SIZE) return false; if (size < 1 || size > this->maximumPiecesSize) return false;
if (this->distributions.at(size) < DISTRIBUTION_MAX) { if (this->distributions.at(size) < DISTRIBUTION_MAX) {
this->distributions.at(size)++; this->distributions.at(size)++;
@@ -283,7 +291,7 @@ bool Settings::increaseDistribution(int size) {
} }
bool Settings::decreaseDistribution(int size) { bool Settings::decreaseDistribution(int size) {
if (size < 1 || size > MAXIMUM_PIECES_SIZE) return false; if (size < 1 || size > this->maximumPiecesSize) return false;
if (this->distributions.at(size) > 0) { if (this->distributions.at(size) > 0) {
this->distributions.at(size)--; this->distributions.at(size)--;
@@ -306,6 +314,10 @@ Keybinds& Settings::getKeybinds() {
return this->keybinds.at(this->chosenKeybinds); return this->keybinds.at(this->chosenKeybinds);
} }
int Settings::getMaximumPiecesSize() const {
return this->maximumPiecesSize;
}
int Settings::getKeybindsLayout() const { int Settings::getKeybindsLayout() const {
return this->chosenKeybinds; return this->chosenKeybinds;
} }

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "../Core/Menu.h" #include "../Core/Menu.h"
#include "StartUpMenu.h"
#include "Keybinds.h" #include "Keybinds.h"
#include "PiecesType.h" #include "PiecesType.h"
@@ -10,17 +11,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;
//#define __JMINOS_RELEASE__
#ifdef __JMINOS_RELEASE__
static const int MAXIMUM_PIECES_SIZE = 15;
#else
static const int MAXIMUM_PIECES_SIZE = 10;
#endif
class Settings { class Settings {
private: private:
Menu menu; Menu menu;
int maximumPiecesSize;
std::vector<Keybinds> keybinds; std::vector<Keybinds> keybinds;
int chosenKeybinds; int chosenKeybinds;
int windowSizeMode; int windowSizeMode;
@@ -30,7 +25,7 @@ class Settings {
std::vector<int> distributions; std::vector<int> distributions;
public: public:
Settings(); Settings(int maximumPiecesSize);
void loadSettingsFromFile(); void loadSettingsFromFile();
@@ -70,6 +65,8 @@ class Settings {
Keybinds& getKeybinds(); Keybinds& getKeybinds();
int getMaximumPiecesSize() const;
int getKeybindsLayout() const; int getKeybindsLayout() const;
Gamemode getGamemode() const; Gamemode getGamemode() const;

View File

@@ -0,0 +1,15 @@
#include "StartUpMenu.h"
#include "PlayerCursor.h"
StartUpMenu::StartUpMenu() :
playerCursor({LOADED_PIECES_SIZE}) {
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
}
int StartUpMenu::getMaximumPiecesSize() {
return LOADED_PIECES_SIZE;
//TODO
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include "PiecesType.h"
#include "PlayerCursor.h"
static const int MINIMUM_PIECES_SIZE = 4;
static const int MAXIMUM_PIECES_SIZE = 15;
//#define __JMINOS_RELEASE__
#ifdef __JMINOS_RELEASE__
static const int LOADED_PIECES_SIZE = 15;
#else
static const int LOADED_PIECES_SIZE = 10;
#endif
static const std::pair<PiecesType, int> DEFAULT_SELECTION = {ALL_PIECES, MINIMUM_PIECES_SIZE};
class StartUpMenu {
private:
PlayerCursor playerCursor;
public:
StartUpMenu();
int getMaximumPiecesSize();
};

View File

@@ -1,3 +1,4 @@
#include "StartUpMenu.h"
#include "GraphApp.h" #include "GraphApp.h"
#include "../Pieces/PiecesFiles.h" #include "../Pieces/PiecesFiles.h"
@@ -13,7 +14,7 @@ int main() {
std::srand(std::time(NULL)); std::srand(std::time(NULL));
PiecesFiles pf; PiecesFiles pf;
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) { for (int i = 1; i <= LOADED_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 +31,10 @@ int main() {
} }
} }
GraphApp UI; StartUpMenu startUp;
int maximumPiecesSize = startUp.getMaximumPiecesSize();
GraphApp UI(maximumPiecesSize);
UI.run(); UI.run();
return 0; return 0;