about summary refs log tree commit diff stats
path: root/Source/PuzzleSerializer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/PuzzleSerializer.cpp')
-rw-r--r--Source/PuzzleSerializer.cpp61
1 files changed, 39 insertions, 22 deletions
diff --git a/Source/PuzzleSerializer.cpp b/Source/PuzzleSerializer.cpp index 8faede9..3732db8 100644 --- a/Source/PuzzleSerializer.cpp +++ b/Source/PuzzleSerializer.cpp
@@ -318,7 +318,18 @@ void PuzzleSerializer::WriteDots(const Puzzle& p) {
318 for (int x=0; x<p.width; x++) { 318 for (int x=0; x<p.width; x++) {
319 for (int y=0; y<p.height; y++) { 319 for (int y=0; y<p.height; y++) {
320 if (x%2 == y%2) continue; // Cells are invalid, intersections are already handled. 320 if (x%2 == y%2) continue; // Cells are invalid, intersections are already handled.
321 if (p.grid[x][y].dot == Cell::Dot::NONE) continue; 321
322 bool shouldWriteDot = false;
323 if (p.grid[x][y].dot != Cell::Dot::NONE) {
324 shouldWriteDot = true;
325 } else if (p.symmetry != Puzzle::Symmetry::NONE) {
326 Pos sym = p.GetSymmetricalPos(x, y);
327 // Write symmetrical dots, but don't actually set the flag for them. They're only there for symmetrical tracing.
328 if (p.grid[sym.x][sym.y].dot != Cell::Dot::NONE) {
329 shouldWriteDot = true;
330 }
331 }
332 if (!shouldWriteDot) continue;
322 333
323 // We need to introduce a new segment which contains this dot. Break the existing segment, and add one. 334 // We need to introduce a new segment which contains this dot. Break the existing segment, and add one.
324 int connectionLocation = -1; 335 int connectionLocation = -1;
@@ -339,19 +350,24 @@ void PuzzleSerializer::WriteDots(const Puzzle& p) {
339 _connectionsA.push_back(other_connection); 350 _connectionsA.push_back(other_connection);
340 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); 351 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size()));
341 352
342 int flags = Flags::HAS_DOT; 353 int flags = 0;
343 switch (p.grid[x][y].dot) { 354 if (p.symmetry != Puzzle::Symmetry::NONE && p.grid[x][y].dot == Cell::Dot::NONE) {
344 case Cell::Dot::BLACK: 355 // A dot was asked to be introduced strictly for tracing reasons, don't set any flags.
345 break; 356 } else {
346 case Cell::Dot::BLUE: 357 flags |= Flags::HAS_DOT;
347 flags |= DOT_IS_BLUE; 358 switch (p.grid[x][y].dot) {
348 break; 359 case Cell::Dot::BLACK:
349 case Cell::Dot::YELLOW: 360 break;
350 flags |= DOT_IS_ORANGE; 361 case Cell::Dot::BLUE:
351 break; 362 flags |= DOT_IS_BLUE;
352 case Cell::Dot::INVISIBLE: 363 break;
353 flags |= DOT_IS_INVISIBLE; 364 case Cell::Dot::YELLOW:
354 break; 365 flags |= DOT_IS_ORANGE;
366 break;
367 case Cell::Dot::INVISIBLE:
368 flags |= DOT_IS_INVISIBLE;
369 break;
370 }
355 } 371 }
356 372
357 auto [xPos, yPos] = xy_to_pos(p, x, y); 373 auto [xPos, yPos] = xy_to_pos(p, x, y);
@@ -414,13 +430,11 @@ void PuzzleSerializer::WriteGaps(const Puzzle& p) {
414 _connectionsB.push_back(gap2Location); 430 _connectionsB.push_back(gap2Location);
415 AddIntersection(p, x, y, xPos + INTERVAL / 2, yPos, Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); 431 AddIntersection(p, x, y, xPos + INTERVAL / 2, yPos, Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN);
416 } 432 }
417 if (p.symmetry != Puzzle::Symmetry::NONE) { 433 if (p.symmetry != Puzzle::Symmetry::NONE && p.grid[x][y].gap == Cell::Gap::NONE) {
418 if (p.grid[x][y].gap == Cell::Gap::NONE) { 434 // A gap was asked to be introduced strictly for tracing reasons, but it shouldn't look like a gap.
419 // A gap was asked to be introduced strictly for interaction reasons, but it shouldn't look like a gap. 435 // Add a connection between two halves of the gap to cover it graphically.
420 // Add a connection between two halves of the gap to cover it graphically. 436 _connectionsA.push_back(gap1Location);
421 _connectionsA.push_back(gap1Location); 437 _connectionsB.push_back(gap2Location);
422 _connectionsB.push_back(gap2Location);
423 }
424 } 438 }
425 } 439 }
426 } 440 }
@@ -546,7 +560,10 @@ int PuzzleSerializer::xy_to_loc(const Puzzle& p, int x, int y) const {
546 560
547int PuzzleSerializer::extra_xy_to_loc(const Puzzle& p, int x, int y) const { 561int PuzzleSerializer::extra_xy_to_loc(const Puzzle& p, int x, int y) const {
548 auto search = _extraLocations.find(x * p.height + y); 562 auto search = _extraLocations.find(x * p.height + y);
549 if (search == _extraLocations.end()) return -1; // @Error 563 if (search == _extraLocations.end()) {
564 assert(false);
565 return -1; // @Error
566 }
550 return search->second; 567 return search->second;
551} 568}
552 569