Skip to content

Commit

Permalink
Support saving JPZ files without solutions.
Browse files Browse the repository at this point in the history
- Omit the (empty) solution attribute from all cells
- Disable check/reveal actions
- Show completion message regardless of grid correctness
  • Loading branch information
jpd236 committed Oct 5, 2023
1 parent bc9bd89 commit a1898a4
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions puz/formats/jpz/save_jpz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ void SaveJpz(Puzzle * puz, const std::string & filename, void * /* dummy */)

if (grid.IsScrambled())
throw ConversionError("Jpz does not support scrambled puzzles");
if (! grid.HasSolution())
throw ConversionError("Jpz does not support puzzles without a solution");
if (grid.GetType() == TYPE_DIAGRAMLESS)
throw ConversionError("Can't save a diagramless puzzle as jpz.");

Expand All @@ -88,16 +86,21 @@ void SaveJpz(Puzzle * puz, const std::string & filename, void * /* dummy */)

xml::node actions = settings.append_child("actions");
actions.append_attribute("buttons-layout") = "below";
actions.append_child("check").append_attribute("label") = "Check";
actions.append_child("reveal-letter").append_attribute("label") =
"Reveal Letter";
actions.append_child("reveal-word").append_attribute("label") =
"Reveal Word";
actions.append_child("revert").append_attribute("label") = "Clear All";
actions.append_child("solution").append_attribute("label") = "Solution";

xml::node completion = settings.append_child("completion");
completion.append_attribute("only-if-correct") = "true";
if (grid.HasSolution()) {
actions.append_child("check").append_attribute("label") = "Check";
actions.append_child("reveal-letter").append_attribute("label") =
"Reveal Letter";
actions.append_child("reveal-word").append_attribute("label") =
"Reveal Word";
actions.append_child("solution").append_attribute("label") = "Solution";
completion.append_attribute("only-if-correct") = "true";
}
else {
completion.append_attribute("only-if-correct") = "false";
}

string_t message = puz->GetMeta(puzT("completion"));
if (message.empty()) {
message = puzT("Congratulations, you have solved the puzzle!");
Expand Down Expand Up @@ -172,8 +175,9 @@ void SaveJpz(Puzzle * puz, const std::string & filename, void * /* dummy */)
{
if (square->IsAnnotation())
cell.append_attribute("type") = "clue";
cell.append_attribute("solution") =
encode_utf8(square->GetSolution()).c_str();
if (grid.HasSolution())
cell.append_attribute("solution") =
encode_utf8(square->GetSolution()).c_str();
if (square->HasNumber())
cell.append_attribute("number") =
encode_utf8(square->GetNumber()).c_str();
Expand Down

0 comments on commit a1898a4

Please sign in to comment.