about summary refs log tree commit diff stats
path: root/Source/PuzzlerSerializer.h
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2019-11-14 09:12:38 -0800
committerjbzdarkid <jbzdarkid@gmail.com>2019-11-14 09:12:38 -0800
commit0d0abe2ee56382c5751dd12fbca75af87773879f (patch)
tree3a1926ea915cf8b222769ca16c8fc83778738519 /Source/PuzzlerSerializer.h
parent1b833a86102981ce178119fc3526f354b7622170 (diff)
downloadwitness-tutorializer-0d0abe2ee56382c5751dd12fbca75af87773879f.tar.gz
witness-tutorializer-0d0abe2ee56382c5751dd12fbca75af87773879f.tar.bz2
witness-tutorializer-0d0abe2ee56382c5751dd12fbca75af87773879f.zip
Refactoring - split out puzzle from serializer
Diffstat (limited to 'Source/PuzzlerSerializer.h')
-rw-r--r--Source/PuzzlerSerializer.h45
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
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 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};