glimmer-dsl-libui 0.2.16 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.16
1
+ 0.2.20
data/bin/girb CHANGED
File without changes
@@ -18,31 +18,24 @@ window('Area Gallery', 400, 400) {
18
18
  fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
19
19
  }
20
20
  path { # declarative stable path
21
- figure(100, 100) {
22
- line(100, 400)
23
- line(400, 100)
24
- line(400, 400)
25
-
26
- closed true
27
- }
28
-
21
+ polygon(100, 100, 100, 400, 400, 100, 400, 400)
22
+
29
23
  fill r: 202, g: 102, b: 104, a: 0.5
30
24
  stroke r: 0, g: 0, b: 0
31
25
  }
32
26
  path { # declarative stable path
33
- figure(0, 0) {
34
- bezier(200, 100, 100, 200, 400, 100)
35
- bezier(300, 100, 100, 300, 100, 400)
36
- bezier(100, 300, 300, 100, 400, 400)
37
-
38
- closed true
39
- }
27
+ polybezier(0, 0, 200, 100, 100, 200, 400, 100, 300, 100, 100, 300, 100, 400, 100, 300, 300, 100, 400, 400)
40
28
 
41
29
  fill r: 202, g: 102, b: 204, a: 0.5
42
30
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
43
31
  }
44
32
  path { # declarative stable path
45
- arc(400, 220, 180, 90, 90, false)
33
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
34
+
35
+ stroke r: 0, g: 0, b: 0, thickness: 2
36
+ }
37
+ path { # declarative stable path
38
+ arc(404, 216, 190, 90, 90, false)
46
39
 
47
40
  # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
48
41
  fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
@@ -54,9 +47,9 @@ window('Area Gallery', 400, 400) {
54
47
  fill r: 202, g: 102, b: 204, a: 0.5
55
48
  stroke r: 0, g: 0, b: 0, thickness: 2
56
49
  }
57
- text(160, 40, 100) { # x, y, width
50
+ text(161, 40, 100) { # x, y, width
58
51
  string('Area Gallery') {
59
- font family: 'Times', size: 14
52
+ font family: 'Arial', size: 14
60
53
  color :black
61
54
  }
62
55
  }
@@ -88,18 +88,42 @@ window('Area Gallery', 400, 400) {
88
88
  end_x 400
89
89
  end_y 400
90
90
  }
91
-
92
- closed true
93
91
  }
94
92
 
95
93
  fill r: 202, g: 102, b: 204, a: 0.5
96
94
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
97
95
  }
