reight 0.1.7 → 0.1.8

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.
@@ -7,7 +7,15 @@ class Reight::SpriteEditor < Reight::App
7
7
  @canvas ||= Canvas.new(
8
8
  self,
9
9
  project.chips_image,
10
- project.chips_image_path)
10
+ project.chips_image_path
11
+ ).tap do |canvas|
12
+ canvas.frame_changed do |old, new|
13
+ history.append [:frame, old, new]
14
+ end
15
+ canvas.selection_changed do |old, new|
16
+ history.append [new ? :select : :deselect, old, new]
17
+ end
18
+ end
11
19
  end
12
20
 
13
21
  def setup()
@@ -50,13 +58,22 @@ class Reight::SpriteEditor < Reight::App
50
58
 
51
59
  def window_resized()
52
60
  super
53
- [colors, tools, chip_sizes, brush_sizes].flatten.map(&:sprite)
61
+ [chip_sizes, tools, colors, brush_sizes].flatten.map(&:sprite)
54
62
  .each {|sp| sp.w = sp.h = BUTTON_SIZE}
55
63
 
64
+ chips_index.sprite.tap do |sp|
65
+ sp.w, sp.h = INDEX_SIZE, BUTTON_SIZE
66
+ sp.x = SPACE
67
+ sp.y = NAVIGATOR_HEIGHT + SPACE
68
+ end
69
+ chip_sizes.reverse.map {_1.sprite}.each.with_index do |sp, index|
70
+ sp.x = SPACE + CHIPS_WIDTH - (sp.w + (sp.w + 1) * index)
71
+ sp.y = chips_index.sprite.y
72
+ end
56
73
  chips.sprite.tap do |sp|
57
74
  sp.x = SPACE
58
- sp.y = NAVIGATOR_HEIGHT + SPACE
59
- sp.w = CHIPS_WIDTH
75
+ sp.y = chip_sizes.last.sprite.bottom + SPACE
76
+ sp.right = chip_sizes.last.sprite.right
60
77
  sp.bottom = height - SPACE
61
78
  end
62
79
  colors.map {_1.sprite}.each.with_index do |sp, index|
@@ -69,19 +86,15 @@ class Reight::SpriteEditor < Reight::App
69
86
  sp.y = colors.first.sprite.y - (SPACE / 2 + sp.h)
70
87
  end
71
88
  canvas.sprite.tap do |sp|
72
- sp.x = chips.sprite.right + SPACE
73
- sp.y = chips.sprite.y
89
+ sp.x = chip_sizes.last.sprite.right + SPACE
90
+ sp.y = chip_sizes.last.sprite.y
74
91
  sp.bottom = tools.first.sprite.top - SPACE / 2
75
92
  sp.w = sp.h
76
93
  end
77
- chip_sizes.map {_1.sprite}.each.with_index do |sp, index|
94
+ brush_sizes.map {_1.sprite}.each.with_index do |sp, index|
78
95
  sp.x = canvas.sprite.right + SPACE + (sp.w + 1) * index
79
96
  sp.y = canvas.sprite.y
80
97
  end
81
- brush_sizes.map {_1.sprite}.each.with_index do |sp, index|
82
- sp.x = chip_sizes.first.sprite.x + (sp.w + 1) * index
83
- sp.y = chip_sizes.last.sprite.bottom + SPACE
84
- end
85
98
  shapes.map {_1.sprite}.each.with_index do |sp, index|
86
99
  sp.w = 30
87
100
  sp.h = BUTTON_SIZE
@@ -163,14 +176,13 @@ class Reight::SpriteEditor < Reight::App
163
176
  private
164
177
 
165
178
  def sprites()
166
- [canvas, chips, *chip_sizes, *colors, *tools, *brush_sizes, *shapes, *types]
179
+ [chips_index, *chip_sizes, chips, *tools, *colors, canvas, *brush_sizes, *shapes, *types]
167
180
  .map(&:sprite) + super
168
181
  end
169
182
 
170
- def chips()
171
- @chips ||= Chips.new self, project.chips_image do |x, y, w, h|
172
- canvas.set_frame x, y, w, h
173
- chip_changed x, y, w, h
183
+ def chips_index()
184
+ @chips_index ||= Reight::Index.new max: project.chips_npages - 1 do |index|
185
+ chips.offset = chips.index2offset index if index != chips.offset2index
174
186
  end
