about summary refs log tree commit diff stats
path: root/Source/Panel.h
blob: caa7b048ba426504e784a7756c836d44de17d304 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include <memory>
#include <vector>

class Memory;

enum Shape {
    Stone =      0x100,
    Star =       0x200,
    Poly =       0x400,
    Eraser =     0x500,
    Triangle =   0x600,
    RPoly =     0x1000,
    Ylop =      0x2000,
};

enum Color {
    Black =     0x1,
    White =     0x2,
    Gray =      0x3,
    Purple =    0x4,
    Green =     0x5,
    Cyan =      0x6,
    Pink =      0x7,
    Yellow =    0x8,
    Blue =      0x9,
    Orange =    0xA,
};

struct Decoration {
    Shape type;
    Color color;
    int polyshape;
    // For triangles only
    int count;
};

struct Cell {
    bool start;
    enum class Dir {NONE, LEFT, RIGHT, UP, DOWN};
    Dir end;
    std::shared_ptr<Decoration> decoration;
    enum class Dot {NONE, BLACK, BLUE, YELLOW, INVISIBLE};
    Dot dot;
    enum class Gap {NONE, BREAK, FULL};
    Gap gap;
};

struct Puzzle {
    int16_t height;
    int16_t width;
    std::vector<std::vector<Cell>> grid;

    enum class Symmetry {NONE, X, Y, XY};
    Symmetry sym;
    bool pillar;
};

class PuzzleSerializer {
public:
    PuzzleSerializer(const std::shared_ptr<Memory>& memory);
    Puzzle ReadPuzzle(int id);
    void WritePuzzle(const Puzzle& p, int id);

private:
    // @Bug: Blue and orange are swapped?
    enum Flags {
        IS_ENDPOINT =           0x1,
        IS_STARTPOINT =         0x2,
        DOT_IS_BLUE =         0x100,
        DOT_IS_ORANGE =       0x200,
        DOT_IS_INVISIBLE =   0x1000,
        IS_GAP =            0x10000,
        HAS_DOT =           0x40020,
    };

    void ReadIntersections(Puzzle& p, int id);
    void ReadDecorations(Puzzle& p, int id);
    void WriteIntersections(const Puzzle& p, int id);
    void WriteDecorations(const Puzzle& p, int id);

    std::tuple<int, int> loc_to_xy(const Puzzle& p, int location);
    int xy_to_loc(const Puzzle& p, int x, int y);
    // Decoration location
    std::tuple<int, int> dloc_to_xy(const Puzzle& p, int location);
    int xy_to_dloc(const Puzzle& p, int x, int y);
    Cell::Dot FlagsToDot(int flags);

    std::shared_ptr<Memory> _memory;
};