commit 48b28ef0
Create a uniq id for the puzzles
Changed files
| M | CMakeLists.txt before |
| M | extra/docker/Dockerfile before |
| M | src/PuzzleSingleImageState.cpp before |
| M | src/PuzzleSingleImageState.hpp before |
| M | src/sago_multi_scrambler_puzzle2.cpp before |
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b604de1..452d18f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,5 +36,5 @@ file(GLOB SOURCES "src/*.cpp" "src/*/*.cpp" "src/*/*/*.cpp" "src/*/*/*/*.cpp" "s
add_executable(sago_multi_scrambler_puzzle2 ${SOURCES})
TARGET_LINK_LIBRARIES( sago_multi_scrambler_puzzle2 ${Boost_LIBRARIES} )
target_link_libraries( sago_multi_scrambler_puzzle2 ${SDL2_LIBRARIES})
-target_link_libraries( sago_multi_scrambler_puzzle2 physfs platform_folders)
+target_link_libraries( sago_multi_scrambler_puzzle2 physfs platform_folders rhash)
target_link_libraries( sago_multi_scrambler_puzzle2 ${SDL2MIXER_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2TTF_LIBRARIES} ${SDL2GFX_LIBRARIES})
\ No newline at end of file
diff --git a/extra/docker/Dockerfile b/extra/docker/Dockerfile
index c3c3e82..5587f19 100644
--- a/extra/docker/Dockerfile
+++ b/extra/docker/Dockerfile
@@ -5,7 +5,7 @@ ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && apt-get install --no-install-recommends -y build-essential libphysfs-dev libboost-dev cmake libsdl2-dev libsdl2-image-dev \
-libsdl2-gfx-dev libsdl2-mixer-dev libsdl2-ttf-dev libboost-program-options-dev zip gettext
+libsdl2-gfx-dev libsdl2-mixer-dev libsdl2-ttf-dev libboost-program-options-dev librhash-dev zip gettext
RUN mkdir -p /staging/game
diff --git a/src/PuzzleSingleImageState.cpp b/src/PuzzleSingleImageState.cpp
index 5e7e6b9..dd47ff8 100644
--- a/src/PuzzleSingleImageState.cpp
+++ b/src/PuzzleSingleImageState.cpp
@@ -28,6 +28,7 @@ https://github.com/sago007/saland
#include <SDL2/SDL2_gfxPrimitives.h>
#include <time.h>
#include "SagoImGui.hpp"
+#include "rhash.hpp"
PuzzleSingleImageState::PuzzleSingleImageState() {
@@ -210,11 +211,14 @@ void PuzzleSingleImageState::LoadPictureFromFile(const std::string& filename, SD
std::cerr << "Failed to load " << filename << std::endl;
return;
}
+ RHash h(RHASH_SHA256);
+ h.update(filename);
+ picture_id = h.hex(RHASH_SHA256);
source_image_height = bitmapSurface->h;
source_image_width = bitmapSurface->w;
ResizeImage();
this->pictureTex = SDL_CreateTextureFromSurface(renderer, bitmapSurface);
- std::cerr << resized_image_logical_width << ", " << resized_image_logical_height << "\n";
+ std::cerr << resized_image_logical_width << ", " << resized_image_logical_height << ", id: " << picture_id << ", file: " << filename << "\n";
SDL_FreeSurface(bitmapSurface);
pieces_logical.clear();
SDL_Rect piece;
@@ -284,6 +288,7 @@ void PuzzleSingleImageState::ClearPicture() {
SDL_DestroyTexture(this->pictureTex);
this->pictureTex = nullptr;
}
+ picture_id = "";
}
void PuzzleSingleImageState::Shuffle() {
diff --git a/src/PuzzleSingleImageState.hpp b/src/PuzzleSingleImageState.hpp
index 0f98ffb..9c19a25 100644
--- a/src/PuzzleSingleImageState.hpp
+++ b/src/PuzzleSingleImageState.hpp
@@ -25,6 +25,7 @@ https://github.com/sago007/saland
#include "SDL.h"
#include <string>
#include <vector>
+#include "rhash.h"
class PuzzleSingleImageState : public sago::GameStateInterface {
public:
@@ -71,4 +72,5 @@ private:
std::vector<size_t> shuffeled_pieces;
std::vector<size_t> rotated_pieces;
int marked_piece = -1;
+ std::string picture_id = "";
};
diff --git a/src/sago_multi_scrambler_puzzle2.cpp b/src/sago_multi_scrambler_puzzle2.cpp
index d7c199f..66c5777 100644
--- a/src/sago_multi_scrambler_puzzle2.cpp
+++ b/src/sago_multi_scrambler_puzzle2.cpp
@@ -34,6 +34,7 @@ https://github.com/sago007/saland
#include "MainGameState.hpp"
#include "editor/SagoTextureSelector.hpp"
#include "version.h"
+#include <filesystem>
GlobalData globalData;
@@ -107,7 +108,13 @@ int main(int argc, const char* argv[]) {
InitSagoFS(argc, argv);
if (vm.count("input-file")) {
const std::vector<std::string>& input_files = vm["input-file"].as<std::vector<std::string> >();
- runSinglePuzzle(input_files.at(0));
+ std::filesystem::path p = input_files.at(0);
+ std::error_code ec;
+ std::string filename = std::filesystem::canonical(p, ec).string();
+ if (ec) {
+ std::cerr << "Failed to open file: " << input_files.at(0) << "\n";
+ }
+ runSinglePuzzle(filename);
return 0;
}
if (vm.count("collection")) {