reight 0.1.2

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 (58) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/release-gem.yml +62 -0
  3. data/.github/workflows/tag.yml +35 -0
  4. data/.github/workflows/test.yml +37 -0
  5. data/.github/workflows/utils.rb +56 -0
  6. data/.gitignore +1 -0
  7. data/ChangeLog.md +23 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE +21 -0
  10. data/README.md +62 -0
  11. data/Rakefile +30 -0
  12. data/VERSION +1 -0
  13. data/bin/r8 +35 -0
  14. data/lib/reight/all.rb +59 -0
  15. data/lib/reight/app/map/brush.rb +27 -0
  16. data/lib/reight/app/map/brush_base.rb +54 -0
  17. data/lib/reight/app/map/canvas.rb +150 -0
  18. data/lib/reight/app/map/chips.rb +84 -0
  19. data/lib/reight/app/map/editor.rb +117 -0
  20. data/lib/reight/app/map/line.rb +35 -0
  21. data/lib/reight/app/map/rect.rb +29 -0
  22. data/lib/reight/app/map/tool.rb +32 -0
  23. data/lib/reight/app/map.rb +8 -0
  24. data/lib/reight/app/music/editor.rb +25 -0
  25. data/lib/reight/app/music.rb +1 -0
  26. data/lib/reight/app/navigator.rb +172 -0
  27. data/lib/reight/app/runner.rb +275 -0
  28. data/lib/reight/app/sound/editor.rb +25 -0
  29. data/lib/reight/app/sound.rb +1 -0
  30. data/lib/reight/app/sprite/brush.rb +43 -0
  31. data/lib/reight/app/sprite/canvas.rb +254 -0
  32. data/lib/reight/app/sprite/chips.rb +92 -0
  33. data/lib/reight/app/sprite/color.rb +30 -0
  34. data/lib/reight/app/sprite/editor.rb +272 -0
  35. data/lib/reight/app/sprite/fill.rb +45 -0
  36. data/lib/reight/app/sprite/line.rb +37 -0
  37. data/lib/reight/app/sprite/select.rb +58 -0
  38. data/lib/reight/app/sprite/shape.rb +43 -0
  39. data/lib/reight/app/sprite/tool.rb +27 -0
  40. data/lib/reight/app/sprite.rb +10 -0
  41. data/lib/reight/app.rb +123 -0
  42. data/lib/reight/button.rb +93 -0
  43. data/lib/reight/chip.rb +150 -0
  44. data/lib/reight/extension.rb +24 -0
  45. data/lib/reight/helpers.rb +69 -0
  46. data/lib/reight/history.rb +135 -0
  47. data/lib/reight/map.rb +264 -0
  48. data/lib/reight/project.rb +115 -0
  49. data/lib/reight/reight.rb +83 -0
  50. data/lib/reight.rb +18 -0
  51. data/reight.gemspec +40 -0
  52. data/res/icons.png +0 -0
  53. data/test/helper.rb +15 -0
  54. data/test/test_chip.rb +108 -0
  55. data/test/test_chip_list.rb +68 -0
  56. data/test/test_map.rb +232 -0
  57. data/test/test_map_chunk.rb +226 -0
  58. metadata +244 -0
