summary refs log tree commit diff stats
path: root/Source/PuzzleSerializer.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/PuzzleSerializer.h')
-rw-r--r--Source/PuzzleSerializer.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/Source/PuzzleSerializer.h b/Source/PuzzleSerializer.h new file mode 100644 index 0000000..d9b9edd --- /dev/null +++ b/Source/PuzzleSerializer.h
@@ -0,0 +1,62 @@
1#pragma once
2#include <memory>
3#include <unordered_map>
4
5#include "Puzzle.h"
6
7class Memory;
8
9class PuzzleSerializer {
10public:
11 PuzzleSerializer(const std::shared_ptr<Memory>& memory);
12 Puzzle ReadPuzzle(int id);
13 void WritePuzzle(const Puzzle& p, int id);
14
15private:
16 // @Bug: Blue and orange are swapped?
17 enum Flags {
18 IS_ENDPOINT = 0x1,
19 IS_STARTPOINT = 0x2,
20 HAS_NO_CONN = 0x8,
21 HAS_DOT = 0x20,
22 DOT_IS_BLUE = 0x100,
23 DOT_IS_ORANGE = 0x200,
24 DOT_IS_INVISIBLE = 0x1000,
25 HAS_ONE_CONN = 0x100000,
26 HAS_VERTI_CONN = 0x200000,
27 HAS_HORIZ_CONN = 0x400000,
28 };
29
30 void ReadIntersections(Puzzle& p);
31 void ReadExtras(Puzzle& p);
32 void ReadDecorations(Puzzle& p, int id);
33 void ReadSequence(Puzzle& p, int id);
34
35 void WriteIntersections(const Puzzle& p);
36 void WriteDots(const Puzzle& p);
37 void WriteGaps(const Puzzle& p);
38 void WriteEndpoints(const Puzzle& p);
39 void WriteDecorations(const Puzzle& p, int id);
40 void WriteSequence(const Puzzle& p, int id);
41
42 std::tuple<int, int> loc_to_xy(const Puzzle& p, int location) const;
43 int xy_to_loc(const Puzzle& p, int x, int y) const;
44 // Decoration location
45 std::tuple<int, int> dloc_to_xy(const Puzzle& p, int location) const;
46 int xy_to_dloc(const Puzzle& p, int x, int y) const;
47 // Grid coordinates
48 std::tuple<float, float> xy_to_pos(const Puzzle& p, int x, int y) const;
49 Cell::Dot FlagsToDot(int flags) const;
50 // Iterate connection lists for another location which is connected to us; return that other location.
51 int FindConnection(int location) const;
52
53 std::shared_ptr<Memory> _memory;
54
55 std::vector<float> _intersectionLocations;
56 std::vector<int> _intersectionFlags;
57 std::vector<int> _connectionsA;
58 std::vector<int> _connectionsB;
59 std::vector<std::tuple<int, int, int>> _endpointLocations;
60
61 float MIN, MAX, WIDTH_INTERVAL, HEIGHT_INTERVAL, HORIZ_GAP_SIZE, VERTI_GAP_SIZE;
62};