96
+ path { # declarative stable path
97
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
98
+ figure {
99
+ x 100
100
+ y 100
101
+
102
+ line {
103
+ x 400
104
+ y 100
105
+ }
106
+ line {
107
+ x 100
108
+ y 400
109
+ }
110
+ line {
111
+ x 400
112
+ y 400
113
+ }
114
+ line {
115
+ x 0
116
+ y 0
117
+ }
118
+ }
119
+
120
+ stroke r: 0, g: 0, b: 0, thickness: 2
121
+ }
98
122
  path { # declarative stable path
99
123
  arc {
100
- x_center 400
101
- y_center 220
102
- radius 180
124
+ x_center 404
125
+ y_center 216
126
+ radius 190
103
127
  start_angle 90
104
128
  sweep 90
105
129
  is_negative false
@@ -120,12 +144,12 @@ window('Area Gallery', 400, 400) {
120
144
  stroke r: 0, g: 0, b: 0, thickness: 2
121
145
  }
122
146
  text {
123
- x 160
147
+ x 161
124
148
  y 40
125
149
  width 100
126
150
 
127
151
  string {
128
- font family: 'Times', size: 14
152
+ font family: 'Arial', size: 14
129
153
  color :black
130
154
 
131
155
  'Area Gallery'
@@ -8,42 +8,35 @@ window('Area Gallery', 400, 400) {
8
8
  path { # a dynamic path is added semi-declaratively inside on_draw block
9
9
  square(0, 0, 100)
10
10
  square(100, 100, 400)
11
-
11
+
12
12
  fill r: 102, g: 102, b: 204
13
13
  }
14
14
  path { # a dynamic path is added semi-declaratively inside on_draw block
15
15
  rectangle(0, 100, 100, 400)
16
16
  rectangle(100, 0, 400, 100)
17
-
17
+
18
18
  # linear gradient (has x0, y0, x1, y1, and stops)
19
19
  fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
20
20
  }
21
21
  path { # a dynamic path is added semi-declaratively inside on_draw block
22
- figure(100, 100) {
23
- line(100, 400)
24
- line(400, 100)
25
- line(400, 400)
26
-
27
- closed true
28
- }
29
-
22
+ polygon(100, 100, 100, 400, 400, 100, 400, 400)
23
+
30
24
  fill r: 202, g: 102, b: 104, a: 0.5
31
25
  stroke r: 0, g: 0, b: 0
32
26
  }
33
27
  path { # a dynamic path is added semi-declaratively inside on_draw block
34
- figure(0, 0) {
35
- bezier(200, 100, 100, 200, 400, 100)
36
- bezier(300, 100, 100, 300, 100, 400)
37
- bezier(100, 300, 300, 100, 400, 400)
38
-
39
- closed true
40
- }
41
-
28
+ polybezier(0, 0, 200, 100, 100, 200, 400, 100, 300, 100, 100, 300, 100, 400, 100, 300, 300, 100, 400, 400)
29
+
42
30
  fill r: 202, g: 102, b: 204, a: 0.5
43
31
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
44
32
  }
45
33
  path { # a dynamic path is added semi-declaratively inside on_draw block
46
- arc(400, 220, 180, 90, 90, false)
34
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
35
+
36
+ stroke r: 0, g: 0, b: 0, thickness: 2
37
+ }
38
+ path { # a dynamic path is added semi-declaratively inside on_draw block
39
+ arc(404, 216, 190, 90, 90, false)
47
40
 
48
41
  # radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
49
42
  fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
@@ -55,9 +48,9 @@ window('Area Gallery', 400, 400) {
55
48
  fill r: 202, g: 102, b: 204, a: 0.5
56
49
  stroke r: 0, g: 0, b: 0, thickness: 2
57
50
  }
58
- text(160, 40, 100) { # x, y, width
51
+ text(161, 40, 100) { # x, y, width
59
52
  string('Area Gallery') {
60
- font family: 'Times', size: 14
53
+ font family: 'Arial', size: 14
61
54
  color :black
62
55
  }
63
56
  }
@@ -53,10 +53,10 @@ window('Area Gallery', 400, 400) {
53
53
  x 400
54
54
  y 400
55
55
  }
56
-
56
+
57
57
  closed true
58
58
  }
59
-
59
+
60
60
  fill r: 202, g: 102, b: 104, a: 0.5
61
61
  stroke r: 0, g: 0, b: 0
62
62
  }
@@ -89,18 +89,42 @@ window('Area Gallery', 400, 400) {
89
89
  end_x 400
90
90
  end_y 400
91
91
  }
92
-
93
- closed true
94
92
  }
95
-
93
+
96
94
  fill r: 202, g: 102, b: 204, a: 0.5
97
95
  stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
98
96
  }
97
+ path { # a dynamic path is added semi-declaratively inside on_draw block
98
+ polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
99
+ figure {
100
+ x 100
101
+ y 100
102
+
103
+ line {
104
+ x 400
105
+ y 100
106
+ }
107
+ line {
108
+ x 100
109
+ y 400
110
+ }
111
+ line {
112
+ x 400
113
+ y 400
114
+ }
115
+ line {
116
+ x 0
117
+ y 0
118
+ }
119
+ }
120
+
121
+ stroke r: 0, g: 0, b: 0, thickness: 2
122
+ }
99
123
  path { # a dynamic path is added semi-declaratively inside on_draw block
100
124
  arc {
101
- x_center 400
102
- y_center 220
103
- radius 180
125
+ x_center 404
126
+ y_center 216
127
+ radius 190
104
128
  start_angle 90
105
129
  sweep 90
106
130
  is_negative false
@@ -121,12 +145,12 @@ window('Area Gallery', 400, 400) {
121
145
  stroke r: 0, g: 0, b: 0, thickness: 2
122
146
  }
123
147
  text {
124
- x 160
148
+ x 161
125
149
  y 40
126
150
  width 100
127
151
 
128
152
  string {
129
- font family: 'Times', size: 14
153
+ font family: 'Arial', size: 14
130
154
  color :black
131
155
 
132
156
  'Area Gallery'
@@ -31,20 +31,13 @@ end
31
31
 
32
32
  # method-based custom control representing a graph path
33
33
  def graph_path(width, height, should_extend, &block)
34
- locations = point_locations(width, height)
34
+ locations = point_locations(width, height).flatten
35
35
  path {
36
- first_location = locations[0] # x and y
37
- figure(first_location[0], first_location[1]) {
38
- locations.each do |loc|
39
- line(loc[0], loc[1])
40
- end
41
- if should_extend
42
- line(width, height)
43
- line(0, height)
44
-
45
- closed true
46
- end
47
- }
36
+ if should_extend
37
+ polygon(locations + [width, height, 0, height])
38
+ else
39
+ polyline(locations)
40
+ end
48
41
 
49
42
  # apply a transform to the coordinate space for this path so (0, 0) is the top-left corner of the graph
50
43
  transform {
@@ -11,7 +11,7 @@ class MetaExample
11
11
 
12
12
  def examples
13
13
  if @examples.nil?
14
- example_files = Dir.glob(File.join(File.expand_path('.', __dir__), '**', '*.rb'))
14
+ example_files = Dir.glob(File.join(File.expand_path('.', __dir__), '*.rb'))
15
15
  example_file_names = example_files.map { |f| File.basename(f, '.rb') }
16
16
  example_file_names = example_file_names.reject { |f| f == 'meta_example' || f.match(/\d$/) }
17
17
  @examples = example_file_names.map { |f| f.underscore.titlecase }
@@ -110,6 +110,8 @@ class MetaExample
110
110
  FileUtils.mkdir_p(parent_dir)
111
111
  example_file = File.join(parent_dir, "#{selected_example.underscore}.rb")
112
112
  File.write(example_file, @code_entry.text)
113
+ example_supporting_directory = File.expand_path(selected_example.underscore, __dir__)
114
+ FileUtils.cp_r(example_supporting_directory, parent_dir) if Dir.exist?(example_supporting_directory)
113
115
  FileUtils.cp_r(File.expand_path('../icons', __dir__), File.dirname(parent_dir))
114
116
  FileUtils.cp_r(File.expand_path('../sounds', __dir__), File.dirname(parent_dir))
115
117
  run_example(example_file)
@@ -0,0 +1,48 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Tetris
23
+ module Model
24
+ class Block
25
+ COLOR_CLEAR = :white
26
+
27
+ attr_accessor :color
28
+
29
+ # Initializes with color. Default color (gray) signifies an empty block
30
+ def initialize(color = COLOR_CLEAR)
31
+ @color = color
32
+ end
33
+
34
+ # Clears block color. `quietly` option indicates if it should not notify observers by setting value quietly via variable not attribute writer.
35
+ def clear
36
+ self.color = COLOR_CLEAR unless self.color == COLOR_CLEAR
37
+ end
38
+
39
+ def clear?
40
+ self.color == COLOR_CLEAR
41
+ end
42
+
43
+ def occupied?
44
+ !clear?
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,308 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'fileutils'
23
+ require 'json'
24
+ require 'glimmer/data_binding/observer'
25
+ require 'glimmer/config'
26
+
27
+ require_relative 'block'
28
+ require_relative 'tetromino'
29
+ require_relative 'past_game'
30
+
31
+ class Tetris
32
+ module Model
33
+ class Game
34
+ PLAYFIELD_WIDTH = 10
35
+ PLAYFIELD_HEIGHT = 20
36
+ PREVIEW_PLAYFIELD_WIDTH = 4
37
+ PREVIEW_PLAYFIELD_HEIGHT = 2
38
+ SCORE_MULTIPLIER = {1 => 40, 2 => 100, 3 => 300, 4 => 1200}
39
+
40
+ attr_reader :playfield_width, :playfield_height
41
+ attr_accessor :game_over, :paused, :preview_tetromino, :lines, :score, :level, :high_scores, :beeping, :added_high_score, :show_high_scores, :up_arrow_action
42
+ alias game_over? game_over
43
+ alias paused? paused
44
+ alias beeping? beeping
45
+ alias added_high_score? added_high_score
46
+
47
+ def initialize(playfield_width = PLAYFIELD_WIDTH, playfield_height = PLAYFIELD_HEIGHT)
48
+ @playfield_width = playfield_width
49
+ @playfield_height = playfield_height
50
+ @high_scores = []
51
+ @show_high_scores = false
52
+ @beeping = true
53
+ @up_arrow_action = :rotate_left
54
+ load_high_scores!
55
+ end
56
+
57
+ def configure_beeper(&beeper)
58
+ @beeper = beeper
59
+ end
60
+
61
+ def game_in_progress?
62
+ !game_over? && !paused?
63
+ end
64
+
65
+ def start!
66
+ self.show_high_scores = false
67
+ self.paused = false
68
+ self.level = 1
69
+ self.score = 0
70
+ self.lines = 0
71
+ reset_playfield
72
+ reset_preview_playfield
73
+ reset_tetrominoes
74
+ preview_next_tetromino!
75
+ consider_adding_tetromino
76
+ self.game_over = false
77
+ end
78
+ alias restart! start!
79
+
80
+ def game_over!
81
+ add_high_score!
82
+ beep
83
+ self.game_over = true
84
+ end
85
+
86
+ def clear_high_scores!
87
+ high_scores.clear
88
+ save_high_scores!
89
+ end
90
+
91
+ def add_high_score!
92
+ self.added_high_score = true
93
+ high_scores.prepend(PastGame.new("Player #{high_scores.count + 1}", score, lines, level))
94
+ save_high_scores!
95
+ end
96
+
97
+ def save_high_scores!
98
+ high_score_file_content = @high_scores.map {|past_game| past_game.to_a.join("\t") }.join("\n")
99
+ FileUtils.mkdir_p(tetris_dir)
100
+ File.write(tetris_high_score_file, high_score_file_content)
101
+ rescue => e
102
+ # Fail safely by keeping high scores in memory if unable to access disk
103
+ Glimmer::Config.logger.error {"Failed to save high scores in: #{tetris_high_score_file}\n#{e.full_message}"}
104
+ end
105
+
106
+ def load_high_scores!
107
+ if File.exist?(tetris_high_score_file)
108
+ self.high_scores = File.read(tetris_high_score_file).split("\n").map {|line| PastGame.new(*line.split("\t")) }
109
+ end
110
+ rescue => e
111
+ # Fail safely by keeping high scores in memory if unable to access disk
112
+ Glimmer::Config.logger.error {"Failed to load high scores from: #{tetris_high_score_file}\n#{e.full_message}"}
113
+ end
114
+
115
+ def tetris_dir
116
+ @tetris_dir ||= File.join(File.expand_path('~'), '.glimmer-tetris')
117
+ end
118
+
119
+ def tetris_high_score_file
120
+ File.join(tetris_dir, "high_scores.txt")
121
+ end
122
+
123
+ def down!(instant: false)
124
+ return unless game_in_progress?
125
+ current_tetromino.down!(instant: instant)
126
+ game_over! if current_tetromino.row <= 0 && current_tetromino.stopped?
127
+ end
128
+
129
+ def right!
130
+ return unless game_in_progress?
131
+ current_tetromino.right!
132
+ end
133
+
134
+ def left!
135
+ return unless game_in_progress?
136
+ current_tetromino.left!
137
+ end
138
+
139
+ def rotate!(direction)
140
+ return unless game_in_progress?
141
+ current_tetromino.rotate!(direction)
142
+ end
143
+
144
+ def current_tetromino
145
+ tetrominoes.last
146
+ end
147
+
148
+ def tetrominoes
149
+ @tetrominoes ||= reset_tetrominoes
150
+ end
151
+
152
+ # Returns blocks in the playfield
153
+ def playfield
154
+ @playfield ||= @original_playfield = @playfield_height.times.map do
155
+ @playfield_width.times.map do
156
+ Block.new
157
+ end
158
+ end
159
+ end
160
+
161
+ # Executes a hypothetical scenario without truly changing playfield permanently
162
+ def hypothetical(&block)
163
+ @playfield = hypothetical_playfield
164
+ block.call
165
+ @playfield = @original_playfield
166
+ end
167
+
168
+ # Returns whether currently executing a hypothetical scenario
169
+ def hypothetical?
170
+ @playfield != @original_playfield
171
+ end
172
+
173
+ def hypothetical_playfield
174
+ @playfield_height.times.map { |row|
175
+ @playfield_width.times.map { |column|
176
+ playfield[row][column].clone
177
+ }
178
+ }
179
+ end
180
+
181
+ def preview_playfield
182
+ @preview_playfield ||= PREVIEW_PLAYFIELD_HEIGHT.times.map {|row|
183
+ PREVIEW_PLAYFIELD_WIDTH.times.map {|column|
184
+ Block.new
185
+ }
186
+ }
187
+ end
188
+
189
+ def preview_next_tetromino!
190
+ self.preview_tetromino = Tetromino.new(self)
191
+ end
192
+
193
+ def calculate_score!(eliminated_lines)
194
+ new_score = SCORE_MULTIPLIER[eliminated_lines] * (level + 1)
195
+ self.score += new_score
196
+ end
197
+
198
+ def level_up!
199
+ self.level += 1 if lines >= self.level*10
200
+ end
201
+
202
+ def delay
203
+ [1.1 - (level.to_i * 0.1), 0.001].max
204
+ end
205
+
206
+ def beep
207
+ @beeper&.call if beeping
208
+ end
209
+
210
+ def instant_down_on_up=(value)
211
+ self.up_arrow_action = :instant_down if value
212
+ end
213
+
214
+ def instant_down_on_up
215
+ self.up_arrow_action == :instant_down
216
+ end
217
+
218
+ def rotate_right_on_up=(value)
219
+ self.up_arrow_action = :rotate_right if value
220
+ end
221
+
222
+ def rotate_right_on_up
223
+ self.up_arrow_action == :rotate_right
224
+ end
225
+
226
+ def rotate_left_on_up=(value)
227
+ self.up_arrow_action = :rotate_left if value
228
+ end
229
+
230
+ def rotate_left_on_up
231
+ self.up_arrow_action == :rotate_left
232
+ end
233
+
234
+ def reset_tetrominoes
235
+ @tetrominoes = []
236
+ end
237
+
238
+ def reset_playfield
239
+ playfield.each do |row|
240
+ row.each do |block|
241
+ block.clear
242
+ end
243
+ end
244
+ end
245
+
246
+ def reset_preview_playfield
247
+ preview_playfield.each do |row|
248
+ row.each do |block|
249
+ block.clear
250
+ end
251
+ end
252
+ end
253
+
254
+ def consider_adding_tetromino
255
+ if tetrominoes.empty? || current_tetromino.stopped?
256
+ preview_tetromino.launch!
257
+ preview_next_tetromino!
258
+ end
259
+ end
260
+
261
+ def consider_eliminating_lines
262
+ eliminated_lines = 0
263
+ playfield.each_with_index do |row, playfield_row|
264
+ if row.all? {|block| !block.clear?}
265
+ eliminated_lines += 1
266
+ shift_blocks_down_above_row(playfield_row)
267
+ end
268
+ end
269
+ if eliminated_lines > 0
270
+ beep
271
+ self.lines += eliminated_lines
272
+ level_up!
273
+ calculate_score!(eliminated_lines)
274
+ end
275
+ end
276
+
277
+ def playfield_remaining_heights(tetromino = nil)
278
+ @playfield_width.times.map do |playfield_column|
279
+ bottom_most_block = tetromino.bottom_most_block_for_column(playfield_column)
280
+ (playfield.each_with_index.detect do |row, playfield_row|
281
+ !row[playfield_column].clear? &&
282
+ (
283
+ tetromino.nil? ||
284
+ bottom_most_block.nil? ||
285
+ (playfield_row > tetromino.row + bottom_most_block[:row_index])
286
+ )
287
+ end || [nil, @playfield_height])[1]
288
+ end.to_a
289
+ end
290
+
291
+ private
292
+
293
+ def shift_blocks_down_above_row(row)
294
+ row.downto(0) do |playfield_row|
295
+ playfield[playfield_row].each_with_index do |block, playfield_column|
296
+ previous_row = playfield[playfield_row - 1]
297
+ previous_block = previous_row[playfield_column]
298
+ block.color = previous_block.color unless block.color == previous_block.color
299
+ end
300
+ end
301
+ playfield[0].each(&:clear)
302
+ end
303
+
304
+ end
305
+
306
+ end
307
+
308
+ end