@@ -0,0 +1,226 @@
1
+ require_relative 'helper'
2
+ using Reight
3
+
4
+
5
+ class TestMapChunk < Test::Unit::TestCase
6
+
7
+ def chunk(...) = R8::Map::Chunk.new(...)
8
+
9
+ def chip(x, y, w, h, id: 1, image: self.image, pos: nil) =
10
+ R8::Chip.new id, image, x, y, w, h, pos: pos
11
+
12
+ def image(w = 100, h = 100) = create_image w, h
13
+
14
+ def vec(...) = create_vector(...)
15
+
16
+ def test_initialize()
17
+ assert_equal [1, 3, 4, 6], chunk(1, 3, 4, 6, chip_size: 2).frame
18
+ assert_equal [1, 3, 4, 6], chunk(1.1, 3, 4, 6, chip_size: 2).frame
19
+ assert_equal [1, 3, 4, 6], chunk(1, 3.3, 4, 6, chip_size: 2).frame
20
+
21
+ assert_raise(ArgumentError) {chunk 1, 3, 4, 6, chip_size: 2.2}
22
+ assert_raise(ArgumentError) {chunk 1, 3, 4.4, 6, chip_size: 2}
23
+ assert_raise(ArgumentError) {chunk 1, 3, 4, 6.6, chip_size: 2}
24
+ end
25
+
26
+ def test_put()
27
+ img = image
28
+ new_chip = -> id, size, pos: nil {
29
+ chip 0, 0, size, size, id: id, image: img, pos: pos
30
+ }
31
+
32
+ chunk(10, 20, 30, 40, chip_size: 10).tap do |c|
33
+ assert_nil c[20, 30]
34
+ assert_equal 0, count_all_chips(c)
35
+ end
36
+
37
+ chunk(10, 20, 30, 40, chip_size: 10).tap do |c|
38
+ c.put 20, 30, new_chip[1, 10]
39
+ assert_equal new_chip[1, 10, pos: vec(20, 30)], c[20, 30]
40
+ assert_equal 1, count_all_chips(c)
41
+ end
42
+
43
+ chunk(10, 20, 30, 40, chip_size: 10).tap do |c|
44
+ c.put 25, 35, new_chip[2, 10]
45
+ assert_equal new_chip[2, 10, pos: vec(20, 30)], c[25, 35]
46
+ assert_equal new_chip[2, 10, pos: vec(20, 30)], c[20, 30]
47
+ assert_equal 1, count_all_chips(c)
48
+ end
49
+
50
+ chunk(10, 20, 30, 40, chip_size: 10).tap do |c|
51
+ c.put 20.2, 30.3, new_chip[3, 10]
52
+ assert_equal new_chip[3, 10, pos: vec(20, 30)], c[20.2, 30.3]
53
+ assert_equal new_chip[3, 10, pos: vec(20, 30)], c[20, 30]
54
+ assert_equal 1, count_all_chips(c)
55
+ end
56
+
57
+ chunk(10, 20, 30, 40, chip_size: 10).tap do |c|
58
+ c.put 25, 35, new_chip[4, 20]
59
+ assert_equal new_chip[4, 20, pos: vec(20, 30)], c[25, 35]
60
+ assert_equal new_chip[4, 20, pos: vec(20, 30)], c[20, 30]
61
+ assert_equal new_chip[4, 20, pos: vec(20, 30)], c[35, 35]
62
+ assert_equal new_chip[4, 20, pos: vec(20, 30)], c[30, 30]
63
+ assert_equal new_chip[4, 20, pos: vec(20, 30)], c[35, 45]
64
+ assert_equal new_chip[4, 20, pos: vec(20, 30)], c[30, 40]
65
+ assert_equal new_chip[4, 20, pos: vec(20, 30)], c[25, 45]
66
+ assert_equal new_chip[4, 20, pos: vec(20, 30)], c[20, 40]
67
+ assert_equal 4, count_all_chips(c)
68
+
69
+ assert_equal c[20, 30].object_id, c[30, 30].object_id
70
+ assert_equal c[20, 30].object_id, c[30, 40].object_id
71
+ assert_equal c[20, 30].object_id, c[20, 40].object_id
72
+ end
73
+
74
+ chunk(10, 20, 30, 40, chip_size: 10).tap do |c|
75
+ assert_nothing_raised {c.put 20, 30, chip(0, 0, 10, 10)}
76
+ assert_raise {c.put 20, 30, chip(0, 0, 10, 10)}
77
+ end
78
+ end
79
+
80
+ def test_delete()
81
+ [
82
+ [0, 0], [20, 30], [90, 90]
83
+ ].each do |xx, yy|
84
+ chunk(10, 20, 30, 40, chip_size: 10).tap do |c|
85
+ assert_nothing_raised {c.delete xx, yy}
86
+ assert_equal 0, count_all_chips(c)
87
+ end
88
+ end
89
+
90
+ [
91
+ [20, 30, 0], [21, 31, 0], [25, 35, 0], [29, 39, 0],
92
+ [19, 29, 1], [30, 40, 1],
93
+ [29.999, 39.999, 0],
94
+ [19.999, 29.999, 1]
95
+ ].each do |xx, yy, count|
96
+ chunk(10, 20, 30, 40, chip_size: 10).tap do |c|
97
+ c.put 20, 30, chip(0, 0, 10, 10)
98
+ assert_equal 1, count_all_chips(c)
99
+ assert_nothing_raised {c.delete xx, yy}
100
+ assert_equal count, count_all_chips(c)
101
+ end
102
+ end
103
+
104
+ [
105
+ [20, 30, 0], [30, 30, 0], [20, 40, 0], [30, 40, 0],
106
+ [39, 40, 0], [30, 49, 0], [39, 49, 0],
107
+ [19, 29, 4], [40, 50, 4],
108
+ [39.999, 49.999, 0], [39.999, 40, 0], [30, 49.999, 0],
109
+ [19.999, 29.999, 4],
110
+ ].each do |xx, yy, count|
111
+ chunk(10, 20, 30, 40, chip_size: 10).tap do |c|
112
+ c.put 20, 30, chip(0, 0, 20, 20)
113
+ assert_equal 4, count_all_chips(c)
114
+ assert_nothing_raised {c.delete xx, yy}
115
+ assert_equal count, count_all_chips(c)
116
+ end
117
+ end
118
+ end
119
+
120
+ def test_delete_last_nils()
121
+ chunk(0, 0, 30, 30, chip_size: 10).tap do |c|
122
+ c.put 10, 10, chip(0, 0, 10, 10)
123
+ c.put 10, 20, chip(0, 0, 10, 10)
124
+ assert_equal 8, c.to_hash[:chips].size
125
+
126
+ c.delete 10, 20
127
+ assert_equal 5, c.to_hash[:chips].size
128
+ end
129
+ end
130
+
131
+ def test_each_chip()
132
+ c = chunk 10, 20, 30, 40, chip_size: 10
133
+ c.put 10, 20, chip(0, 0, 10, 10, id: 1)
134
+ c.put 20, 30, chip(0, 0, 20, 20, id: 2)
135
+
136
+ assert_equal(
137
+ [[1, 10,20, 10,20], [2, 20,30, 20,30]],
138
+ c.each_chip(include_hidden: false).map {|chip, x, y| [chip.id, chip.pos.x,chip.pos.y, x,y]})
139
+ assert_equal(
140
+ [
141
+ [1, 10,20, 10,20],
142
+ [2, 20,30, 20,30], [2, 20,30, 30,30], [2, 20,30, 20,40], [2, 20,30, 30,40]
143
+ ],
144
+ c.each_chip(include_hidden: true) .map {|chip, x, y| [chip.id, chip.pos.x,chip.pos.y, x,y]})
145
+ end
146
+
147
+ def test_each_chip_pos()
148
+ c = chunk 10, 20, 30, 40, chip_size: 10
149
+ assert_equal [], c.each_chip_pos( 0, 0, 10, 10).to_a
150
+ assert_equal [], c.each_chip_pos(20, 30, 0, 0).to_a
151
+ assert_equal [[20, 30]], c.each_chip_pos(20, 30, 1, 1).to_a
152
+ assert_equal [[10, 20]], c.each_chip_pos(20, 30, -1, -1) .to_a
153
+ assert_equal [[20, 30]], c.each_chip_pos(20, 30, 10, 10).to_a
154
+ assert_equal [[20, 30], [30, 30]], c.each_chip_pos(20, 30, 11, 10).to_a
155
+ assert_equal [[20, 30], [20, 40]], c.each_chip_pos(20, 30, 10, 11).to_a
156
+ assert_equal([[20, 30], [30, 30], [20, 40], [30, 40]],
157
+ c.each_chip_pos(20, 30, 11, 11).to_a)
158
+ assert_equal [[20, 30]], c.each_chip_pos(29, 39, 1, 1) .to_a
159
+ assert_equal [[20, 30], [30, 30]], c.each_chip_pos(29, 39, 2, 1) .to_a
160
+ end
161
+
162
+ def test_to_hash()
163
+ c = chunk 10, 20, 30, 40, chip_size: 10
164
+ c.put 20, 30, chip(0, 0, 10, 10, id: 1)
165
+ assert_equal(
166
+ {
167
+ x: 10, y: 20, w: 30, h: 40, chip_size: 10,
168
+ chips: [nil,nil,nil, nil,[1,20,30]]
169
+ },
170
+ c.to_hash)
171
+
172
+ c.put 30, 40, chip(0, 0, 10, 20, id: 2)
173
+ assert_equal(
174
+ {
175
+ x: 10, y: 20, w: 30, h: 40, chip_size: 10,
176
+ chips: [nil,nil,nil, nil,[1,20,30],nil, nil,nil,[2,30,40], nil,nil,[2,30,40]]
177
+ },
178
+ c.to_hash)
179
+ end
180
+
181
+ def test_compare()
182
+ assert_not_equal chunk(10, 20, 30, 40, chip_size: 10), chunk( 0, 20, 30, 40, chip_size: 10)
183
+ assert_not_equal chunk(10, 20, 30, 40, chip_size: 10), chunk(10, 0, 30, 40, chip_size: 10)
184
+ assert_not_equal chunk(10, 20, 30, 40, chip_size: 10), chunk(10, 20, 0, 40, chip_size: 10)
185
+ assert_not_equal chunk(10, 20, 30, 40, chip_size: 10), chunk(10, 20, 30, 0, chip_size: 10)
186
+ assert_not_equal chunk(10, 20, 30, 40, chip_size: 10), chunk(10, 20, 30, 40, chip_size: 1)
187
+
188
+ c1, c2 = chunk(10, 20, 30, 40, chip_size: 10), chunk(10, 20, 30, 40, chip_size: 10)
189
+ assert_equal c1, c2
190
+
191
+ img = image
192
+ c1.put 10, 20, chip(0, 0, 10, 10, id: 1, image: img); assert_not_equal c1, c2
193
+ c2.put 10, 20, chip(0, 0, 10, 10, id: 1, image: img); assert_equal c1, c2
194
+ c2.delete 10, 20
195
+ c2.put 10, 20, chip(0, 0, 10, 10, id: 2, image: img); assert_not_equal c1, c2
196
+ end
197
+
198
+ def test_restore()
199
+ img = image
200
+ chips = R8::ChipList.restore({
201
+ next_id: 3, chips: [
202
+ {id: 1, x: 0, y: 0, w: 10, h: 10},
203
+ {id: 2, x: 0, y: 0, w: 10, h: 20},
204
+ ]
205
+ }, img)
206
+ restored = R8::Map::Chunk.restore({
207
+ x: 10, y: 20, w: 30, h: 40, chip_size: 10,
208
+ chips: [nil,nil,nil, nil,[1,20,30],nil, nil,nil,[2,30,40], nil,nil,[2,30,40]]
209
+ }, chips)
210
+
211
+ assert_equal(
212
+ chunk(10, 20, 30, 40, chip_size: 10).tap {
213
+ _1.put 20, 30, chip(0, 0, 10, 10, id: 1, image: img)
214
+ _1.put 30, 40, chip(0, 0, 10, 20, id: 2, image: img)
215
+ },
216
+ restored)
217
+ assert_equal restored[30, 40].object_id, restored[30, 50].object_id
218
+ end
219
+
220
+ private
221
+
222
+ def count_all_chips(chunk)
223
+ chunk.each_chip(include_hidden: true).to_a.size
224
+ end
225
+
226
+ end# TestMapChunk
metadata ADDED
@@ -0,0 +1,244 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reight
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - xordog
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-01-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xot
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.2
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.3.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 0.3.2
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.3.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: rucy
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.3.2
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.3.2
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 0.3.2
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.3.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: beeps
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 0.3.2
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.3.2
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.3.2
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 0.3.2
73
+ - !ruby/object:Gem::Dependency
74
+ name: rays
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 0.3.2
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.3.2
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.2
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.3.2
93
+ - !ruby/object:Gem::Dependency
94
+ name: reflexion
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: 0.3.2
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 0.3.2
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.3.2
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 0.3.2
113
+ - !ruby/object:Gem::Dependency
114
+ name: processing
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '1.1'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 1.1.2
123
+ type: :runtime
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '1.1'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 1.1.2
133
+ - !ruby/object:Gem::Dependency
134
+ name: rubysketch
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 0.7.2
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 0.7.2
143
+ type: :runtime
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: 0.7.2
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 0.7.2
153
+ description: A Retro Game Engine for Ruby.
154
+ email: xordog@gmail.com
155
+ executables:
156
+ - r8
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".github/workflows/release-gem.yml"
161
+ - ".github/workflows/tag.yml"
162
+ - ".github/workflows/test.yml"
163
+ - ".github/workflows/utils.rb"
164
+ - ".gitignore"
165
+ - ChangeLog.md
166
+ - Gemfile
167
+ - LICENSE
168
+ - README.md
169
+ - Rakefile
170
+ - VERSION
171
+ - bin/r8
172
+ - lib/reight.rb
173
+ - lib/reight/all.rb
174
+ - lib/reight/app.rb
175
+ - lib/reight/app/map.rb
176
+ - lib/reight/app/map/brush.rb
177
+ - lib/reight/app/map/brush_base.rb
178
+ - lib/reight/app/map/canvas.rb
179
+ - lib/reight/app/map/chips.rb
180
+ - lib/reight/app/map/editor.rb
181
+ - lib/reight/app/map/line.rb
182
+ - lib/reight/app/map/rect.rb
183
+ - lib/reight/app/map/tool.rb
184
+ - lib/reight/app/music.rb
185
+ - lib/reight/app/music/editor.rb
186
+ - lib/reight/app/navigator.rb
187
+ - lib/reight/app/runner.rb
188
+ - lib/reight/app/sound.rb
189
+ - lib/reight/app/sound/editor.rb
190
+ - lib/reight/app/sprite.rb
191
+ - lib/reight/app/sprite/brush.rb
192
+ - lib/reight/app/sprite/canvas.rb
193
+ - lib/reight/app/sprite/chips.rb
194
+ - lib/reight/app/sprite/color.rb
195
+ - lib/reight/app/sprite/editor.rb
196
+ - lib/reight/app/sprite/fill.rb
197
+ - lib/reight/app/sprite/line.rb
198
+ - lib/reight/app/sprite/select.rb
199
+ - lib/reight/app/sprite/shape.rb
200
+ - lib/reight/app/sprite/tool.rb
201
+ - lib/reight/button.rb
202
+ - lib/reight/chip.rb
203
+ - lib/reight/extension.rb
204
+ - lib/reight/helpers.rb
205
+ - lib/reight/history.rb
206
+ - lib/reight/map.rb
207
+ - lib/reight/project.rb
208
+ - lib/reight/reight.rb
209
+ - reight.gemspec
210
+ - res/icons.png
211
+ - test/helper.rb
212
+ - test/test_chip.rb
213
+ - test/test_chip_list.rb
214
+ - test/test_map.rb
215
+ - test/test_map_chunk.rb
216
+ homepage: https://github.com/xord/reight
217
+ licenses:
218
+ - MIT
219
+ metadata: {}
220
+ post_install_message:
221
+ rdoc_options: []
222
+ require_paths:
223
+ - lib
224
+ required_ruby_version: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: 3.0.0
229
+ required_rubygems_version: !ruby/object:Gem::Requirement
230
+ requirements:
231
+ - - ">="
232
+ - !ruby/object:Gem::Version
233
+ version: '0'
234
+ requirements: []
235
+ rubygems_version: 3.4.19
236
+ signing_key:
237
+ specification_version: 4
238
+ summary: A Retro Game Engine for Ruby.
239
+ test_files:
240
+ - test/helper.rb
241
+ - test/test_chip.rb
242
+ - test/test_chip_list.rb
243
+ - test/test_map.rb
244
+ - test/test_map_chunk.rb