diff --git a/doc/files_format.md b/doc/files_format.md index fa2891e..7430c1d 100644 --- a/doc/files_format.md +++ b/doc/files_format.md @@ -48,4 +48,7 @@ The settings file has the following format: - The last selected height of the board, stored with 1 byte - The uniformity mode (0 for default distribution, 1 for uniformous distribution, 2 for custom distribution), stored with 1 byte - For each size, store the custom proportion (from 0 to 10) (15x1 byte total) -- Every selected pieces, using 1 byte for the type of selection (once again converted from an Enum) and 1 byte for the actual value +- Every selected pieces + - For every groupe of piece (ALL, CONVEX, HOLELESS, OTHER), use 1 byte for the type (once again converted from an Enum) and 1 byte for the size + - 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). diff --git a/src/GraphicalUI/Settings.cpp b/src/GraphicalUI/Settings.cpp index 0d2a9a1..44a31ad 100644 --- a/src/GraphicalUI/Settings.cpp +++ b/src/GraphicalUI/Settings.cpp @@ -82,12 +82,25 @@ void Settings::loadSettingsFromFile() { // selected pieces char pieceType; char pieceValue; + char lowByte; + char midByte; + char highByte; + this->selectedPieces.clear(); while (settingsFile.get(pieceType)) { if (settingsFile.eof()) break; - settingsFile.get(pieceValue); - this->selectedPieces.push_back({PiecesType(pieceType), pieceValue}); + if (getSizeOfPieces(PiecesType(pieceType)) == 0) { + settingsFile.get(pieceValue); + this->selectedPieces.emplace_back(PiecesType(pieceType), pieceValue); + } + else { + 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(); } @@ -147,8 +160,18 @@ void Settings::saveSettingsToFile() const { for (const auto& [type, value] : this->selectedPieces) { byte = type; settingsFile.write(&byte, 1); - byte = value; - settingsFile.write(&byte, 1); + if (getSizeOfPieces(type) == 0) { + byte = value; + settingsFile.write(&byte, 1); + } + else { + int number = value; + for (int i = 0; i < 3; i++) { + byte = (number % 256); + settingsFile.write(&byte, 1); + number = (number >> 8); + } + } } }