From 039b48fe49c31f6033a17aabab353b7b7696e11b Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sat, 16 Nov 2019 11:10:26 -0800 Subject: it's alive --- Source/PuzzlerSerializer.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'Source/PuzzlerSerializer.cpp') diff --git a/Source/PuzzlerSerializer.cpp b/Source/PuzzlerSerializer.cpp index 86f59e7..cf013ca 100644 --- a/Source/PuzzlerSerializer.cpp +++ b/Source/PuzzlerSerializer.cpp @@ -234,8 +234,8 @@ void PuzzleSerializer::WriteEndpoints(const Puzzle& p) { for (int x=0; x(_intersectionFlags.size())); // This endpoint + _connectionsA.push_back(xy_to_loc(p, x, y)); + _connectionsB.push_back(static_cast(_intersectionFlags.size())); auto [xPos, yPos] = xy_to_pos(p, x, y); switch (p.grid[x][y].end) { @@ -252,6 +252,7 @@ void PuzzleSerializer::WriteEndpoints(const Puzzle& p) { yPos -= .05f; break; } + _endpointLocations.emplace_back(x, y, static_cast(_intersectionFlags.size())); _intersectionLocations.push_back(xPos); _intersectionLocations.push_back(yPos); _intersectionFlags.push_back(Flags::IS_ENDPOINT); @@ -273,10 +274,10 @@ void PuzzleSerializer::WriteDots(const Puzzle& p) { if ((x1+1 == x && x2-1 == x && y1 == y && y2 == y) || (y1+1 == y && y2-1 == y && x1 == x && x2 == x)) { int other_connection = _connectionsB[i]; - _connectionsB[i] = static_cast(_intersectionFlags.size()); // This endpoint + _connectionsB[i] = static_cast(_intersectionFlags.size()); _connectionsA.push_back(other_connection); - _connectionsB.push_back(static_cast(_intersectionFlags.size())); // This endpoint + _connectionsB.push_back(static_cast(_intersectionFlags.size())); break; } } @@ -314,25 +315,25 @@ void PuzzleSerializer::WriteGaps(const Puzzle& p) { // Reminder: Y goes from 0.0 (bottom) to 1.0 (top) if (x%2 == 0) { // Vertical gap _connectionsA.push_back(xy_to_loc(p, x, y-1)); - _connectionsB.push_back(static_cast(_intersectionFlags.size())); // This endpoint + _connectionsB.push_back(static_cast(_intersectionFlags.size())); _intersectionLocations.push_back(xPos); _intersectionLocations.push_back(yPos + VERTI_GAP_SIZE / 2); _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); _connectionsA.push_back(xy_to_loc(p, x, y+1)); - _connectionsB.push_back(static_cast(_intersectionFlags.size())); // This endpoint + _connectionsB.push_back(static_cast(_intersectionFlags.size())); _intersectionLocations.push_back(xPos); _intersectionLocations.push_back(yPos - VERTI_GAP_SIZE / 2); _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); } else if (y%2 == 0) { // Horizontal gap _connectionsA.push_back(xy_to_loc(p, x-1, y)); - _connectionsB.push_back(static_cast(_intersectionFlags.size())); // This endpoint + _connectionsB.push_back(static_cast(_intersectionFlags.size())); _intersectionLocations.push_back(xPos - HORIZ_GAP_SIZE / 2); _intersectionLocations.push_back(yPos); _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); _connectionsA.push_back(xy_to_loc(p, x+1, y)); - _connectionsB.push_back(static_cast(_intersectionFlags.size())); // This endpoint + _connectionsB.push_back(static_cast(_intersectionFlags.size())); _intersectionLocations.push_back(xPos + HORIZ_GAP_SIZE / 2); _intersectionLocations.push_back(yPos); _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); @@ -371,6 +372,14 @@ void PuzzleSerializer::WriteSequence(const Puzzle& p, int id) { } } + Pos endpoint = p.sequence[p.sequence.size() - 1]; + for (auto [x, y, location] : _endpointLocations) { + if (x == endpoint.x && y == endpoint.y) { + sequence.emplace_back(location); + break; + } + } + _memory->WritePanelData(id, SEQUENCE_LEN, {static_cast(sequence.size())}); _memory->WriteNewArray(id, SEQUENCE, sequence); } -- cgit 1.4.1