5 Commits

Author SHA1 Message Date
6da3cb66fa changed InfoAppMenu 2025-05-23 23:57:13 +02:00
e0ab6a4828 update readme and main.cpp debug messages 2025-05-23 22:35:31 +02:00
a62b3c018d fixed holding spwaning the piece 1 row lower 2025-04-01 18:45:01 +02:00
46ebb88ef2 we can load polyos in the app now 2025-03-31 21:14:06 +02:00
de14978b01 support unsupported sizes 2025-03-31 20:29:34 +02:00
19 changed files with 346 additions and 151 deletions

View File

@@ -4,19 +4,26 @@ Modern stacker game with every polyominos from size 1 to 15, made in C++ with [S
## Download
// to bo included when release version is done //
// TODO when the game is finished //
This game has been tested on and provides executables for Windows 11 and Linux under Ubuntu only.
If your OS isn't compactible with either of theses two, you can try [manually building the project](#manual-build-and-run).
This game has been tested on and built on Windows 11 and WSL2 Ubuntu only.
If your OS isn't compactible with either of theses two, you can try [manually building the project](#manual-build).
## How to play
### General
You can see and change in-game keybinds in the **SETTINGS** section of the main menu!
All of in-menu navigation is done with the arrow keys, the Enter key and the Escape key. Theses are unmutable keybinds.
You will find some more infos about the Rotation System and the scoring in the **INFO** section of the main menu.
If you want to know more details about the generation and classification of polyominoes, [check the documentation](/doc/)!
All of in-menu navigation is done with the **arrow keys**, the **Enter key** and the **Escape key**. Theses are unchangeable keybinds.
You will find more infos about the Rotation System, the scoring system, or the different pieces type in the **INFO** section of the main menu.
If you want to know more details about the generation of polyominoes, [check the documentation](/doc/)!
## Features
- Every polyominoes from size 1 to 15, selectable as you wish, with customizable propotionnality for each size!
- Customizable keybinds!
- 0° rotations!
- AutoRS as the Rotation System!
- IRS, IHS, infinite hold, and other leniency mechanics!
- Very bland interface!! (i'm not a designer)
### Available gamemodes
@@ -26,6 +33,10 @@ If you want to know more details about the generation and classification of poly
- MASTER : clear 200 lines at levels higher than maximum gravity!
- ZEN : practice indefinitely in this mode with no gravity!
### Screenshots
// TODO when the game is finished //
## Manual build
This project uses xmake for compiling, xmake is cross-platform and works in most OS, xmake also automatically install supported librairies.
@@ -43,12 +54,19 @@ If you need to change the toolchain (for example using gcc):
### Run the project
``xmake run``
Note that the program will generate the polyomino files for you the first time. This lasts several minutes so it only does it up to size 10. If you want to use the full range up to size 15, you will need to uncomment the ``#define`` at line 13 of file ``src/GraphicalUI/Settings.h``.
If for some reasons you wanna run the command line version:
The program will generate the polyomino files for you if you don't have them.
As this is a lengthy process, debug mode limits pieces size to 10.
To switch between debug and release mode:
``xmake f -m debug``
``xmake f -m release``
If for some reasons you wanna run the command line version (not updated):
``xmake run text``
### Create a release version (xmake packaging ???)
### Package the project
// TODO when the game is finished //
## Credits

View File

@@ -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),
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.

View File

@@ -67,27 +67,29 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
if (AREJustEnded) {
this->lost = this->board.spawnNextPiece();
this->resetPiece(true);
}
/* IRS and IHS */
bool initialRotated = (this->initialActions.contains(ROTATE_0) || this->initialActions.contains(ROTATE_CW)
|| this->initialActions.contains(ROTATE_180) || this->initialActions.contains(ROTATE_CCW));
Rotation initialRotation = NONE
+ ((this->initialActions.contains(ROTATE_CW)) ? CLOCKWISE : NONE)
+ ((this->initialActions.contains(ROTATE_180)) ? DOUBLE : NONE)
+ ((this->initialActions.contains(ROTATE_CCW)) ? COUNTERCLOCKWISE : NONE);
if (this->initialActions.contains(HOLD)) {
this->lost = (!this->board.hold(initialRotation));
this->board.hold(initialRotation);
}
else {
if ((initialRotation != NONE) || this->initialActions.contains(ROTATE_0)) {
this->lost = (!this->board.rotate(initialRotation));
if (initialRotated) {
this->board.rotate(initialRotation);
}
}
this->lost = this->board.activePieceInWall();
if (this->lost) {
if (initialRotation == NONE) {
this->board.rotate(NONE);
this->lost = this->board.activePieceInWall();
if (this->lost) {
this->framesPassed++;
return;
@@ -97,7 +99,7 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
/* HOLD */
if (playerActions.contains(HOLD) && (!this->heldActions.contains(HOLD))) {
if (this->board.hold()) {
if (this->board.hold({})) {
this->resetPiece(false);
}
}

View File

@@ -11,6 +11,7 @@
#include <utility>
#include <cstdlib>
#include <iostream>
#include <optional>
GameBoard::GameBoard(int boardWidth, int boardHeight, const std::shared_ptr<PiecesList>& piecesList, int nextQueueLength) :
@@ -194,12 +195,12 @@ bool GameBoard::activePieceOverlaps(const std::set<Position>& safePositions, con
return false;
}
bool GameBoard::hold(Rotation initialRotation) {
bool GameBoard::hold(std::optional<Rotation> initialRotation) {
Position storedPosition = this->activePiecePosition;
std::swap(this->activePiece, this->heldPiece);
bool isFirstTimeHolding = (this->activePiece == nullptr);
if (isFirstTimeHolding) {
// try with the next piece in queue since there is no piece in the hold box yet
if (this->nextQueueLength == 0) {
this->activePiece = std::make_shared<Piece>(this->generator.lookNext());
}
@@ -208,21 +209,25 @@ bool GameBoard::hold(Rotation initialRotation) {
}
}
Piece stored = *this->activePiece;
Position storedPosition = this->activePiecePosition;
// try initial rotation
this->goToSpawnPosition();
this->rotate(initialRotation);
if (initialRotation.has_value()) {
std::shared_ptr<Piece> storedPiece(this->activePiece);
this->rotate(initialRotation.value());
// if the piece can't spawn, abort initial rotation
if (this->activePieceInWall()) {
this->activePiece = std::make_shared<Piece>(stored);
this->goToSpawnPosition();
this->activePiece = storedPiece;
}
}
// if the piece can't spawn, try 0° rotation
if (this->activePieceInWall()) {
std::shared_ptr<Piece> storedPiece(this->activePiece);
this->rotate(NONE);
// if the piece still can't spawn, abort holding
if (this->activePieceInWall()) {
if (isFirstTimeHolding) {
this->activePiece = nullptr;
}
this->activePiece = (isFirstTimeHolding) ? nullptr : storedPiece;
std::swap(this->activePiece, this->heldPiece);
this->activePiecePosition = storedPosition;
return false;
@@ -230,7 +235,6 @@ bool GameBoard::hold(Rotation initialRotation) {
}
if (isFirstTimeHolding) {
// confirm we keep the piece we tried with
this->nextQueue.push_back(this->generator.getNext());
this->nextQueue.erase(this->nextQueue.begin());
}

View File

@@ -7,6 +7,7 @@
#include <vector>
#include <memory>
#include <optional>
/**
@@ -90,7 +91,7 @@ class GameBoard {
* Tries holding the active piece or swapping it if one was already stocked, while trying to apply an initial rotation to the newly spawned piece
* @return If it suceeded
*/
bool hold(Rotation initialRotation = NONE);
bool hold(std::optional<Rotation> initialRotation);
/**
* Spawns the next piece from the queue

View File

@@ -39,7 +39,7 @@ inline std::string getGamemodeGoal(Gamemode gamemode) {
"200 lines",
"2 minutes",
"200 lines",
"Chill"
"Infinite"
};
return GAMEMODE_DESCRIPTIONS[gamemode];

View File

@@ -29,6 +29,7 @@ PiecesList::PiecesList() {
bool PiecesList::loadPieces(int size) {
if (size < 1) return false;
if (size <= this->highestLoadedSize) return true;
PiecesFiles piecesFiles;
for (int i = this->highestLoadedSize + 1; i <= size; i++) {

View File

@@ -57,6 +57,33 @@ class AppMenu {
}
}
sf::Text createText(int fontSize = 2) const {
sf::Text newText(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * fontSize);
newText.setFillColor(sf::Color::Black);
newText.setOutlineColor(sf::Color::White);
newText.setOutlineThickness(0);
return newText;
}
void setTextPosition(sf::Text& text, float xPos, float yPos) const {
float sizeMultiplier = this->settings->getWindowSizeMultiplier();
text.setOrigin(sf::Vector2f({0, text.getLocalBounds().size.y / 2}));
text.setPosition(sf::Vector2f({sizeMultiplier * xPos, sizeMultiplier * yPos}));
}
void setTitlePosition(sf::Text& text, float yPos) const {
float sizeMultiplier = this->settings->getWindowSizeMultiplier();
text.setOrigin({text.getLocalBounds().getCenter().x, text.getLocalBounds().size.y / 2});
text.setPosition(sf::Vector2f({sizeMultiplier * 40.f, sizeMultiplier * yPos}));
}
void setTextOutline(sf::Text& text, bool hasOutline) const {
text.setOutlineThickness(hasOutline * (this->settings->getWindowSizeMultiplier() / 2));
}
void placeText(sf::Text& text, const std::optional<PlayerCursor>& playerCursor, const sf::String& string, float xPos, float yPos, const std::optional<sf::Vector2u>& cursorPos) const {
float sizeMultiplier = this->settings->getWindowSizeMultiplier();

View File

@@ -16,6 +16,10 @@ GamePiecesAppMenu::GamePiecesAppMenu(std::shared_ptr<MenuStack> menuStack, std::
for (int i = 1; i <= this->settings->getMaximumPiecesSize(); i++) {
this->playerCursor.addRow(i + 1, this->settings->getMenu().readPiecesList().getNumberOfPieces(i) + 4);
}
if (this->settings->getMaximumPiecesSize() < MAXIMUM_PIECES_SIZE) {
this->playerCursor.addRow(this->settings->getMaximumPiecesSize() + 2, 1);
}
}
void GamePiecesAppMenu::computeFrame() {
@@ -30,7 +34,20 @@ void GamePiecesAppMenu::computeFrame() {
if (this->playerCursor.getPosition().y == 0) {
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 < MAXIMUM_PIECES_SIZE) {
this->playerCursor.addRow(newMaxSize + 2, 1);
}
}
else if (this->playerCursor.getPosition().y > 1) {
if (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);
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() < MAXIMUM_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 + 1, 35.f, drawFromFirstElem);
this->drawRow(firstElem + 2, 45.f, drawFromFirstElem);
@@ -112,6 +130,7 @@ void GamePiecesAppMenu::drawSelectedPiecesRow(float yPos) const {
int pieceSize = getSizeOfPieces(pieceType);
if (pieceSize > 0) {
if (!(pieceSize > this->settings->getMaximumPiecesSize())) {
const Piece& piece = this->settings->getMenu().readPiecesList().lookAtPiece({pieceSize, value});
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());
@@ -119,15 +138,51 @@ void GamePiecesAppMenu::drawSelectedPiecesRow(float yPos) const {
xProgress += (1.f + 8.f);
}
else {
this->placeText(text, {}, "UNLOADED_" + std::to_string(pieceSize), 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, {});
xProgress += (1.f + (text.getGlobalBounds().size.x / this->settings->getWindowSizeMultiplier()));
}
else {
this->placeText(text, {}, "UNLOADED_" + std::to_string(pieceSize), xProgress, yPos, {});
xProgress += (1.f + (text.getGlobalBounds().size.x / this->settings->getWindowSizeMultiplier()));
}
}
elem++;
}
}
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 firstElem = (drawFromFirstElem) ? -4 : std::max(((int) this->playerCursor.getPosition().x) - 7, -4);
@@ -156,6 +211,7 @@ void GamePiecesAppMenu::drawRow(int piecesSize, float yPos, bool drawFromFirstEl
}
}
}
}
void GamePiecesAppMenu::drawPiece(const Piece& piece, int cellSize, const sf::FloatRect& piecePosition, bool selected) const {
sf::RectangleShape rect(piecePosition.size);

View File

@@ -10,12 +10,13 @@
InfoAppMenu::InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow),
playerCursor({4}),
playerCursor({INFO_SECTIONS_COUNT}),
sectionsName(
"< ABOUT >",
"< PIECES TYPES >",
"< 0 DEGREES ROTATIONS >",
"< ROTATION SYSTEM >",
"< SCORING >",
"< 0 DEGREES ROTATIONS >"
"< SCORING >"
),
sectionsContent(
"This game is written in C++,\n"
@@ -27,6 +28,25 @@ InfoAppMenu::InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<S
"to them in any ways.\n"
"Current version: beta.",
"There is multiple pieces type in\n"
"the selection screen. Use theses\n"
"categories for size of at least 7.\n"
"Convex, Holeless and Others are\n"
"all mutually exclusive.\n"
"Others have holes inside them, and\n"
"Convex are presumably easier to\n"
"play with than Holeless.",
"This games introduces 0 degrees\n"
"rotations, which work by simpling\n"
"moving the piece down and kicking\n"
"it as is, allowing for new kinds\n"
"of kicks.\n"
"As a leniency mechanic, when a\n"
"piece spawns it will automatically\n"
"try a 0 degrees rotations if it\n"
"spawned inside a wall.",
"This game uses its own\n"
"Rotation Sytem, called AutoRS.\n"
"The rotation center is always the\n"
@@ -46,25 +66,48 @@ InfoAppMenu::InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<S
"and doubles the score gained.\n"
"A spin is detected when the piece is\n"
"locked in place, a mini-spin simply\n"
"when the last move was a kick.",
"when the last move was a kick."
),
sectionNameText(this->createText()),
sectionContentText(this->createText()),
renderTexture(this->renderWindow->getSize()),
sprite(this->renderTexture.getTexture()) {
"This games introduces 0 degrees\n"
"rotations, which work by simpling\n"
"moving the piece down and kicking\n"
"it as is, allowing for new kinds\n"
"of kicks.\n"
"As a leniency mechanic, when a\n"
"piece spawns it will automatically\n"
"try a 0 degrees rotations if it\n"
"spawned inside a wall."
) {
this->setTextOutline(this->sectionNameText, true);
this->sectionContentText.setLineSpacing((float) this->settings->getWindowSizeMultiplier() / 8);
this->sectionNameText.setString(this->sectionsName[this->playerCursor.getPosition().x]);
this->setTitlePosition(this->sectionNameText, 10.f);
this->sectionContentText.setString(this->sectionsContent[this->playerCursor.getPosition().x]);
this->setTextPosition(this->sectionContentText, 5.f, 30.f);
this->renderTexture.clear(sf::Color(200, 200, 200));
this->renderTexture.draw(this->sectionNameText);
this->renderTexture.draw(this->sectionContentText);
this->renderTexture.display();
this->sprite.setTexture(this->renderTexture.getTexture());
}
void InfoAppMenu::computeFrame() {
this->updateMetaBinds();
this->playerCursor.updatePosition();
if (this->playerCursor.movedLeft() || this->playerCursor.movedRight()) {
this->sectionNameText.setString(this->sectionsName[this->playerCursor.getPosition().x]);
this->setTitlePosition(this->sectionNameText, 10.f);
this->sectionContentText.setString(this->sectionsContent[this->playerCursor.getPosition().x]);
this->setTextPosition(this->sectionContentText, 5.f, 30.f);
this->renderTexture.clear(sf::Color(200, 200, 200));
this->renderTexture.draw(this->sectionNameText);
this->renderTexture.draw(this->sectionContentText);
this->renderTexture.display();
this->sprite.setTexture(this->renderTexture.getTexture());
}
if (this->escReleased) {
this->menuStack->pop();
}
@@ -73,15 +116,7 @@ void InfoAppMenu::computeFrame() {
void InfoAppMenu::drawFrame() const {
this->renderWindow->clear(sf::Color(200, 200, 200));
sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2);
text.setFillColor(sf::Color(0, 0, 0));
text.setOutlineColor(sf::Color(255, 255, 255));
this->placeTitle(text, this->playerCursor, this->sectionsName[this->playerCursor.getPosition().x], 10.f, this->playerCursor.getPosition());
text.setLineSpacing((float) this->settings->getWindowSizeMultiplier() / 8);
text.setOutlineThickness(0);
this->placeText(text, {}, this->sectionsContent[this->playerCursor.getPosition().x], 5.f, 30.f, {});
this->renderWindow->draw(sprite);
this->renderWindow->display();
}

View File

@@ -7,12 +7,18 @@
#include <memory>
#include <SFML/Graphics.hpp>
static const int INFO_SECTIONS_COUNT = 5;
class InfoAppMenu : public AppMenu {
private:
PlayerCursor playerCursor;
sf::String sectionsName[4];
sf::String sectionsContent[4];
sf::String sectionsName[INFO_SECTIONS_COUNT];
sf::String sectionsContent[INFO_SECTIONS_COUNT];
sf::Text sectionNameText;
sf::Text sectionContentText;
sf::RenderTexture renderTexture;
sf::Sprite sprite;
public:
InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);

View File

@@ -6,14 +6,15 @@
#include <stack>
#include <memory>
#include <algorithm>
#include <SFML/Graphics.hpp>
StartUpAppMenu::StartUpAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow),
playerCursor({LOADED_PIECES_SIZE + 1}) {
playerCursor({MAXIMUM_PIECES_SIZE + 1}) {
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
this->playerCursor.goToPosition({(unsigned int) std::clamp(this->settings->getMaximumPiecesSize(), MINIMUM_PIECES_SIZE, MAXIMUM_PIECES_SIZE), 0u});
}
void StartUpAppMenu::computeFrame() {
@@ -22,7 +23,7 @@ void StartUpAppMenu::computeFrame() {
if (this->playerCursor.getPosition().x < MINIMUM_PIECES_SIZE) {
if (this->playerCursor.movedLeft()) {
this->playerCursor.goToPosition({LOADED_PIECES_SIZE, 0});
this->playerCursor.goToPosition({MAXIMUM_PIECES_SIZE, 0});
}
else {
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
@@ -30,7 +31,7 @@ void StartUpAppMenu::computeFrame() {
}
if (this->enterReleased) {
*this->settings = Settings(this->playerCursor.getPosition().x);
this->settings->loadSettingsFromFile(true, {this->playerCursor.getPosition().x});
this->menuStack->pop();
if (this->settings->hasLoadedPieces()) {

View File

@@ -12,7 +12,7 @@ static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND);
GraphApp::GraphApp() {
this->settings = std::make_shared<Settings>(0);
this->settings = std::make_shared<Settings>(false);
this->menuStack = std::make_shared<MenuStack>();
this->renderWindow = std::make_shared<sf::RenderWindow>();
}

View File

@@ -42,6 +42,13 @@ void PlayerCursor::updatePosition() {
}
}
bool PlayerCursor::moved() const {
return (this->movedLeft()
|| this->movedRight()
|| this->movedUp()
|| this->movedDown());
}
bool PlayerCursor::movedLeft() const {
return this->shouldMove(this->leftDAS);
}
@@ -115,7 +122,7 @@ const sf::Vector2u& PlayerCursor::getPosition() const {
bool PlayerCursor::shouldMove(int DAS) const {
return (DAS == 1
|| (DAS > MENU_DAS && (DAS % 5) == 0)
|| (DAS > (FRAMES_PER_SECOND * 2)));
|| (DAS > (MENU_DAS * 4)));
}
void PlayerCursor::moveLeft() {

View File

@@ -18,6 +18,8 @@ class PlayerCursor {
void updatePosition();
bool moved() const;
bool movedLeft() const;
bool movedRight() const;

View File

@@ -5,6 +5,7 @@
#include "PiecesType.h"
#include <vector>
#include <optional>
#include <fstream>
#include <algorithm>
#include <SFML/Graphics.hpp>
@@ -17,20 +18,21 @@ static const int DISTRIBUTION_MAX = 20;
Settings::Settings(bool loadPieces) {
this->keybinds.clear();
this->keybinds.reserve(NUMBER_OF_KEYBINDS);
for (int i = 0; i < NUMBER_OF_KEYBINDS; 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) {
maximumPiecesSizeRequest = MINIMUM_PIECES_SIZE;
}
else if (maximumPiecesSizeRequest > LOADED_PIECES_SIZE || maximumPiecesSizeRequest > MAXIMUM_PIECES_SIZE) {
maximumPiecesSizeRequest = LOADED_PIECES_SIZE;
else if (maximumPiecesSizeRequest > MAXIMUM_PIECES_SIZE) {
maximumPiecesSizeRequest = MAXIMUM_PIECES_SIZE;
}
bool succeeded = true;
@@ -40,12 +42,13 @@ bool Settings::loadPieces(int maximumPiecesSizeRequest) {
i++;
}
this->maximumPiecesSize = (succeeded) ? maximumPiecesSizeRequest : 0;
return succeeded;
if (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);
char byte;
@@ -54,8 +57,15 @@ void Settings::loadSettingsFromFile(bool loadPieces) {
// maximum pieces size
settingsFile.get(byte);
this->maximumPiecesSize = byte;
if (loadPieces) {
this->loadedPieces = this->loadPieces(byte);
if (maximumPiecesSizeRequest.has_value()) {
this->loadPieces(maximumPiecesSizeRequest.value());
}
else {
this->loadPieces(byte);
}
}
else {
this->loadedPieces = false;
@@ -124,20 +134,17 @@ void Settings::loadSettingsFromFile(bool loadPieces) {
if (getSizeOfPieces(PiecesType(pieceType)) == 0) {
settingsFile.get(pieceSize);
if (!(pieceSize > this->maximumPiecesSize)) {
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceSize);
}
}
else {
if (!(getSizeOfPieces(PiecesType(pieceType)) > this->maximumPiecesSize)) {
settingsFile.get(lowByte);
settingsFile.get(midByte);
settingsFile.get(highByte);
int pieceNumber = ((unsigned char) lowByte) + ((unsigned char) midByte << 8) + ((unsigned char) highByte << 16);
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceNumber);
}
}
}
this->confirmSelectedPieces();
}
else {
@@ -309,27 +316,35 @@ void Settings::confirmSelectedPieces() {
this->menu.getPiecesList().unselectAll();
if (this->getSelectedPieces().size() == 0) {
this->selectedPieces.push_back(DEFAULT_SELECTION);
}
bool selectedNone = true;
for (const auto& [type, value] : this->selectedPieces) {
int size = getSizeOfPieces(type);
if (size == 0) {
if (!(value > this->maximumPiecesSize)) {
switch (type) {
case CONVEX_PIECES : {this->menu.getPiecesList().selectConvexPieces(value); break;}
case HOLELESS_PIECES : {this->menu.getPiecesList().selectHolelessPieces(value); break;}
case OTHER_PIECES : {this->menu.getPiecesList().selectOtherPieces(value); break;}
case ALL_PIECES : {this->menu.getPiecesList().selectAllPieces(value); break;}
}
selectedNone = false;
}
}
else {
if (!(getSizeOfPieces(type) > this->maximumPiecesSize)) {
this->menu.getPiecesList().selectPiece(size, value);
selectedNone = false;
}
}
}
if (selectedNone) {
this->selectedPieces.push_back(DEFAULT_SELECTION);
this->confirmSelectedPieces();
}
}
bool Settings::increaseDistribution(int size) {
if (!this->loadedPieces) return false;
if (size < 1 || size > this->maximumPiecesSize) return false;

View File

@@ -5,21 +5,22 @@
#include "PiecesType.h"
#include <vector>
#include <optional>
#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_HEIGHT = 40;
static const int MINIMUM_PIECES_SIZE = 4;
static const int MAXIMUM_PIECES_SIZE = 15;
static const int RELEASE_PIECES_SIZE = 15;
static const int DEBUG_PIECES_SIZE = 10;
//#define __JMINOS_RELEASE__
#ifdef __JMINOS_RELEASE__
static const int LOADED_PIECES_SIZE = 15;
static const int MINIMUM_PIECES_SIZE = 4;
#ifdef NDEBUG
static const int MAXIMUM_PIECES_SIZE = RELEASE_PIECES_SIZE;
#else
static const int LOADED_PIECES_SIZE = 10;
static const int MAXIMUM_PIECES_SIZE = DEBUG_PIECES_SIZE;
#endif
static const std::pair<PiecesType, int> DEFAULT_SELECTION = {ALL_PIECES, MINIMUM_PIECES_SIZE};
@@ -41,11 +42,9 @@ class Settings {
public:
Settings(bool loadPieces);
private:
bool loadPieces(int maximumPiecesSizeRequest);
void loadPieces(int maximumPiecesSizeRequest);
public:
void loadSettingsFromFile(bool loadPieces = true);
void loadSettingsFromFile(bool loadPieces, std::optional<int> maximumPiecesSizeRequest);
void saveSettingsToFile() const;

View File

@@ -13,15 +13,32 @@ int main() {
std::srand(std::time(NULL));
PiecesFiles pf;
for (int i = 1; i <= LOADED_PIECES_SIZE; i++) {
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
std::cout << "pieces files for size " << i << " not found, generating..." << std::endl;
#ifdef NDEBUG
std::cout << "IMPORTANT: You are currently in release mode, if you do not wish to generate big pieces (can take several minutes), type 'xmake f -m debug'." << std::endl;
#endif
std::cout << "INFO: Pieces files for size " << i << " not found, generating..." << std::endl;
pf.savePieces(i);
}
}
#ifndef NDEBUG
std::cout << "IMPORTANT: you are currently in debug mode, if you wish to use bigger pieces, type 'xmake f -m release'." << std::endl;
bool everythingGenerated = true;
for (int i = DEBUG_PIECES_SIZE; i <= RELEASE_PIECES_SIZE; i++) {
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
everythingGenerated = false;
}
}
if (!everythingGenerated) {
std::cout << "NOTE : you do not have all pieces generated, generating can take several minutes." << std::endl;
}
#endif
if (!std::filesystem::exists("data/config/settings.bin")) {
std::cout << "settings file not found, generating..." << std::endl;
std::cout << "INFO: Settings file not found, generating..." << std::endl;
resetSettingsFile();
}
else {
@@ -30,13 +47,17 @@ int main() {
settingsFile.get(byte);
if ((unsigned char) byte < CURRENT_FILE_FORMAT_VERSION) {
std::cout << "INFO: Files format changed, regenerating..." << std::endl;
resetSettingsFile();
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
resetKeybindFile(i);
}
}
}
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
if (!std::filesystem::exists("data/config/keybinds/layout" + std::to_string(i) + ".bin")) {
std::cout << "keybind file n°" << (i + 1) << "/" << NUMBER_OF_KEYBINDS << " not found, generating..." << std::endl;
std::cout << "INFO: Keybind file n°" << (i + 1) << "/" << NUMBER_OF_KEYBINDS << " not found, generating..." << std::endl;
resetKeybindFile(i);
}
}