diff options
author | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-18 09:16:16 -0800 |
---|---|---|
committer | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-18 09:16:16 -0800 |
commit | bff40e55c9c55fbc8439bb225d1937b2d805e629 (patch) | |
tree | e3aa7a2912c4208247139a9c2b806035af876a33 /Source/PuzzleSerializer.h | |
parent | 695d0e12950b9df248ea7b84f8434e32acc84f11 (diff) | |
download | witness-tutorializer-bff40e55c9c55fbc8439bb225d1937b2d805e629.tar.gz witness-tutorializer-bff40e55c9c55fbc8439bb225d1937b2d805e629.tar.bz2 witness-tutorializer-bff40e55c9c55fbc8439bb225d1937b2d805e629.zip |
Cleanup & progress on tutorial
Diffstat (limited to 'Source/PuzzleSerializer.h')
-rw-r--r-- | Source/PuzzleSerializer.h | 62 |
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 | |||
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 | 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 | }; | ||