about summary refs log tree commit diff stats
path: root/Source/PuzzlerSerializer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/PuzzlerSerializer.cpp')
-rw-r--r--Source/PuzzlerSerializer.cpp25
1 files changed, 17 insertions, 8 deletions
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) {
234 for (int x=0; x<p.width; x++) { 234 for (int x=0; x<p.width; x++) {
235 for (int y=0; y<p.height; y++) { 235 for (int y=0; y<p.height; y++) {
236 if (p.grid[x][y].end == Cell::Dir::NONE) continue; 236 if (p.grid[x][y].end == Cell::Dir::NONE) continue;
237 _connectionsA.push_back(xy_to_loc(p, x, y)); // Target to connect to 237 _connectionsA.push_back(xy_to_loc(p, x, y));
238 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint 238 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size()));
239 239
240 auto [xPos, yPos] = xy_to_pos(p, x, y); 240 auto [xPos, yPos] = xy_to_pos(p, x, y);
241 switch (p.grid[x][y].end) { 241 switch (p.grid[x][y].end) {
@@ -252,6 +252,7 @@ void PuzzleSerializer::WriteEndpoints(const Puzzle& p) {
252 yPos -= .05f; 252 yPos -= .05f;
253 break; 253 break;
254 } 254 }
255 _endpointLocations.emplace_back(x, y, static_cast<int>(_intersectionFlags.size()));
255 _intersectionLocations.push_back(xPos); 256 _intersectionLocations.push_back(xPos);
256 _intersectionLocations.push_back(yPos); 257 _intersectionLocations.push_back(yPos);
257 _intersectionFlags.push_back(Flags::IS_ENDPOINT); 258 _intersectionFlags.push_back(Flags::IS_ENDPOINT);
@@ -273,10 +274,10 @@ void PuzzleSerializer::WriteDots(const Puzzle& p) {
273 if ((x1+1 == x && x2-1 == x && y1 == y && y2 == y) || 274 if ((x1+1 == x && x2-1 == x && y1 == y && y2 == y) ||
274 (y1+1 == y && y2-1 == y && x1 == x && x2 == x)) { 275 (y1+1 == y && y2-1 == y && x1 == x && x2 == x)) {
275 int other_connection = _connectionsB[i]; 276 int other_connection = _connectionsB[i];
276 _connectionsB[i] = static_cast<int>(_intersectionFlags.size()); // This endpoint 277 _connectionsB[i] = static_cast<int>(_intersectionFlags.size());
277 278
278 _connectionsA.push_back(other_connection); 279 _connectionsA.push_back(other_connection);
279 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint 280 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size()));
280 break; 281 break;
281 } 282 }
282 } 283 }
@@ -314,25 +315,25 @@ void PuzzleSerializer::WriteGaps(const Puzzle& p) {
314 // Reminder: Y goes from 0.0 (bottom) to 1.0 (top) 315 // Reminder: Y goes from 0.0 (bottom) to 1.0 (top)
315 if (x%2 == 0) { // Vertical gap 316 if (x%2 == 0) { // Vertical gap
316 _connectionsA.push_back(xy_to_loc(p, x, y-1)); 317 _connectionsA.push_back(xy_to_loc(p, x, y-1));
317 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint 318 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size()));
318 _intersectionLocations.push_back(xPos); 319 _intersectionLocations.push_back(xPos);
319 _intersectionLocations.push_back(yPos + VERTI_GAP_SIZE / 2); 320 _intersectionLocations.push_back(yPos + VERTI_GAP_SIZE / 2);
320 _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); 321 _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN);
321 322
322 _connectionsA.push_back(xy_to_loc(p, x, y+1)); 323 _connectionsA.push_back(xy_to_loc(p, x, y+1));
323 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint 324 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size()));
324 _intersectionLocations.push_back(xPos); 325 _intersectionLocations.push_back(xPos);
325 _intersectionLocations.push_back(yPos - VERTI_GAP_SIZE / 2); 326 _intersectionLocations.push_back(yPos - VERTI_GAP_SIZE / 2);
326 _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); 327 _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN);
327 } else if (y%2 == 0) { // Horizontal gap 328 } else if (y%2 == 0) { // Horizontal gap
328 _connectionsA.push_back(xy_to_loc(p, x-1, y)); 329 _connectionsA.push_back(xy_to_loc(p, x-1, y));
329 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint 330 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size()));
330 _intersectionLocations.push_back(xPos - HORIZ_GAP_SIZE / 2); 331 _intersectionLocations.push_back(xPos - HORIZ_GAP_SIZE / 2);
331 _intersectionLocations.push_back(yPos); 332 _intersectionLocations.push_back(yPos);
332 _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); 333 _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN);
333 334
334 _connectionsA.push_back(xy_to_loc(p, x+1, y)); 335 _connectionsA.push_back(xy_to_loc(p, x+1, y));
335 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint 336 _connectionsB.push_back(static_cast<int>(_intersectionFlags.size()));
336 _intersectionLocations.push_back(xPos + HORIZ_GAP_SIZE / 2); 337 _intersectionLocations.push_back(xPos + HORIZ_GAP_SIZE / 2);
337 _intersectionLocations.push_back(yPos); 338 _intersectionLocations.push_back(yPos);
338 _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); 339 _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN);
@@ -371,6 +372,14 @@ void PuzzleSerializer::WriteSequence(const Puzzle& p, int id) {
371 } 372 }
372 } 373 }
373 374
375 Pos endpoint = p.sequence[p.sequence.size() - 1];
376 for (auto [x, y, location] : _endpointLocations) {
377 if (x == endpoint.x && y == endpoint.y) {
378 sequence.emplace_back(location);
379 break;
380 }
381 }
382
374 _memory->WritePanelData<int>(id, SEQUENCE_LEN, {static_cast<int>(sequence.size())}); 383 _memory->WritePanelData<int>(id, SEQUENCE_LEN, {static_cast<int>(sequence.size())});
375 _memory->WriteNewArray<int>(id, SEQUENCE, sequence); 384 _memory->WriteNewArray<int>(id, SEQUENCE, sequence);
376} 385}