rubysketch 0.5.3 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  module RubySketch
2
2
 
3
3
 
4
+ # @private
4
5
  class Window < Processing::Window
5
6
 
6
7
  def on_update(e)
data/pod.rake CHANGED
@@ -19,15 +19,17 @@ task :setup
19
19
 
20
20
  repos.each do |repo, ver|
21
21
  rakefile = "#{repo}/Rakefile"
22
- opts = {
23
- depth: 1,
24
- branch: (ENV['RUBYSKETCH_BRANCH'] || "v#{ver}")
25
- }.map {|k, v| "--#{k} #{v}"}.join ' '
22
+ opts = [
23
+ '-c advice.detachedHead=false',
24
+ '--no-single-branch',
25
+ '--depth 1',
26
+ "--branch #{ENV['RUBYSKETCH_BRANCH'] || ('v' + ver)}"
27
+ ]
26
28
 
27
29
  task :setup => rakefile
28
30
 
29
31
  file rakefile do
30
- sh %( git clone #{opts} #{github}/#{repo} )
32
+ sh %( git clone #{opts.join ' '} #{github}/#{repo} )
31
33
  sh %( cd #{repo} && VENDOR_NOCOMPILE=1 rake vendor erb )
32
34
  end
33
35
  end
data/rubysketch.gemspec CHANGED
@@ -28,12 +28,12 @@ Gem::Specification.new do |s|
28
28
  s.platform = Gem::Platform::RUBY
29
29
  s.required_ruby_version = '>= 2.7.0'
30
30
 
31
- s.add_runtime_dependency 'xot', '~> 0.1.33'
32
- s.add_runtime_dependency 'rucy', '~> 0.1.33'
33
- s.add_runtime_dependency 'beeps', '~> 0.1.33'
34
- s.add_runtime_dependency 'rays', '~> 0.1.33'
35
- s.add_runtime_dependency 'reflexion', '~> 0.1.33'
36
- s.add_runtime_dependency 'processing', '~> 0.5.3'
31
+ s.add_runtime_dependency 'xot', '~> 0.1.35'
32
+ s.add_runtime_dependency 'rucy', '~> 0.1.35'
33
+ s.add_runtime_dependency 'beeps', '~> 0.1.36'
34
+ s.add_runtime_dependency 'rays', '~> 0.1.35'
35
+ s.add_runtime_dependency 'reflexion', '~> 0.1.36'
36
+ s.add_runtime_dependency 'processing', '~> 0.5.6'
37
37
 
38
38
  s.add_development_dependency 'rake'
39
39
  s.add_development_dependency 'test-unit'
data/test/helper.rb CHANGED
@@ -1,6 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
-
4
1
  %w[../xot ../rucy ../beeps ../rays ../reflex ../processing .]
5
2
  .map {|s| File.expand_path "../#{s}/lib", __dir__}
6
3
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
data/test/test_sprite.rb CHANGED
@@ -1,23 +1,238 @@
1
- # -*- coding: utf-8 -*-
2
-
3
-
4
1
  require_relative 'helper'
5
2
 
6
3
 
7
4
  class TestSprite < Test::Unit::TestCase
8
5
 
6
+ RS = RubySketch
7
+
9
8
  def sprite(*args, **kwargs)
10
- RubySketch::Sprite.new(*args, **kwargs)
9
+ RS::Sprite.new(*args, **kwargs)
11
10
  end
12
11
 
13
12
  def vec(*args, **kwargs)
14
- Processing::Vector.new(*args, **kwargs)
13
+ RS::Vector.new(*args, **kwargs)
14
+ end
15
+
16
+ def image(w, h)
17
+ RS::Image.new Rays::Image.new(w, h)
15
18
  end
16
19
 
17
20
  def test_initialize()
18
- assert_equal 0, sprite.x
19
- assert_equal 0, sprite.y
20
- assert_equal vec(0, 0), sprite.pos
21
+ assert_equal vec(0, 0), sprite .pos
22
+ assert_equal vec(1, 2), sprite(1, 2) .pos
23
+ assert_equal vec(1, 2), sprite(1, 2, 3, 4).pos
24
+
25
+ assert_equal vec(0, 0), sprite .size
26
+ assert_equal vec(3, 4), sprite(1, 2, 3, 4) .size
27
+ assert_equal vec(5, 6), sprite( image: image(5, 6)).size
28
+ assert_equal vec(5, 6), sprite(1, 2, image: image(5, 6)).size
29
+ assert_equal vec(3, 4), sprite(1, 2, 3, 4, image: image(5, 6)).size
30
+
31
+ assert_equal nil, sprite .image
32
+ assert_equal [1, 2], sprite(image: image(1, 2)).image.size
33
+
34
+ assert_equal nil, sprite.offset
35
+ assert_equal vec(1, 2), sprite(offset: [1, 2]).offset
36
+ assert_equal vec(1, 2), sprite(offset: vec(1, 2)).offset
37
+
38
+ assert_raise {sprite 0, 0, -1, 0}
39
+ assert_raise {sprite 0, 0, 0, -1}
40
+ end
41
+
42
+ def test_position()
43
+ s = sprite
44
+ assert_equal vec(0, 0), s.pos
45
+
46
+ s.pos = vec(1, 2)
47
+ assert_equal vec(1, 2), s.pos
48
+
49
+ s.pos = [3, 4]
50
+ assert_equal vec(3, 4), s.pos
51
+ end
52
+
53
+ def test_xy()
54
+ s = sprite
55
+ assert_equal 0, s.x
56
+ assert_equal vec(0, 0), s.pos
57
+
58
+ s.x = 1
59
+ assert_equal 1, s.x
60
+ assert_equal vec(1, 0), s.pos
61
+
62
+ s.y = 2
63
+ assert_equal 2, s.y
64
+ assert_equal vec(1, 2), s.pos
65
+ end
66
+
67
+ def test_size()
68
+ assert_equal vec(0, 0), sprite .size
69
+ assert_equal vec(1, 0), sprite(0, 0, 1) .size
70
+ assert_equal vec(1, 2), sprite(0, 0, 1, 2) .size
71
+ assert_equal vec(3, 4), sprite(image: image(3, 4)).size
72
+ end
73
+
74
+ def test_wh()
75
+ assert_equal 1, sprite(0, 0, 1, 2).width
76
+ assert_equal 2, sprite(0, 0, 1, 2).height
77
+ end
78
+
79
+ def test_angle()
80
+ s = sprite
81
+ assert_equal 0, s.angle
82
+
83
+ s.angle = Math::PI
84
+ assert_in_epsilon Math::PI, s.angle
85
+ end
86
+
87
+ def test_pivot()
88
+ s = sprite
89
+ assert_each_in_epsilon [0, 0], s.pivot
90
+
91
+ s.pivot = [0.1, 0.2]
92
+ assert_each_in_epsilon [0.1, 0.2], s.pivot
93
+ end
94
+
95
+ def test_velocity()
96
+ s = sprite
97
+ assert_equal vec(0, 0), s.vel
98
+
99
+ s.vel = vec(1, 2)
100
+ assert_equal vec(1, 2), s.vel
101
+
102
+ s.vel = [3, 4]
103
+ assert_equal vec(3, 4), s.vel
104
+ end
105
+
106
+ def test_vxvy()
107
+ s = sprite
108
+ assert_equal 0, s.vx
109
+ assert_equal vec(0, 0), s.vel
110
+
111
+ s.vx = 1
112
+ assert_equal 1, s.vx
113
+ assert_equal vec(1, 0), s.vel
114
+
115
+ s.vy = 2
116
+ assert_equal 2, s.vy
117
+ assert_equal vec(1, 2), s.vel
118
+ end
119
+
120
+ def test_image()
121
+ s = sprite
122
+ assert_equal nil, s.image
123
+
124
+ s.image = image(1, 2)
125
+ assert_equal [1, 2], s.image.size
126
+
127
+ s.image = image(3, 4)
128
+ assert_equal [3, 4], s.image.size
129
+
130
+ s.image = nil
131
+ assert_equal nil, s.image
132
+ end
133
+
134
+ def test_offset()
135
+ s = sprite
136
+ assert_equal nil, s.offset
137
+
138
+ s.offset = [1, 2]
139
+ assert_equal vec(1, 2), s.offset
140
+
141
+ s.offset = vec(3, 4)
142
+ assert_equal vec(3, 4), s.offset
143
+
144
+ s.offset = [5]
145
+ assert_equal vec(5, 0), s.offset
146
+
147
+ s.offset = []
148
+ assert_equal vec(0, 0), s.offset
149
+
150
+ s.offset = nil
151
+ assert_equal nil, s.offset
152
+
153
+ assert_raise(ArgumentError) {s.offset = 1}
154
+ end
155
+
156
+ def test_oxoy()
157
+ s = sprite
158
+ assert_equal [0, 0], [s.ox, s.oy]
159
+ assert_equal nil, s.offset
160
+
161
+ s.ox = 1
162
+ assert_equal [1, 0], [s.ox, s.oy]
163
+ assert_equal vec(1, 0), s.offset
164
+
165
+ s = sprite
166
+
167
+ s.oy = 2
168
+ assert_equal [0, 2], [s.ox, s.oy]
169
+ assert_equal vec(0, 2), s.offset
170
+
171
+ s.offset = nil
172
+ assert_equal [0, 0], [s.ox, s.oy]
173
+ assert_equal nil, s.offset
174
+ end
175
+
176
+ def test_dynamic?()
177
+ s = sprite
178
+ assert_equal false, s.dynamic?
179
+
180
+ s.dynamic = true
181
+ assert_equal true, s.dynamic?
182
+
183
+ s.dynamic = false
184
+ assert_equal false, s.dynamic?
185
+ end
186
+
187
+ def test_density()
188
+ s = sprite
189
+ assert_equal 1, s.dens
190
+
191
+ s.dens = 2
192
+ assert_equal 2, s.dens
193
+ end
194
+
195
+ def test_friction()
196
+ s = sprite
197
+ assert_equal 0, s.fric
198
+
199
+ s.fric = 1
200
+ assert_equal 1, s.fric
201
+ end
202
+
203
+ def test_restitution()
204
+ s = sprite
205
+ assert_equal 0, s.rest
206
+
207
+ s.rest = 1
208
+ assert_equal 1, s.rest
209
+ end
210
+
211
+ def test_blocks()
212
+ s = sprite
213
+ v = s.instance_variable_get :@view__
214
+ assert_nil v.update
215
+ assert_nil v.contact
216
+ assert_nil v.will_contact
217
+
218
+ s.update {}
219
+ assert_not_nil v.update
220
+ assert_nil v.contact
221
+ assert_nil v.will_contact
222
+
223
+ s.contact {}
224
+ assert_not_nil v.update
225
+ assert_not_nil v.contact
226
+ assert_nil v.will_contact
227
+
228
+ s.contact? {}
229
+ assert_not_nil v.update
230
+ assert_not_nil v.contact
231
+ assert_not_nil v.will_contact
232
+ end
233
+
234
+ def test_inspect()
235
+ assert_match %r|#<RubySketch::Sprite:0x\w{16}>|, sprite.inspect
21
236
  end
22
237
 
23
238
  end# TestSprite
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysketch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-21 00:00:00.000000000 Z
11
+ date: 2023-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot
@@ -16,84 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.33
19
+ version: 0.1.35
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.33
26
+ version: 0.1.35
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rucy
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.33
33
+ version: 0.1.35
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.33
40
+ version: 0.1.35
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: beeps
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.33
47
+ version: 0.1.36
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.33
54
+ version: 0.1.36
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rays
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.33
61
+ version: 0.1.35
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.33
68
+ version: 0.1.35
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: reflexion
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.1.33
75
+ version: 0.1.36
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.1.33
82
+ version: 0.1.36
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: processing
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.5.3
89
+ version: 0.5.6
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.5.3
96
+ version: 0.5.6
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -156,13 +156,13 @@ files:
156
156
  - RubySketch.podspec
157
157
  - VERSION
158
158
  - examples/hello.rb
159
+ - examples/physics.rb
160
+ - examples/sprite.rb
159
161
  - lib/rubysketch.rb
160
162
  - lib/rubysketch/all.rb
161
163
  - lib/rubysketch/context.rb
162
164
  - lib/rubysketch/extension.rb
163
- - lib/rubysketch/graphics_context.rb
164
165
  - lib/rubysketch/helper.rb
165
- - lib/rubysketch/sound.rb
166
166
  - lib/rubysketch/sprite.rb
167
167
  - lib/rubysketch/window.rb
168
168
  - pod.rake
@@ -170,7 +170,6 @@ files:
170
170
  - src/RubySketch.h
171
171
  - src/RubySketch.mm
172
172
  - test/helper.rb
173
- - test/test_sound.rb
174
173
  - test/test_sprite.rb
175
174
  homepage: https://github.com/xord/rubysketch
176
175
  licenses: []
@@ -196,5 +195,4 @@ specification_version: 4
196
195
  summary: A game engine based on the Processing API.
197
196
  test_files:
198
197
  - test/helper.rb
199
- - test/test_sound.rb
200
198
  - test/test_sprite.rb
@@ -1,37 +0,0 @@
1
- module RubySketch
2
-
3
-
4
- module GraphicsContext
5
-
6
- def sprite(*sprites)
7
- sprites.flatten! if sprites.first&.is_a? Array
8
- sprites.each do |sp|
9
- v = sp.getInternal__
10
- f, angle, img, offset = v.frame, v.angle, sp.image, sp.offset
11
- if angle == 0
12
- drawSprite__ f.x, f.y, f.w, f.h, img, offset
13
- else
14
- pushMatrix do
15
- translate f.x, f.y
16
- rotate radians(angle)
17
- drawSprite__ 0, 0, f.w, f.h, img, offset
18
- end
19
- end
20
- end
21
- end
22
-
23
- def drawSprite__(x, y, w, h, img, offset)
24
- if img && offset
25
- ox, oy = offset
26
- copy img, ox, oy, w, h, x, y, w, h
27
- elsif img
28
- image img, x, y
29
- else
30
- rect x, y, w, h
31
- end
32
- end
33
-
34
- end# GraphicsContext
35
-
36
-
37
- end# RubySketch
@@ -1,55 +0,0 @@
1
- module RubySketch
2
-
3
-
4
- class Sound
5
-
6
- # @private
7
- def initialize(sound)
8
- @sound = sound
9
- end
10
-
11
- def play()
12
- old = @player
13
- @player = @sound.play
14
- old&.stop
15
- true
16
- end
17
-
18
- def pause()
19
- return false unless @player
20
- @player.pause
21
- true
22
- end
23
-
24
- def stop()
25
- return false unless @player
26
- @player.stop
27
- @player = nil
28
- true
29
- end
30
-
31
- def playing?()
32
- @player ? @player.playing? : false
33
- end
34
-
35
- def paused?()
36
- !playing? && !stopped?
37
- end
38
-
39
- def stopped?()
40
- @player ? @player.stopped? : true
41
- end
42
-
43
- def save(path)
44
- @sound.save path
45
- end
46
-
47
- def self.load(path)
48
- f = Beeps::FileIn.new path
49
- self.new Beeps::Sound.new(f, f.seconds, nchannels: f.nchannels)
50
- end
51
-
52
- end# Sound
53
-
54
-
55
- end# RubySketch
data/test/test_sound.rb DELETED
@@ -1,90 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
-
4
- require_relative 'helper'
5
-
6
-
7
- class TestSound < Test::Unit::TestCase
8
-
9
- RS = RubySketch
10
- B = Beeps
11
-
12
- PATH = 'test.wav'
13
-
14
- def sound()
15
- RS::Sound.load PATH
16
- end
17
-
18
- def setup()
19
- B::Sound.new(B::Oscillator.new >> B::Gain.new(gain: 0), 0.1).save PATH
20
- end
21
-
22
- def teardown()
23
- B::SoundPlayer.stop_all
24
- File.delete PATH if File.exist?(PATH)
25
- end
26
-
27
- def test_play()
28
- s = sound
29
- assert_equal [false, false, true], [s.playing?, s.paused?, s.stopped?]
30
- s.play
31
- assert_equal [true, false, false], [s.playing?, s.paused?, s.stopped?]
32
- end
33
-
34
- def test_pause()
35
- s = sound
36
- s.play
37
- assert_equal [true, false, false], [s.playing?, s.paused?, s.stopped?]
38
- s.pause
39
- assert_equal [false, true, false], [s.playing?, s.paused?, s.stopped?]
40
- end
41
-
42
- def test_stop()
43
- s = sound
44
- s.play
45
- assert_equal [true, false, false], [s.playing?, s.paused?, s.stopped?]
46
- s.stop
47
- assert_equal [false, false, true], [s.playing?, s.paused?, s.stopped?]
48
- end
49
-
50
- def test_play_end_then_stop()
51
- s = sound
52
- s.play
53
- assert_equal [true, false, false], [s.playing?, s.paused?, s.stopped?]
54
- sleep 0.2
55
- assert_equal [false, false, true], [s.playing?, s.paused?, s.stopped?]
56
- end
57
-
58
- def test_play_after_pause()
59
- s = sound
60
- s.play
61
- s.pause
62
- assert_equal [false, true, false], [s.playing?, s.paused?, s.stopped?]
63
- s.play
64
- assert_equal [true, false, false], [s.playing?, s.paused?, s.stopped?]
65
- end
66
-
67
- def test_stop_after_pause()
68
- s = sound
69
- s.play
70
- s.pause
71
- assert_equal [false, true, false], [s.playing?, s.paused?, s.stopped?]
72
- s.stop
73
- assert_equal [false, false, true], [s.playing?, s.paused?, s.stopped?]
74
- end
75
-
76
- def test_save()
77
- s = sound
78
-
79
- File.delete PATH
80
- assert_false File.exist? PATH
81
-
82
- s.save PATH
83
- assert_true File.exist? PATH
84
- end
85
-
86
- def test_load()
87
- assert_nothing_raised {sound.play}
88
- end
89
-
90
- end# TestSound