diff options
author | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-24 14:08:30 -0800 |
---|---|---|
committer | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-24 14:08:30 -0800 |
commit | 81fa5933d23db320934d168329b818b1868eeb6c (patch) | |
tree | 8527b3e9bdb4c1d523937fe47f249900be657983 /Source | |
parent | 88ad92c9382a68532503a351b053de024d116774 (diff) | |
download | witness-tutorializer-81fa5933d23db320934d168329b818b1868eeb6c.tar.gz witness-tutorializer-81fa5933d23db320934d168329b818b1868eeb6c.tar.bz2 witness-tutorializer-81fa5933d23db320934d168329b818b1868eeb6c.zip |
Grid cells are now square. Yay.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/PuzzleSerializer.cpp | 30 | ||||
-rw-r--r-- | Source/PuzzleSerializer.h | 3 |
2 files changed, 19 insertions, 14 deletions
diff --git a/Source/PuzzleSerializer.cpp b/Source/PuzzleSerializer.cpp index 3dffde1..da7a336 100644 --- a/Source/PuzzleSerializer.cpp +++ b/Source/PuzzleSerializer.cpp | |||
@@ -14,7 +14,7 @@ Puzzle PuzzleSerializer::ReadPuzzle(int id) { | |||
14 | int height = _memory->ReadEntityData<int>(id, GRID_SIZE_Y, 1)[0]; | 14 | int height = _memory->ReadEntityData<int>(id, GRID_SIZE_Y, 1)[0]; |
15 | if (width == 0) width = height; | 15 | if (width == 0) width = height; |
16 | if (height == 0) height = width; | 16 | if (height == 0) height = width; |
17 | if (width < 0 || height < 0) return Puzzle(); // @Error: Grid size should be always positive? Looks like the starting panels break this rule, though. | 17 | if (width < 0 || height < 0) return p; // @Error: Grid size should be always positive? Looks like the starting panels break this rule, though. |
18 | 18 | ||
19 | _numGridLocations = width * height; // Highest location which represents a gridded intersection | 19 | _numGridLocations = width * height; // Highest location which represents a gridded intersection |
20 | _numIntersections = _memory->ReadEntityData<int>(id, NUM_DOTS, 1)[0]; | 20 | _numIntersections = _memory->ReadEntityData<int>(id, NUM_DOTS, 1)[0]; |
@@ -46,12 +46,16 @@ void PuzzleSerializer::WritePuzzle(const Puzzle& p, int id) { | |||
46 | 46 | ||
47 | MIN = 0.1f; | 47 | MIN = 0.1f; |
48 | MAX = 0.9f; | 48 | MAX = 0.9f; |
49 | WIDTH_INTERVAL = (MAX - MIN) / (p.width/2); | 49 | |
50 | HEIGHT_INTERVAL = (MAX - MIN) / (p.height/2); | 50 | if (p.height > p.width) { |
51 | GAP_SIZE = min(WIDTH_INTERVAL, HEIGHT_INTERVAL) / 2; | 51 | INTERVAL = (MAX - MIN) / (p.height - (p.height%2)); |
52 | // @Improvement: This will make grid cells square... but how do I keep the puzzle centered? Maybe save extra metadata? | 52 | X_OFF = (p.height - p.width) / 2; |
53 | // INTERVAL = (MAX - MIN) / (max(p.width, p.height) / 2); | 53 | Y_OFF = 0; |
54 | // GAP_SIZE = INTERVAL / 2; | 54 | } else { |
55 | INTERVAL = (MAX - MIN) / (p.width - (p.width%2)); | ||
56 | X_OFF = 0; | ||
57 | Y_OFF = (p.width - p.height) / 2; | ||
58 | } | ||
55 | 59 | ||
56 | WriteIntersections(p); | 60 | WriteIntersections(p); |
57 | WriteEndpoints(p); | 61 | WriteEndpoints(p); |
@@ -404,22 +408,22 @@ void PuzzleSerializer::WriteGaps(const Puzzle& p) { | |||
404 | gap1Location = static_cast<int>(_intersectionFlags.size()); | 408 | gap1Location = static_cast<int>(_intersectionFlags.size()); |
405 | _connectionsA[connectionLocation] = xy_to_loc(p, x, y-1); | 409 | _connectionsA[connectionLocation] = xy_to_loc(p, x, y-1); |
406 | _connectionsB[connectionLocation] = gap1Location; | 410 | _connectionsB[connectionLocation] = gap1Location; |
407 | AddIntersection(p, x, y, xPos, yPos + GAP_SIZE / 2, Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); | 411 | AddIntersection(p, x, y, xPos, yPos + INTERVAL / 4, Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); |
408 | 412 | ||
409 | gap2Location = static_cast<int>(_intersectionFlags.size()); | 413 | gap2Location = static_cast<int>(_intersectionFlags.size()); |
410 | _connectionsA.push_back(xy_to_loc(p, x, y+1)); | 414 | _connectionsA.push_back(xy_to_loc(p, x, y+1)); |
411 | _connectionsB.push_back(gap2Location); | 415 | _connectionsB.push_back(gap2Location); |
412 | AddIntersection(p, x, y, xPos, yPos - GAP_SIZE / 2, Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); | 416 | AddIntersection(p, x, y, xPos, yPos - INTERVAL / 4, Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); |
413 | } else if (y%2 == 0) { // Horizontal gap | 417 | } else if (y%2 == 0) { // Horizontal gap |
414 | gap1Location = static_cast<int>(_intersectionFlags.size()); | 418 | gap1Location = static_cast<int>(_intersectionFlags.size()); |
415 | _connectionsA[connectionLocation] = xy_to_loc(p, x-1, y); | 419 | _connectionsA[connectionLocation] = xy_to_loc(p, x-1, y); |
416 | _connectionsB[connectionLocation] = gap1Location; | 420 | _connectionsB[connectionLocation] = gap1Location; |
417 | AddIntersection(p, x, y, xPos - GAP_SIZE / 2, yPos, Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); | 421 | AddIntersection(p, x, y, xPos - INTERVAL / 4, yPos, Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); |
418 | 422 | ||
419 | gap2Location = static_cast<int>(_intersectionFlags.size()); | 423 | gap2Location = static_cast<int>(_intersectionFlags.size()); |
420 | _connectionsA.push_back(xy_to_loc(p, x+1, y)); | 424 | _connectionsA.push_back(xy_to_loc(p, x+1, y)); |
421 | _connectionsB.push_back(gap2Location); | 425 | _connectionsB.push_back(gap2Location); |
422 | AddIntersection(p, x, y, xPos + GAP_SIZE / 2, yPos, Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); | 426 | AddIntersection(p, x, y, xPos + INTERVAL / 4, yPos, Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); |
423 | } | 427 | } |
424 | if (p.symmetry != Puzzle::Symmetry::NONE) { | 428 | if (p.symmetry != Puzzle::Symmetry::NONE) { |
425 | if (p.grid[x][y].gap == Cell::Gap::NONE) { | 429 | if (p.grid[x][y].gap == Cell::Gap::NONE) { |
@@ -574,8 +578,8 @@ int PuzzleSerializer::xy_to_dloc(const Puzzle& p, int x, int y) const { | |||
574 | 578 | ||
575 | std::tuple<float, float> PuzzleSerializer::xy_to_pos(const Puzzle& p, int x, int y) const { | 579 | std::tuple<float, float> PuzzleSerializer::xy_to_pos(const Puzzle& p, int x, int y) const { |
576 | return { | 580 | return { |
577 | MIN + (x/2.0f) * WIDTH_INTERVAL, | 581 | MIN + (x + X_OFF) * INTERVAL, |
578 | MAX - (y/2.0f) * HEIGHT_INTERVAL | 582 | MAX - (y + Y_OFF) * INTERVAL |
579 | }; | 583 | }; |
580 | } | 584 | } |
581 | 585 | ||
diff --git a/Source/PuzzleSerializer.h b/Source/PuzzleSerializer.h index 4d254d8..4ccd383 100644 --- a/Source/PuzzleSerializer.h +++ b/Source/PuzzleSerializer.h | |||
@@ -65,5 +65,6 @@ private: | |||
65 | // Locations of non-grid points, i.e. dots, gaps, and endpoints | 65 | // Locations of non-grid points, i.e. dots, gaps, and endpoints |
66 | std::unordered_map<int, int> _extraLocations; | 66 | std::unordered_map<int, int> _extraLocations; |
67 | 67 | ||
68 | float MIN, MAX, WIDTH_INTERVAL, HEIGHT_INTERVAL, INTERVAL, GAP_SIZE; | 68 | float MIN, MAX, INTERVAL; |
69 | int X_OFF, Y_OFF; | ||
69 | }; | 70 | }; |