diff options
Diffstat (limited to 'Source/PuzzlerSerializer.h')
-rw-r--r-- | Source/PuzzlerSerializer.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Source/PuzzlerSerializer.h b/Source/PuzzlerSerializer.h new file mode 100644 index 0000000..00c89f5 --- /dev/null +++ b/Source/PuzzlerSerializer.h | |||
@@ -0,0 +1,45 @@ | |||
1 | #pragma once | ||
2 | #include <memory> | ||
3 | |||
4 | #include "Puzzle.h" | ||
5 | |||
6 | |||
7 | class Memory; | ||
8 | |||
9 | class PuzzleSerializer { | ||
10 | public: | ||
11 | PuzzleSerializer(const std::shared_ptr<Memory>& memory); | ||
12 | Puzzle ReadPuzzle(int id); | ||
13 | void WritePuzzle(const Puzzle& p, int id); | ||
14 | |||
15 | private: | ||
16 | // @Bug: Blue and orange are swapped? | ||
17 | enum Flags { | ||
18 | IS_ENDPOINT = 0x1, | ||
19 | IS_STARTPOINT = 0x2, | ||
20 | IS_FULL_GAP = 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, int id); | ||
31 | void ReadDecorations(Puzzle& p, int id); | ||
32 | void WriteIntersections(const Puzzle& p, int id); | ||
33 | void WriteDecorations(const Puzzle& p, int id); | ||
34 | |||
35 | std::tuple<int, int> loc_to_xy(const Puzzle& p, int location) const; | ||
36 | int xy_to_loc(const Puzzle& p, int x, int y) const; | ||
37 | // Decoration location | ||
38 | std::tuple<int, int> dloc_to_xy(const Puzzle& p, int location) const; | ||
39 | int xy_to_dloc(const Puzzle& p, int x, int y) const; | ||
40 | Cell::Dot FlagsToDot(int flags) const; | ||
41 | // Iterate connection lists for another location which is connected to us; return that other location. | ||
42 | int FindConnection(int i, const std::vector<int>& connections_a, const std::vector<int>& connections_b) const; | ||
43 | |||
44 | std::shared_ptr<Memory> _memory; | ||
45 | }; | ||