reight 0.1.6 → 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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/PULL_REQUEST_TEMPLATE.md +12 -0
  3. data/CONTRIBUTING.md +7 -0
  4. data/ChangeLog.md +76 -0
  5. data/README.md +6 -5
  6. data/Rakefile +5 -2
  7. data/VERSION +1 -1
  8. data/bin/r8 +18 -8
  9. data/lib/reight/all.rb +7 -2
  10. data/lib/reight/app/chips.rb +124 -0
  11. data/lib/reight/app/map/brush.rb +1 -1
  12. data/lib/reight/app/map/brush_base.rb +3 -3
  13. data/lib/reight/app/map/canvas.rb +10 -15
  14. data/lib/reight/app/map/editor.rb +44 -17
  15. data/lib/reight/app/map/line.rb +5 -5
  16. data/lib/reight/app/map/rect.rb +2 -2
  17. data/lib/reight/app/map.rb +0 -1
  18. data/lib/reight/app/navigator.rb +33 -47
  19. data/lib/reight/app/runner.rb +123 -86
  20. data/lib/reight/app/sound/brush.rb +32 -0
  21. data/lib/reight/app/sound/canvas.rb +190 -0
  22. data/lib/reight/app/sound/editor.rb +170 -10
  23. data/lib/reight/app/sound/eraser.rb +28 -0
  24. data/lib/reight/app/sound/tool.rb +29 -0
  25. data/lib/reight/app/sound.rb +4 -0
  26. data/lib/reight/app/sprite/canvas.rb +23 -18
  27. data/lib/reight/app/sprite/color.rb +3 -1
  28. data/lib/reight/app/sprite/editor.rb +58 -47
  29. data/lib/reight/app/sprite/line.rb +1 -1
  30. data/lib/reight/app/sprite/shape.rb +1 -1
  31. data/lib/reight/app/sprite.rb +0 -1
  32. data/lib/reight/app.rb +24 -5
  33. data/lib/reight/button.rb +10 -7
  34. data/lib/reight/chip.rb +32 -6
  35. data/lib/reight/context.rb +168 -0
  36. data/lib/reight/helpers.rb +2 -2
  37. data/lib/reight/index.rb +87 -0
  38. data/lib/reight/map.rb +141 -11
  39. data/lib/reight/project.rb +45 -6
  40. data/lib/reight/reight.rb +11 -15
  41. data/lib/reight/sound.rb +238 -0
  42. data/lib/reight/sprite.rb +42 -0
  43. data/lib/reight/text.rb +124 -0
  44. data/lib/reight.rb +7 -3
  45. data/reight.gemspec +7 -7
  46. data/res/icons.png +0 -0
  47. data/test/helper.rb +16 -0
  48. data/test/test_map.rb +7 -7
  49. data/test/test_map_chunk.rb +6 -6
  50. data/test/test_sprite.rb +28 -0
  51. metadata +42 -32
  52. data/lib/reight/app/map/chips.rb +0 -84
  53. data/lib/reight/app/music/editor.rb +0 -25
  54. data/lib/reight/app/music.rb +0 -1
  55. data/lib/reight/app/sprite/chips.rb +0 -92
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 443639fd56ce2df76ee0d57d6bc4c61c0a121e2615a0511068a9b37cc41fd4d1
4
- data.tar.gz: afcf2bf4c67f3e1712a375d654ed5583af9c3473659fedb1d1129511d2d9747b
3
+ metadata.gz: f33c4762be06696447cc2975a6363c5865325115c438d6d2ba62bae45f0c1362
4
+ data.tar.gz: 785b2dc2beb430356875301d0ca8a4423bcea7327789055878e76ea5f0a13c33
5
5
  SHA512:
