git repos / blockattack-game

commit e48b9d40

Poul Sander · 2025-10-07 20:08
e48b9d407a35e377646ea1f088f39910965d7cc6 patch · browse files
parent ee1c1ede34954655f86167b6b52640b4f3b6dd67

Add option to add a new file and fix issue when adding a puzzle with none selected

Changed files

M source/code/puzzle_editor/PuzzleEditorState.cpp before
M source/code/puzzle_editor/PuzzleEditorState.hpp before
M source/code/puzzlehandler.cpp before
diff --git a/source/code/puzzle_editor/PuzzleEditorState.cpp b/source/code/puzzle_editor/PuzzleEditorState.cpp index 11f7c32..7f31c0b 100644 --- a/source/code/puzzle_editor/PuzzleEditorState.cpp +++ b/source/code/puzzle_editor/PuzzleEditorState.cpp
@@ -389,6 +389,21 @@ void PuzzleEditorState::Draw(SDL_Renderer* target) {
}
}
+ ImGui::Separator();
+ ImGui::InputText("##newfilename", new_filename_buffer, sizeof(new_filename_buffer));
+ if (ImGui::Button("Create file")) {
+ std::string new_file(new_filename_buffer);
+ if (new_file.size()) {
+ const auto it = std::find(puzzle_files.begin(), puzzle_files.end(), new_file);
+ if (it == puzzle_files.end()) {
+ puzzle_files.push_back(new_file);
+ std::sort(puzzle_files.begin(), puzzle_files.end());
+ sago::WriteFileContent(fmt::format("puzzles/{}", new_file).c_str(), "0"); // Create file with 0 puzzles in it
+ SelectFile(new_file);
+ }
+ }
+ }
+
ImGui::End();
ImGui::Begin("Puzzles in file");
const int puzzle_count = PuzzleGetNumberOfPuzzles();
diff --git a/source/code/puzzle_editor/PuzzleEditorState.hpp b/source/code/puzzle_editor/PuzzleEditorState.hpp index 8b0a3d8..e481afe 100644 --- a/source/code/puzzle_editor/PuzzleEditorState.hpp +++ b/source/code/puzzle_editor/PuzzleEditorState.hpp
@@ -75,6 +75,7 @@ private:
std::string selected_file;
std::vector<std::string> puzzle_files;
sago::SagoLogicalResize window_resize;
+ char new_filename_buffer[256] = "untitled.levels";
std::map<std::string, std::vector<PuzzleState> > undo_file_stack;
std::map<std::string, std::vector<PuzzleState> > redo_file_stack;
diff --git a/source/code/puzzlehandler.cpp b/source/code/puzzlehandler.cpp index e104097..1205946 100644 --- a/source/code/puzzlehandler.cpp +++ b/source/code/puzzlehandler.cpp
@@ -177,10 +177,14 @@ void EditorRemovePuzzle(size_t level) {
}
void EditorAddPuzzle(size_t level) {
- if (nrOfPuzzles >= 50) {
+ if (nrOfPuzzles >= maxNrOfPuzzleStages) {
return;
}
- memmove( puzzleLevels[level+1], puzzleLevels[level], sizeof(puzzleLevels[0])*(50-level-1) );
+ if (level >= maxNrOfPuzzleStages)
+ {
+ level = 0;
+ }
+ memmove( puzzleLevels[level+1], puzzleLevels[level], sizeof(puzzleLevels[0])*(maxNrOfPuzzleStages-level-1) );
nrOfPuzzles++;
for (size_t i = 0; i < 6; i++) {
for (size_t j =0; j < 12; j++) {