summaryrefslogtreecommitdiffstats
path: root/svgbob/src/location.rs
blob: 686a7f3a93b12bafaa7be0c70b60a514d7417491 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use self::Direction::{Top,Bottom,Left,Right};
use point_block::PointBlock;
use block::{Block::{self,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y}};
/// a location in the grid
/// relative to the focused char
/// go to direction and how many steps to get there
#[derive(Debug, Clone, PartialOrd, PartialEq, Ord, Eq)]
pub struct Location(pub Vec<(Direction, usize)>);

/// 8 directions which a character can connect to
///   \|/
///   -+-
///   /|\

#[derive(Debug, Clone, PartialOrd, PartialEq, Ord, Eq)]
pub enum Direction {
    Top,
    Bottom,
    Left,
    Right,
    TopLeft,
    TopRight,
    BottomLeft,
    BottomRight,
}

impl Location {
    pub fn go(direction: Direction) -> Self {
        Self::jump(direction, 1)
    }

    // this location
    // TODO: hacky fix these
    pub fn this()-> Self{
        Self::jump(Right, 0)
    }

    pub fn jump(direction: Direction, step: usize) -> Self {
        Location(vec![(direction, step)])
    }


    fn jump_to(&mut self, direction: Direction, step: usize) {
        self.0.push((direction, step));
    }

    fn go_jump(&self, direction: Direction, step: usize) -> Self {
        let mut loc = self.clone();
        loc.jump_to(direction, step);
        loc
    }

    fn go_top(&self, step: usize) -> Self {
        self.go_jump(Top, step)
    }
    fn go_left(&self, step: usize) -> Self {
        self.go_jump(Left, step)
    }
    fn go_bottom(&self, step: usize) -> Self {
        self.go_jump(Bottom, step)
    }
    fn go_right(&self, step: usize) -> Self {
        self.go_jump(Right, step)
    }

    pub fn top(&self) -> Self {
        self.go_top(1)
    }
    pub fn bottom(&self) -> Self {
        self.go_bottom(1)
    }
    pub fn left(&self) -> Self {
        self.go_left(1)
    }
    pub fn right(&self) -> Self {
        self.go_right(1)
    }

    pub fn a(&self) -> PointBlock {
        self.block(A)
    }

    pub fn b(&self) -> PointBlock {
        self.block(B)
    }
    pub fn c(&self) -> PointBlock {
        self.block(C)
    }
    pub fn d(&self) -> PointBlock {
        self.block(D)
    }
    pub fn e(&self) -> PointBlock {
        self.block(E)
    }
    pub fn f(&self) -> PointBlock {
        self.block(F)
    }
    pub fn g(&self) -> PointBlock {
        self.block(G)
    }
    pub fn h(&self) -> PointBlock {
        self.block(H)
    }
    pub fn i(&self) -> PointBlock {
        self.block(I)
    }
    pub fn j(&self) -> PointBlock {
        self.block(J)
    }
    pub fn k(&self) -> PointBlock {
        self.block(K)
    }
    pub fn l(&self) -> PointBlock {
        self.block(L)
    }
    pub fn m(&self) -> PointBlock {
        self.block(M)
    }
    pub fn n(&self) -> PointBlock {
        self.block(N)
    }
    pub fn o(&self) -> PointBlock {
        self.block(O)
    }
    pub fn p(&self) -> PointBlock {
        self.block(P)
    }
    pub fn q(&self) -> PointBlock {
        self.block(Q)
    }
    pub fn r(&self) -> PointBlock {
        self.block(R)
    }
    pub fn s(&self) -> PointBlock {
        self.block(S)
    }
    pub fn t(&self) -> PointBlock {
        self.block(T)
    }
    pub fn u(&self) -> PointBlock {
        self.block(U)
    }
    pub fn v(&self) -> PointBlock {
        self.block(V)
    }
    pub fn w(&self) -> PointBlock {
        self.block(W)
    }
    pub fn x(&self) -> PointBlock {
        self.block(X)
    }
    pub fn y(&self) -> PointBlock {
        self.block(Y)
    }

    pub fn block(&self, block: Block) -> PointBlock {
        PointBlock {
            location: Some(self.clone()),
            block: block,
            adjust_x: 0.0,
            adjust_y: 0.0
        }
    }
}