6
- metadata.gz: c293eb4bc9281f295f5adc22007fe1e5139b9fd1c26aeb6e19374769c6476e69c0417d7d897ef94f78ee40b893c9fbcb57ddc9776881b565ef6556ee42863cc0
7
- data.tar.gz: d5dab9d239a2c161cf032fff213c894eafc7bc38410ecd5883207dee2f78d1502247dd7072649d9f6dd2f779afacac15f3a42da243a8c0a1fabddccfc2902116
6
+ metadata.gz: 825762a3025e5270621ad31e0f85994509adc2c9e504e4ff820bcb22bf453b263813ebc8c0a29574489943ace7e30c8d1384e7d2b1ac33ed7a3fa3cae2e6b4ca
7
+ data.tar.gz: 12bb191d3da0b11a72692157fd9d68c4598042ddb0ea8c5d36261d2fd8195765719a5fc4f4423996f8e16dd4bc923b213954e7bf839b9d7e23a643d96659f0d6
@@ -0,0 +1,12 @@
1
+ ## Pull Requests Not Accepted 🚫
2
+
3
+ Thank you for your interest in contributing!
4
+ However, this repository does not accept pull requests directly.
5
+
6
+ ### Where to Contribute?
7
+
8
+ Please submit your changes to the [xord/all](https://github.com/xord/all) monorepo, which serves as the primary repository for all our main libraries.
9
+
10
+ For more details, please refer to our [contribution guidelines](../CONTRIBUTING.md).
11
+
12
+ Thanks for your understanding! 🙌
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,7 @@
1
+ # Contribution Guide
2
+
3
+ Thank you for your interest in contributing!
4
+ However, this repository does not accept pull requests.
5
+ Instead, please submit your changes to the [xord/all](https://github.com/xord/all) monorepo, which serves as the primary repository for all our main libraries.
6
+
7
+ For any questions, feel free to open an issue.
data/ChangeLog.md CHANGED
@@ -1,6 +1,82 @@
1
1
  # reight ChangeLog
2
2
 
3
3
 
4
+ ## [v0.1.8] - 2025-03-24
5
+
6
+ - Add '--edit' command-line option to enable edit mode
7
+ - Add Text#editable?
8
+ - Add SpriteEditor::chips_index
9
+ - Add frame_changed and selection_changed to Sprite::Canvas
10
+ - Add Index control for maps
11
+ - Add PULL_REQUEST_TEMPLATE.md
12
+ - Add CONTRIBUTING.md
13
+ - Update layout
14
+ - Share the chips.rb
15
+ - Move chip_sizes above chips
16
+ - Refine visuals of button and index
17
+ - Index has min and max
18
+ - Text::initialize can take 'align:' keyword parameter
19
+ - The text input area will not be shaked if the value determined by the click is empty
20
+ - Fix the text value if not reverted on exiting edit mode with invalid value
21
+ - Delete App#name
22
+ - Simplify inspect() text
23
+ - Update readme: Add link to examples (by @kaibadash)
24
+
25
+ - Fix some crashes
26
+
27
+
28
+ ## [v0.1.7] - 2025-03-07
29
+
30
+ - Add Reight::Context
31
+ - Add docs for Reight::Context
32
+ - Add Reight::Sprite class
33
+ - Add sound editor
34
+ - Add size() and createCanvas()
35
+ - Add App#active?
36
+ - Project: Add clear_all_sprites()
37
+ - Map: Add to_sprites(), sprites(), sprites_at(), clear_sprites()
38
+ - Map::Chunk: Add sprites(), clear_sprites(), and each()
39
+ - Chip: Add sprite(), clear_sprites(), and each()
40
+ - Add Map::SpriteArray class
41
+ - Add SpriteWorld#offset and SpriteWorld#zoom
42
+
43
+ - Define Sprite and Sound classes in the main context
44
+ - Change pixelsPerMeter from 100 to 8
45
+ - createSprite() creates a new Reight::Sprite instance
46
+ - Map: delete/delete_chip -> Map#remove/remove_chip
47
+ - Map::Chunk: Caches drawing contents
48
+ - Disable the '<=>' operators for Map, Map::Chunk, Chip, ChipList
49
+ - Sound: play() accepts a block parameter that is called when playback ends
50
+ - Sound: play() can take gain parameter
51
+ - Sound: Default gain: 0.1 -> 0.2
52
+ - Sound: apply envelope and gain
53
+ - Offset the button text while it is pressed
54
+
55
+ - Runner: During game execution, the Run button re-runs the game
56
+ - Runner: Delete F10 to restart
57
+ - Runner: Delete restart button
58
+ - Runner: Rescue exceptions raised by user script
59
+ - Runner: Stop all timers on stop running user script
60
+ - Runner: runner.rb does not use 'using Reight', so define funcs in runner context
61
+ - Runner: User script paths are relative to project directory
62
+
63
+ - SpriteEditor: Black is treated as a transparent color
64
+ - SpriteEditor: Update color palette to 32 colors
65
+ - SpriteEditor: Show color code
66
+
67
+ - SoundEditor: Cancel attack and release on successive notes to avoid click noise
68
+ - SoundEditor: Display tone colors on each tone button
69
+ - SoundEditor: Canvas is scrollable
70
+
71
+ - Fix pick_color fails to get pixel color
72
+ - Fix crash on moving window
73
+ - Fix crash on switching from editer to another editor
74
+ - Fix yard crash caused by pattern matching rightward assginment
75
+ - Fix misaligned mouse position on sound editor canvas
76
+ - Fix error on drawing line tool at map editor
77
+ - Fix the angle mode of Reight::Context does not sync with root context
78
+
79
+
4
80
  ## [v0.1.6] - 2025-01-30
5
81
 
6
82
  - Update dependencies: processing, rubysketch
data/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # Reight - A Retro Game Engine for Ruby
3
2
 
4
3
  Reight is an open-source Ruby library inspired by the powerful [Processing](https://processing.org/) API, designed to make creative coding accessible and enjoyable for everyone. With support for both Mac and Windows, this library brings the joy of visual programming to Ruby developers.
@@ -38,20 +37,22 @@ Here’s a simple example to get you started:
38
37
  # Create a window and draw something
39
38
  draw do
40
39
  background 0
41
- $sprites ||= project.maps.first.map(&:to_sprite)
42
- sprite $sprites
40
+ $sprites ||= project.maps.first.map(&:to_sprite)
41
+ sprite $sprites
43
42
  end
44
43
  ```
45
44
 
46
45
  Run the script and watch your window come to life!
47
46
 
48
- ```
47
+ ```bash
49
48
  $ bundle exec r8 .
50
49
  ```
51
50
 
51
+ You can find example projects in [xord/reight-examples](https://github.com/xord/reight-examples).
52
+
52
53
  ## Documentation
53
54
 
54
- Comprehensive documentation and guides can be found [here](https://www.rubydoc.info/gems/reight/0.1/index).
55
+ Comprehensive documentation and guides can be found [here](https://www.rubydoc.info/gems/reight/).
55
56
 
56
57
  ## License
57
58
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@
4
4
  .map {|s| File.expand_path "#{s}/lib", __dir__}
5
5
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
6
6
 
7
- require 'xot/rake'
7
+ require 'rucy/rake'
8
8
 
9
9
  require 'xot/extension'
10
10
  require 'rucy/extension'
@@ -18,13 +18,16 @@ require 'reight/extension'
18
18
 
19
19
  EXTENSIONS = [Xot, Rucy, Beeps, Rays, Reflex, Processing, RubySketch, Reight]
20
20
 
21
+ ENV['RDOC'] = 'yardoc --no-private'
22
+
21
23
  default_tasks
22
24
  test_ruby_extension
25
+ generate_documents
23
26
  build_ruby_gem
24
27
 
25
28
 
26
29
  task :run do
27
30
  libs = %w[xot rucy beeps rays reflex processing rubysketch]
28
31
  .map {|lib| "-I#{ENV['ALL']}/#{lib}/lib"}
29
- sh %( ruby #{libs.join ' '} -Ilib bin/r8 '#{ENV["dir"] || "."}' )
32
+ sh %( ruby #{libs.join ' '} -Ilib bin/r8 --edit '#{ENV["dir"] || "demo/hello"}' )
30
33
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.8
data/bin/r8 CHANGED
@@ -1,21 +1,31 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
3
4
  require 'reight'
4
- using Reight
5
5
 
6
6
 
7
- def r8 = $r8__
7
+ opt = OptionParser.new
8
+ opt.banner = "Usage: r8 [options] [DIR]"
9
+ opt.version = Reight::Extension.version
10
+
11
+ opt.on '-e', '--edit', "edit mode"
12
+ opt.on_tail '-h', '--help'
13
+
14
+ params = {}
15
+ argv = opt.parse! ARGV, into: params
8
16
 
9
- def usage()
10
- <<~END
11
- USAGE: r8 [path]
12
- END
17
+ if params.key? :help
18
+ puts opt.help
19
+ exit
13
20
  end
14
21
 
22
+
23
+ def r8 = $r8__
24
+
15
25
  Reight::CONTEXT__.tap do |c|
16
- path = ARGV.shift or return puts usage
26
+ path = argv.shift || '.'
17
27
  path = File.expand_path path, Dir.pwd unless path.start_with?('/')
18
- c.setup {Reight::R8.new(path).setup}
28
+ c.setup {Reight::R8.new(path, edit: params[:edit]).setup}
19
29
  c.draw {r8.draw}
20
30
  c.key_pressed {r8.key_pressed}
21
31
  c.key_released {r8.key_released}
data/lib/reight/all.rb CHANGED
@@ -21,17 +21,22 @@ end# Reight
21
21
 
22
22
  require 'reight/extension'
23
23
  require 'reight/helpers'
24
- require 'reight/project'
25
24
  require 'reight/history'
26
25
  require 'reight/button'
26
+ require 'reight/text'
27
+ require 'reight/index'
27
28
 
28
29
  require 'reight/reight'
30
+ require 'reight/context'
31
+ require 'reight/project'
32
+ require 'reight/sprite'
29
33
  require 'reight/chip'
30
34
  require 'reight/map'
35
+ require 'reight/sound'
31
36
  require 'reight/app'
32
37
  require 'reight/app/navigator'
33
38
  require 'reight/app/runner'
39
+ require 'reight/app/chips'
34
40
  require 'reight/app/sprite'
35
41
  require 'reight/app/map'
36
42
  require 'reight/app/sound'
37
- require 'reight/app/music'
@@ -0,0 +1,124 @@
1
+ using Reight
2
+
3
+
4
+ class Reight::App::Chips
5
+
6
+ include Reight::Hookable
7
+
8
+ def initialize(
9
+ app, chips, size = 8,
10
+ page_width = app.project.chips_page_width,
11
+ page_height = app.project.chips_page_height)
12
+
13
+ hook :frame_changed
14
+ hook :offset_changed
15
+
16
+ @app, @chips = app, chips
17
+ @page_size = create_vector page_width, page_height
18
+ @offset = create_vector 0, 0
19
+
20
+ set_frame 0, 0, size, size
21
+ end
22
+
23
+ attr_reader :x, :y, :size, :offset
24
+
25
+ def chip = @chips.at x, y, size, size
26
+
27
+ def set_frame(x, y, w = size, h = size)
28
+ raise 'Chips: width != height' if w != h
29
+ @x = align_to_grid(x).clamp(0..@chips.image.width)
30
+ @y = align_to_grid(y).clamp(0..@chips.image.height)
31
+ @size = w
32
+ frame_changed! @x, @y, @size, @size
33
+ end
34
+
35
+ def offset=(pos)
36
+ sp = sprite
37
+ x = pos.x.clamp([-(@chips.image.width - sp.w), 0].min..0)
38
+ y = pos.y.clamp([-(@chips.image.height - sp.h), 0].min..0)
39
+ offset = create_vector x, y
40
+ return if offset == @offset
41
+ @offset = offset
42
+ offset_changed! @offset
43
+ end
44
+
45
+ def index2offset(index)
46
+ pw, ph = @page_size.x.to_i, @page_size.y.to_i
47
+ size = @chips.image.width / pw
48
+ create_vector -(index % size).to_i * pw, -(index / size).to_i * ph
49
+ end
50
+
51
+ def offset2index(offset = self.offset)
52
+ iw = @chips.image.width
53
+ pw, ph = @page_size.x.to_i, @page_size.y.to_i
54
+ x, y = (-offset.x / ph).to_i, (-offset.y / pw).to_i
55
+ w = (iw / pw).to_i
56
+ y * w + x
57
+ end
58
+
59
+ def draw()
60
+ sp = sprite
61
+ clip sp.x, sp.y, sp.w, sp.h
62
+
63
+ fill 0
64
+ no_stroke
65
+ rect 0, 0, sp.w, sp.h
66
+
67
+ translate offset.x, offset.y
68
+ draw_offset_grids
69
+ image @chips.image, 0, 0
70
+ draw_frame
71
+ end
72
+
73
+ def draw_offset_grids()
74
+ no_fill
75
+ stroke 50
76
+ iw, ih = @chips.image.width, @chips.image.height
77
+ cw, ch = @page_size.x, @page_size.y
78
+ (cw...iw).step(cw) {|x| line x, 0, x, ih}
79
+ (ch...ih).step(ch) {|y| line 0, y, iw, y}
80
+ end
81
+
82
+ def draw_frame()
83
+ no_fill
84
+ stroke 255
85
+ stroke_weight 1
86
+ rect @x, @y, @size, @size
87
+ end
88
+
89
+ def mouse_pressed(x, y)
90
+ @prev_pos = create_vector x, y
91
+ end
92
+
93
+ def mouse_released(x, y)
94
+ end
95
+
96
+ def mouse_dragged(x, y)
97
+ pos = create_vector x, y
98
+ self.offset += pos - @prev_pos if @prev_pos
99
+ @prev_pos = pos
100
+ end
101
+
102
+ def mouse_clicked(x, y)
103
+ set_frame(
104
+ -offset.x + align_to_grid(x),
105
+ -offset.y + align_to_grid(y))
106
+ end
107
+
108
+ def sprite()
109
+ @sprite ||= RubySketch::Sprite.new.tap do |sp|
110
+ sp.draw {draw}
111
+ sp.mouse_pressed {mouse_pressed sp.mouse_x, sp.mouse_y}
112
+ sp.mouse_released {mouse_released sp.mouse_x, sp.mouse_y}
113
+ sp.mouse_dragged {mouse_dragged sp.mouse_x, sp.mouse_y}
114
+ sp.mouse_clicked {mouse_clicked sp.mouse_x, sp.mouse_y}
115
+ end
116
+ end
117
+
118
+ private
119
+
120
+ def align_to_grid(n)
121
+ n.to_i / 8 * 8
122
+ end
123
+
124
+ end# Chips
@@ -10,7 +10,7 @@ class Reight::MapEditor::Brush < Reight::MapEditor::BrushBase
10
10
 
11
11
  def brush(cursor_from, cursor_to, chip)
12
12
  x, y, = cursor_to
13
- put_or_delete_chip x, y, chip
13
+ put_or_remove_chip x, y, chip
14
14
  false
15
15
  end
16
16
 
@@ -5,15 +5,15 @@ class Reight::MapEditor::BrushBase < Reight::MapEditor::Tool
5
5
 
6
6
  def brush(cursor_from, cursor_to, chip) = nil
7
7
 
8
- def put_or_delete_chip(x, y, chip)
8
+ def put_or_remove_chip(x, y, chip)
9
9
  return false unless x && y && chip
10
10
  m = canvas.map
11
11
  return false if !@deleting && m[x, y]&.id == chip.id
12
12
 
13
13
  result = false
14
14
  m.each_chip x, y, chip.w, chip.h do |ch|
15
- m.delete_chip ch
16
- result |= history.append [:delete_chip, ch.pos.x, ch.pos.y, ch.id]
15
+ m.remove_chip ch
16
+ result |= history.append [:remove_chip, ch.pos.x, ch.pos.y, ch.id]
17
17
  end
18
18
  unless @deleting
19
19
  m.put x, y, chip
@@ -3,26 +3,21 @@ using Reight
3
3
 
4
4
  class Reight::MapEditor::Canvas
5
5
 
6
- include Reight::Hookable
7
-
8
- def initialize(app, map, path)
9
- hook :tool_changed
10
-
11
- @app, @map, @path = app, map, path
6
+ def initialize(app, map)
7
+ @app, @map = app, map
12
8
  @x, @y, @tool, @cursor = 0, 0, nil, nil, nil
13
9
  end
14
10
 
15
- attr_accessor :x, :y
11
+ attr_accessor :x, :y, :tool
16
12
 
17
- attr_reader :map, :tool, :cursor
13
+ attr_reader :map, :cursor
18
14
 
19
- def save()
20
- @app.project.save
15
+ def map=(map)
16
+ @map = map
21
17
  end
22
18
 
23
- def tool=(tool)
24
- @tool = tool
25
- tool_changed! tool
19
+ def save()
20
+ @app.project.save
26
21
  end
27
22
 
28
23
  def set_cursor(x, y, w, h)
@@ -47,7 +42,7 @@ class Reight::MapEditor::Canvas
47
42
  end
48
43
 
49
44
  def sprite()
50
- @sprite ||= Sprite.new.tap do |sp|
45
+ @sprite ||= RubySketch::Sprite.new.tap do |sp|
51
46
  pos = -> {to_image sp.mouse_x, sp.mouse_y}
52
47
  sp.draw {draw}
53
48
  sp.mouse_pressed {mouse_pressed( *pos.call, sp.mouse_button)}
@@ -76,7 +71,7 @@ class Reight::MapEditor::Canvas
76
71
  clip sp.x, sp.y, sp.w, sp.h
77
72
  translate @x, @y
78
73
 
79
- fill 0, 0, 0
74
+ fill 0
80
75
  no_stroke
81
76
  rect(-@x, -@y, sp.w, sp.h)
82
77
 
@@ -4,14 +4,18 @@ using Reight
4
4
  class Reight::MapEditor < Reight::App
5
5
 
6
6
  def canvas()
7
- @canvas ||= Canvas.new self, project.maps.first, project.maps_json_path
7
+ @canvas ||= Canvas.new self, project.maps.first
8
8
  end
9
9
 
10
10
  def chips()
11
- @chips ||= Chips.new self, project.chips
11
+ @chips ||= Chips.new(self, project.chips).tap do |chips|
12
+ chips.offset_changed do |offset|
13
+ chips_index.index = chips.offset2index offset
14
+ end
15
+ end
12
16
  end
13
17
 
14
- def activated()
18
+ def setup()
15
19
  super
16
20
  history.disable do
17
21
  tools[0].click
@@ -42,25 +46,36 @@ class Reight::MapEditor < Reight::App
42
46
 
43
47
  def window_resized()
44
48
  super
49
+ [chip_sizes, tools].flatten.map(&:sprite)
50
+ .each {|sp| sp.w = sp.h = BUTTON_SIZE}
51
+
52
+ chips_index.sprite.tap do |sp|
53
+ sp.w, sp.h = INDEX_SIZE, BUTTON_SIZE
54
+ sp.x = SPACE
55
+ sp.y = NAVIGATOR_HEIGHT + SPACE
56
+ end
57
+ chip_sizes.reverse.map {_1.sprite}.each.with_index do |sp, index|
58
+ sp.x = SPACE + CHIPS_WIDTH - (sp.w + (sp.w + 1) * index)
59
+ sp.y = chips_index.sprite.y
60
+ end
45
61
  chips.sprite.tap do |sp|
46
62
  sp.x = SPACE
47
- sp.y = NAVIGATOR_HEIGHT + SPACE
48
- sp.w = CHIPS_WIDTH
63
+ sp.y = chip_sizes.last.sprite.bottom + SPACE
64
+ sp.right = chip_sizes.last.sprite.right
49
65
  sp.bottom = height - SPACE
50
66
  end
67
+ map_index.sprite.tap do |sp|
68
+ sp.w, sp.h = INDEX_SIZE, BUTTON_SIZE
69
+ sp.x = chip_sizes.last.sprite.right + SPACE
70
+ sp.y = chip_sizes.last.sprite.y
71
+ end
51
72
  tools.map {_1.sprite}.each.with_index do |sp, index|
52
- sp.w = sp.h = BUTTON_SIZE
53
73
  sp.x = chips.sprite.right + SPACE + (sp.w + 1) * index
54
74
  sp.y = height - (SPACE + sp.h)
55
75
  end
56
- chip_sizes.reverse.map {_1.sprite}.each.with_index do |sp, index|
57
- sp.w = sp.h = BUTTON_SIZE
58
- sp.x = width - (SPACE + sp.w * (index + 1) + index)
59
- sp.y = height - (SPACE + sp.h)
60
- end
61
76
  canvas.sprite.tap do |sp|
62
- sp.x = chips.sprite.right + SPACE
63
- sp.y = chips.sprite.y
77
+ sp.x = map_index.sprite.x
78
+ sp.y = map_index.sprite.bottom + SPACE
64
79
  sp.right = width - SPACE
65
80
  sp.bottom = tools.first.sprite.top - SPACE
66
81
  end
@@ -69,8 +84,8 @@ class Reight::MapEditor < Reight::App
69
84
  def undo(flash: true)
70
85
  history.undo do |action|
71
86
  case action
72
- in [:put_chip, x, y, id] then canvas.map.delete x, y
73
- in [:delete_chip, x, y, id] then canvas.map.put x, y, project.chips[id]
87
+ in [:put_chip, x, y, id] then canvas.map.remove x, y
88
+ in [:remove_chip, x, y, id] then canvas.map.put x, y, project.chips[id]
74
89
  in [ :select, sel, _] then sel ? canvas.select(*sel) : canvas.deselect
75
90
  in [:deselect, sel] then canvas.select(*sel)
76
91
  end
@@ -82,7 +97,7 @@ class Reight::MapEditor < Reight::App
82
97
  history.redo do |action|
83
98
  case action
84
99
  in [:put_chip, x, y, id] then canvas.map.put x, y, project.chips[id]
85
- in [:delete_chip, x, y, id] then canvas.map.delete x, y
100
+ in [:remove_chip, x, y, id] then canvas.map.remove x, y
86
101
  in [ :select, _, sel] then canvas.select(*sel)
87
102
  in [:deselect, _] then canvas.deselect
88
103
  end
@@ -93,10 +108,16 @@ class Reight::MapEditor < Reight::App
93
108
  private
94
109
 
95
110
  def sprites()
96
- [canvas, chips, *chip_sizes, *tools]
111
+ [chips_index, *chip_sizes, chips, map_index, *tools, canvas]
97
112
  .map(&:sprite) + super
98
113
  end
99
114
 
115
+ def chips_index()
116
+ @chips_index ||= Reight::Index.new max: project.chips_npages - 1 do |index|
117
+ chips.offset = chips.index2offset index if index != chips.offset2index
118
+ end
119
+ end
120
+
100
121
  def chip_sizes()
101
122
  @chip_sizes ||= group(*[8, 16, 32].map {|size|
102
123
  Reight::Button.new name: "#{size}x#{size}", label: size do
@@ -105,6 +126,12 @@ class Reight::MapEditor < Reight::App
105
126
  })
106
127
  end
107
128
 
129
+ def map_index()
130
+ @map_index ||= Reight::Index.new do |index|
131
+ canvas.map = project.maps[index] ||= Reight::Map.new
132
+ end
133
+ end
134
+
108
135
  def tools()
109
136
  @tools ||= group brush, line, stroke_rect, fill_rect
110
137
  end
@@ -4,7 +4,7 @@ using Reight
4
4
  class Reight::MapEditor::Line < Reight::MapEditor::BrushBase
5
5
 
6
6
  def initialize(app, &block)
7
- super app, icon: app.icon(3, 2, 8), &block
7
+ super app, icon: app.icon(4, 2, 8), &block
8
8
  set_help left: name, right: 'Pick Chip'
9
9
  end
10
10
 
@@ -17,15 +17,15 @@ class Reight::MapEditor::Line < Reight::MapEditor::BrushBase
17
17
  dy = fromy < toy ? chip.h : -chip.h
18
18
  if (tox - fromx).abs > (toy - fromy).abs
19
19
  (fromx..tox).step(dx).each do |x|
20
- y = map x, fromx, tox, fromy, toy
20
+ y = fromy == toy ? toy : map(x, fromx, tox, fromy, toy)
21
21
  y = y / chip.h * chip.h
22
- result |= put_or_delete_chip x, y, chip
22
+ result |= put_or_remove_chip x, y, chip
23
23
  end
24
24
  else
25
25
  (fromy..toy).step(dy).each do |y|
26
- x = map y, fromy, toy, fromx, tox
26
+ x = fromx == tox ? tox : map(y, fromy, toy, fromx, tox)
27
27
  x = x / chip.w * chip.w
28
- result |= put_or_delete_chip x, y, chip
28
+ result |= put_or_remove_chip x, y, chip
29
29
  end
30
30
  end
31
31
  end
@@ -5,7 +5,7 @@ class Reight::MapEditor::Rect < Reight::MapEditor::BrushBase
5
5
 
6
6
  def initialize(app, fill:, &block)
7
7
  @fill = fill
8
- super app, icon: app.icon(fill ? 5 : 4, 2, 8), &block
8
+ super app, icon: app.icon(fill ? 6 : 5, 2, 8), &block
9
9
  set_help left: "#{fill ? 'Fill' : 'Stroke'} #{name}", right: 'Pick Chip'
10
10
  end
11
11
 
@@ -19,7 +19,7 @@ class Reight::MapEditor::Rect < Reight::MapEditor::BrushBase
19
19
  (fromy..toy).step(chip.h).each do |y|
20
20
  (fromx..tox).step(chip.w).each do |x|
21
21
  next if !@fill && fromx < x && x < tox && fromy < y && y < toy
22
- result |= put_or_delete_chip x, y, chip
22
+ result |= put_or_remove_chip x, y, chip
23
23
  end
24
24
  end
25
25
  end
@@ -1,6 +1,5 @@
1
1
  require 'reight/app/map/editor'
2
2
  require 'reight/app/map/canvas'
3
- require 'reight/app/map/chips'
4
3
  require 'reight/app/map/tool'
5
4
  require 'reight/app/map/brush_base'
6
5
  require 'reight/app/map/brush'