11function move! (cur_player:: AbstractPlayer , with_shadow:: Bool = true )
22
3+ # ==================
4+ # handle repl move
5+ # ==================
6+
7+ if is_repl
8+ _move_repl (cur_player)
9+
10+ cur_player. clock. lock =
11+ Nullable {Base.Random.UUID} ()
12+
13+ return
14+ end
15+
316 # ====================
417 # start from scratch
518 # ====================
@@ -14,53 +27,6 @@ function move!(cur_player::AbstractPlayer, with_shadow::Bool=true)
1427 """
1528 end
1629
17- if is_repl
18- cur_string = []
19-
20- cur_piece = cur_player. piece
21-
22- cur_piece_coords = map (
23- cur_block -> calc_block_coords (cur_block),
24- cur_piece. blocks
25- )
26-
27- row_info = map (first, cur_piece_coords)
28- col_info = map (last, cur_piece_coords)
29-
30- max_row = min (cur_player. grid. rows, maximum (row_info) + cur_player. piece. width )
31-
32- min_col = max (1 , minimum (col_info) - cur_player. piece. width )
33- max_col = min (cur_player. grid. cols, maximum (col_info) + cur_player. piece. width )
34-
35- cur_shadow = cur_player. shadow
36-
37- cur_shadow_coords = map (
38- cur_block -> calc_block_coords (cur_block),
39- cur_shadow. blocks
40- )
41-
42- for cur_row in 1 : max_row
43- for cur_col in 1 : cur_player. grid. cols
44- has_piece = cur_player. grid. table[cur_row, cur_col] != " "
45- has_piece && continue
46-
47- if in ((cur_row, cur_col), cur_piece_coords)
48- cur_color = cur_piece. color
49- elseif in ((cur_row, cur_col), cur_shadow_coords)
50- cur_color = " $(cur_piece. color) _shadow"
51- else
52- cur_color = " invisible"
53- end
54-
55- push! (cur_string, " \x 1b[$(cur_player. grid. rows- cur_row+ 4 ) ;$(8 + 2 * cur_col) H" )
56- push! (cur_string, crayon_dict[cur_color])
57- push! (cur_string, " " )
58- push! (cur_string, inv (crayon_dict[cur_color]))
59- end
60- end
61-
62- end
63-
6430 # ==============
6531 # update score
6632 # ==============
@@ -73,9 +39,7 @@ function move!(cur_player::AbstractPlayer, with_shadow::Bool=true)
7339 # re-add piece
7440 # ==============
7541
76- if is_ide
77- cur_piece = cur_player. piece
78- end
42+ cur_piece = cur_player. piece
7943
8044 cur_coords = map (
8145 cur_block -> calc_block_coords (cur_block),
@@ -97,8 +61,6 @@ function move!(cur_player::AbstractPlayer, with_shadow::Bool=true)
9761 """
9862 end
9963
100- is_repl && append! (cur_string, _move_repl (cur_player, cur_coords, false ))
101-
10264 # ==============
10365 # return early
10466 # if no shadow
@@ -117,9 +79,7 @@ function move!(cur_player::AbstractPlayer, with_shadow::Bool=true)
11779 # add shadow
11880 # ============
11981
120- if is_ide
121- cur_shadow = cur_player. shadow
122- end
82+ cur_shadow = cur_player. shadow
12383
12484 cur_coords = map (
12585 cur_block -> calc_block_coords (cur_block),
@@ -135,8 +95,6 @@ function move!(cur_player::AbstractPlayer, with_shadow::Bool=true)
13595 """
13696 end
13797
138- is_repl && append! (cur_string, _move_repl (cur_player, cur_coords, true ))
139-
14098 # ====================
14199 # remove bad borders
142100 # ====================
@@ -172,11 +130,6 @@ function move!(cur_player::AbstractPlayer, with_shadow::Bool=true)
172130 # wrap up move
173131 # ==============
174132
175- if is_repl
176- push! (cur_string, " \x 1b[u" )
177- print (cur_string... )
178- end
179-
180133 tetris_js (cur_player. game. scope, JSString (cur_js))
181134
182135 cur_player. clock. lock =
@@ -186,19 +139,51 @@ function move!(cur_player::AbstractPlayer, with_shadow::Bool=true)
186139
187140end
188141
189- function _move_repl (cur_player:: AbstractPlayer , cur_coords :: Vector{Tuple{Int64,Int64}} , is_shadow )
142+ function _move_repl (cur_player:: AbstractPlayer )
190143 cur_string = []
191144
192- cur_color = cur_player. piece. color
193- is_shadow && ( cur_color *= " _shadow" )
145+ cur_piece = cur_player. piece
194146
195- for (cur_row, cur_col) in cur_coords
196- ( cur_row > cur_player. grid. rows ) && continue
197- push! (cur_string, " \x 1b[$(cur_player. grid. rows- cur_row+ 4 ) ;$(8 + 2 * cur_col) H" )
198- push! (cur_string, crayon_dict[cur_color])
199- push! (cur_string, " " )
200- push! (cur_string, inv (crayon_dict[cur_color]))
147+ cur_piece_coords = map (
148+ cur_block -> calc_block_coords (cur_block),
149+ cur_piece. blocks
150+ )
151+
152+ row_info = map (first, cur_piece_coords)
153+ col_info = map (last, cur_piece_coords)
154+
155+ max_row = min (cur_player. grid. rows, maximum (row_info) + cur_player. piece. width )
156+
157+ min_col = max (1 , minimum (col_info) - cur_player. piece. width )
158+ max_col = min (cur_player. grid. cols, maximum (col_info) + cur_player. piece. width )
159+
160+ cur_shadow = cur_player. shadow
161+
162+ cur_shadow_coords = map (
163+ cur_block -> calc_block_coords (cur_block),
164+ cur_shadow. blocks
165+ )
166+
167+ for cur_row in 1 : max_row
168+ for cur_col in 1 : cur_player. grid. cols
169+ has_piece = cur_player. grid. table[cur_row, cur_col] != " "
170+ has_piece && continue
171+
172+ if in ((cur_row, cur_col), cur_piece_coords)
173+ cur_color = cur_piece. color
174+ elseif in ((cur_row, cur_col), cur_shadow_coords)
175+ cur_color = " $(cur_piece. color) _shadow"
176+ else
177+ cur_color = " invisible"
178+ end
179+
180+ push! (cur_string, " \x 1b[$(cur_player. grid. rows- cur_row+ 4 ) ;$(29 + 2 * cur_col) H" )
181+ push! (cur_string, crayon_dict[cur_color])
182+ push! (cur_string, " " )
183+ push! (cur_string, inv (crayon_dict[cur_color]))
184+ end
201185 end
202186
203- return cur_string
187+ push! (cur_string, " \x 1b[u" )
188+ print (cur_string... )
204189end
0 commit comments