175
187
  end
176
188
 
@@ -182,6 +194,17 @@ class Reight::SpriteEditor < Reight::App
182
194
  })
183
195
  end
184
196
 
197
+ def chips()
198
+ @chips ||= Chips.new(self, project.chips).tap do |chips|
199
+ chips.frame_changed do |x, y, w, h|
200
+ chip_changed x, y, w, h
201
+ end
202
+ chips.offset_changed do |offset|
203
+ chips_index.index = chips.offset2index offset
204
+ end
205
+ end
206
+ end
207
+
185
208
  def tools()
186
209
  @tools ||= group(
187
210
  select,
@@ -204,15 +227,6 @@ class Reight::SpriteEditor < Reight::App
204
227
  def stroke_ellipse = @stroke_ellipse ||= Shape.new(self, :ellipse, false) {canvas.tool = _1}
205
228
  def fill_ellipse = @fill_ellipse ||= Shape.new(self, :ellipse, true) {canvas.tool = _1}
206
229
 
207
- def brush_sizes()
208
- @brush_sizes ||= group(*[1, 2, 3, 5, 10].map {|size|
209
- Reight::Button.new name: "Button Size #{size}", label: size do
210
- brush.size = size
211
- flash "Brush Size #{size}"
212
- end
213
- })
214
- end
215
-
216
230
  def colors()
217
231
  @colors ||= project.palette_colors.map {|color|
218
232
  rgb = self.color(color)
@@ -225,6 +239,15 @@ class Reight::SpriteEditor < Reight::App
225
239
  }
226
240
  end
227
241
 
242
+ def brush_sizes()
243
+ @brush_sizes ||= group(*[1, 2, 3, 5, 10].map {|size|
244
+ Reight::Button.new name: "Button Size #{size}", label: size do
245
+ brush.size = size
246
+ flash "Brush Size #{size}"
247
+ end
248
+ })
249
+ end
250
+
228
251
  def shapes()
229
252
  @shapes ||= group(
230
253
  Reight::Button.new(name: 'No Shape', label: 'None') {
@@ -251,6 +274,7 @@ class Reight::SpriteEditor < Reight::App
251
274
  end
252
275
 
253
276
  def chip_changed(x, y, w, h)
277
+ canvas.set_frame x, y, w, h
254
278
  chip = project.chips.at x, y, w, h
255
279
  shapes[[nil, :rect, :circle].index(chip.shape)].click
256
280
  types[chip.sensor? ? 1 : 0].click
@@ -1,6 +1,5 @@
1
1
  require 'reight/app/sprite/editor'
2
2
  require 'reight/app/sprite/canvas'
3
- require 'reight/app/sprite/chips'
4
3
  require 'reight/app/sprite/color'
5
4
  require 'reight/app/sprite/tool'
6
5
  require 'reight/app/sprite/select'
data/lib/reight/app.rb CHANGED
@@ -8,6 +8,7 @@ class Reight::App
8
8
 
9
9
  SPACE = 6
10
10
  BUTTON_SIZE = 12
11
+ INDEX_SIZE = 36
11
12
  NAVIGATOR_HEIGHT = BUTTON_SIZE + 2
12
13
  CHIPS_WIDTH = 128
13
14
 
@@ -25,6 +26,10 @@ class Reight::App
25
26
 
26
27
  attr_reader :project
27
28
 
29
+ def label()
30
+ self.class.name.split('::').last.gsub(/([a-z])([A-Z])/) {"#{$1} #{$2}"}
31
+ end
32
+
28
33
  def flash(...)
29
34
  navigator.flash(...) if history.enabled?
30
35
  end
@@ -46,10 +51,6 @@ class Reight::App
46
51
  pressing_keys.include? key
47
52
  end
48
53
 
49
- def name()
50
- self.class.name
51
- end
52
-
53
54
  def history()
54
55
  @history ||= Reight::History.new
55
56
  end
data/lib/reight/button.rb CHANGED
@@ -25,7 +25,7 @@ class Reight::Button
25
25
 
26
26
  if @label
27
27
  fill 210
28
- rect 0, pressing? ? 2 : 1, sp.w, sp.h - 1, 2
28
+ rect 0, pressing? ? 1 : 0, sp.w, sp.h, 2
29
29
  end
30
30
 
31
31
  if active?
@@ -44,9 +44,9 @@ class Reight::Button
44
44
  y = pressing? ? 1 : 0
45
45
  text_size r8.project.font_size - 1
46
46
  text_align CENTER, CENTER
47
- fill 100, 100, 100
47
+ fill active? ? 250 : 230
48
48
  text @label, 0, y + 1, sp.w, sp.h
49
- fill 255, 255, 255
49
+ fill active? ? 70 : 50
50
50
  text @label, 0, y, sp.w, sp.h
51
51
  end
52
52
  end
data/lib/reight/chip.rb CHANGED
@@ -77,6 +77,10 @@ class Reight::Chip
77
77
  end
78
78
  end
79
79
 
80
+ def inspect()
81
+ "#<#{self.class.name}:0x#{object_id}>"
82
+ end
83
+
80
84
  # @private
81
85
  def cmp__(o)
82
86
  a = [@id, @image.object_id, @x, @y, @w, @h, @pos, @shape, @sensor]
@@ -134,6 +138,10 @@ class Reight::ChipList
134
138
  @id2chip[id]
135
139
  end
136
140
 
141
+ def inspect()
142
+ "#<#{self.class.name}:0x#{object_id}>"
143
+ end
144
+
137
145
  # @private
138
146
  def cmp__(o)
139
147
  a = [@image, @next_id, @id2chip, @frame2chip]
data/lib/reight/index.rb CHANGED
@@ -7,34 +7,48 @@ class Reight::Index
7
7
  include Reight::Hookable
8
8
  include Reight::HasHelp
9
9
 
10
- def initialize(index = 0, &changed)
10
+ def initialize(index = 0, min: 0, max: nil, &changed)
11
+ hook :changed
12
+
11
13
  super()
12
- @index = index
14
+ @min, @max = min, max
13
15
 
14
- hook :changed
15
16
  self.changed(&changed) if changed
17
+ self.index = index
16
18
  end
17
19
 
18
20
  attr_reader :index
19
21
 
20
- def draw()
21
- sp = sprite
22
- button_w, button_h = sp.h, sp.h
22
+ def index=(index)
23
+ index = index.clamp(@max ? (@min..@max) : (@min..))
24
+ return if index == @index
25
+ @index = index.to_i
26
+ changed! @index
27
+ end
23
28
 
29
+ def draw()
24
30
  no_stroke
25
31
 
26
- fill 230
27
- if pressing? && prev?
28
- rect 0, 0, sp.w / 2, button_h
29
- elsif pressing? && next?
30
- rect sp.w / 2, 0, sp.w / 2, button_h
31
- end
32
+ sp = sprite
33
+ w, h = sp.w, sp.h
34
+ dec = pressing? && prev?
35
+ inc = pressing? && next?
36
+ decy = dec ? 1 : 0
37
+ incy = inc ? 1 : 0
38
+
39
+ fill 220
40
+ rect 0, decy, h, h, 2 if dec
41
+ rect w - h, incy, h, h, 2 if inc
32
42
 
33
- fill 50
34
43
  text_align CENTER, CENTER
35
- text '<', 0, 0, button_w, button_h
36
- text '>', sp.w - button_w, 0, button_w, button_h
37
- text index, 0, 0, sp.w, sp.h
44
+ fill 220
45
+ text '<', 0, decy + 1, h, h
46
+ text '>', w - h, incy + 1, h, h
47
+ text index, 0, 1, w, h
48
+ fill 50
49
+ text '<', 0, decy, h, h
50
+ text '>', w - h, incy, h, h
51
+ text index, 0, 0, w, h
38
52
  end
39
53
 
40
54
  def prev? = sprite.mouse_x < sprite.w / 2
@@ -56,11 +70,8 @@ class Reight::Index
56
70
  end
57
71
 
58
72
  def clicked()
59
- old = @index
60
- @index += 1 if next?
61
- @index -= 1 if prev?
62
- @index = 0 if @index < 0
63
- changed! @index if @index != old
73
+ self.index += 1 if next?
74
+ self.index -= 1 if prev?
64
75
  end
65
76
 
66
77
  def sprite()
data/lib/reight/map.rb CHANGED
@@ -84,6 +84,10 @@ class Reight::Map
84
84
  chunk_at(x, y)&.[](x, y)
85
85
  end
86
86
 
87
+ def inspect()
88
+ "#<#{self.class.name}:0x#{object_id}>"
89
+ end
90
+
87
91
  # @private
88
92
  def cmp__(o)
89
93
  a = [@chip_size, @chunk_size, @chunks]
@@ -187,9 +191,7 @@ class Reight::Map::Chunk
187
191
  attr_reader :x, :y, :w, :h
188
192
 
189
193
  def sprites()
190
- @sprites ||= map {|chip|
191
- chip.to_sprite.tap {|sp| sp.map_chunk = self}
192
- }
194
+ @sprites ||= map(&:sprite).each {_1.map_chunk = self}
193
195
  end
194
196
 
195
197
  def clear_sprites()
@@ -266,6 +268,10 @@ class Reight::Map::Chunk
266
268
  @chips[index]
267
269
  end
268
270
 
271
+ def inspect()
272
+ "#<#{self.class.name}:0x#{object_id}>"
273
+ end
274
+
269
275
  # @private
270
276
  def cmp__(o)
271
277
  a = [@x, @y, @w, @h, @chip_size, @chips]
@@ -377,6 +383,10 @@ class Reight::Map::SpriteArray < Array
377
383
  super
378
384
  end
379
385
 
386
+ def inspect()
387
+ "#<#{self.class.name}:0x#{object_id}>"
388
+ end
389
+
380
390
  def drawSprite__(context)
381
391
  (@chunks&.each || each).each {_1.drawSprite__ context}
382
392
  end
@@ -51,6 +51,17 @@ class Reight::Project
51
51
  }.call
52
52
  end
53
53
 
54
+ def chips_page_width = settings[__method__] || 256
55
+
56
+ def chips_page_height = settings[__method__] || 256
57
+
58
+ def chips_npages()
59
+ w = chips_image_width / chips_page_width .to_f
60
+ h = chips_image_height / chips_page_height.to_f
61
+ raise unless w == w.to_i && h == h.to_i
62
+ (w * h).to_i
63
+ end
64
+
54
65
  def maps_json_name = settings[__method__] || 'maps.json'
55
66
 
56
67
  def maps_json_path = "#{project_dir}/#{maps_json_name}"
data/lib/reight/reight.rb CHANGED
@@ -3,31 +3,29 @@ using Reight
3
3
 
4
4
  class Reight::R8
5
5
 
6
- def initialize(path)
6
+ def initialize(path, edit: false)
7
7
  raise if $r8__
8
8
  $r8__ = self
9
9
 
10
- @path = path
10
+ @path, @edit = path, edit
11
11
  self.current = apps.first
12
12
  end
13
13
 
14
14
  attr_reader :current
15
15
 
16
- def version()
17
- '0.1'
18
- end
16
+ def edit? = @edit
19
17
 
20
18
  def project()
21
19
  @project ||= Reight::Project.new @path
22
20
  end
23
21
 
24
22
  def apps()
25
- @apps ||= [
26
- Reight::Runner.new(project),
27
- Reight::SpriteEditor.new(project),
28
- Reight::MapEditor.new(project),
29
- Reight::SoundEditor.new(project)
30
- ]
23
+ @apps ||= [].tap {|a|
24
+ a << Reight::Runner .new(project)
25
+ a << Reight::SpriteEditor.new(project) if edit?
26
+ a << Reight::MapEditor .new(project) if edit?
27
+ a << Reight::SoundEditor .new(project) if edit?
28
+ }
31
29
  end
32
30
 
33
31
  def flash(...) = current.flash(...)
@@ -48,9 +46,9 @@ class Reight::R8
48
46
 
49
47
  set_title [
50
48
  self.class.name.split('::').first,
51
- version,
49
+ Reight::Extension.version,
52
50
  '|',
53
- current.class.name.split('::').last
51
+ current.label
54
52
  ].join ' '
55
53
  end
56
54
 
data/lib/reight/text.rb CHANGED
@@ -7,30 +7,36 @@ class Reight::Text
7
7
  include Reight::Hookable
8
8
  include Reight::HasHelp
9
9
 
10
- def initialize(text = '', label: nil, regexp: nil, &changed)
10
+ def initialize(text = '', editable: false, align: LEFT, label: nil, regexp: nil, &changed)
11
11
  hook :changed
12
12
 
13
13
  super()
14
- @label, @regexp = label, regexp
15
- @shake = 0
14
+ @editable, @align, @label, @regexp = editable, align, label, regexp
15
+ @shake = 0
16
16
  self.changed(&changed) if changed
17
17
 
18
18
  self.value = text
19
19
  end
20
20
 
21
- attr_accessor :label
21
+ attr_accessor :editable, :align, :label
22
22
 
23
23
  attr_reader :value
24
24
 
25
+ alias editable? editable
26
+
25
27
  def revert()
26
28
  self.value = @old_value
27
29
  @shake = 6
28
30
  end
29
31
 
30
- def focus=(bool)
31
- sprite.capture = bool
32
- revert unless valid? value
33
- changed! value, self if value != @old_value
32
+ def focus=(focus)
33
+ return if focus && !editable?
34
+ return if focus == focus?
35
+ sprite.capture = focus
36
+ unless focus
37
+ revert unless valid? value
38
+ changed! value, self if value != @old_value
39
+ end
34
40
  end
35
41
 
36
42
  def focus?()
@@ -68,15 +74,17 @@ class Reight::Text
68
74
 
69
75
  show_old = value == ''
70
76
  text = show_old ? @old_value : value
71
- text = label + text unless focus?
77
+ text = label.to_s + text unless focus?
78
+ x = 2
72
79
  fill show_old ? 200 : 50
73
- text_align CENTER, CENTER
74
- text text, 0, 0, sp.w, sp.h
80
+ text_align @align, CENTER
81
+ text text, x, 0, sp.w - x * 2, sp.h
75
82
 
76
83
  if focus? && (frame_count % 60) < 30
77
84
  fill 100
78
85
  bounds = text_font.text_bounds value
79
- rect (sp.w + bounds.w) / 2 - 1, (sp.h - bounds.h) / 2, 2, bounds.h
86
+ xx = (@align == LEFT ? x + bounds.w : (sp.w + bounds.w) / 2) - 1
87
+ rect xx, (sp.h - bounds.h) / 2, 2, bounds.h
80
88
  end
81
89
  end
82
90
 
@@ -92,9 +100,9 @@ class Reight::Text
92
100
  def clicked(x, y)
93
101
  if focus?
94
102
  return if hit? x, y
95
- self.value = @old_value if !valid?(ignore_regexp: false)
103
+ self.value = @old_value if value == '' && !valid?(ignore_regexp: false)
96
104
  self.focus = false
97
- else
105
+ elsif editable?
98
106
  self.focus = true
99
107
  @old_value, @value = @value.dup, ''
100
108
  end
data/reight.gemspec CHANGED
@@ -25,13 +25,13 @@ Gem::Specification.new do |s|
25
25
  s.platform = Gem::Platform::RUBY
26
26
  s.required_ruby_version = '>= 3.0.0'
27
27
 
28
- s.add_dependency 'xot', '~> 0.3.4', '>= 0.3.4'
29
- s.add_dependency 'rucy', '~> 0.3.4', '>= 0.3.4'
30
- s.add_dependency 'beeps', '~> 0.3.4', '>= 0.3.4'
31
- s.add_dependency 'rays', '~> 0.3.4', '>= 0.3.4'
32
- s.add_dependency 'reflexion', '~> 0.3.4', '>= 0.3.4'
33
- s.add_dependency 'processing', '~> 1.1', '>= 1.1.6'
34
- s.add_dependency 'rubysketch', '~> 0.7.7', '>= 0.7.7'
28
+ s.add_dependency 'xot', '~> 0.3.5', '>= 0.3.5'
29
+ s.add_dependency 'rucy', '~> 0.3.5', '>= 0.3.5'
30
+ s.add_dependency 'beeps', '~> 0.3.5', '>= 0.3.5'
31
+ s.add_dependency 'rays', '~> 0.3.5', '>= 0.3.5'
32
+ s.add_dependency 'reflexion', '~> 0.3.5', '>= 0.3.5'
33
+ s.add_dependency 'processing', '~> 1.1', '>= 1.1.7'
34
+ s.add_dependency 'rubysketch', '~> 0.7.8', '>= 0.7.8'
35
35
 
36
36
  s.files = `git ls-files`.split $/
37
37
  s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}