dxopal 1.5.2 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/DEVELOPMENT.md +4 -4
  4. data/Gemfile +0 -1
  5. data/Gemfile.lock +22 -24
  6. data/README.md +4 -0
  7. data/Rakefile +6 -1
  8. data/build/dxopal.js +48950 -38847
  9. data/build/dxopal.min.js +1 -1
  10. data/config.ru +1 -1
  11. data/doc/api/DXOpal/Constants/Colors.html +4 -4
  12. data/doc/api/DXOpal/Constants.html +4 -4
  13. data/doc/api/DXOpal/Font.html +4 -4
  14. data/doc/api/DXOpal/Image.html +19 -19
  15. data/doc/api/DXOpal/Input/KeyCodes.html +6 -6
  16. data/doc/api/DXOpal/Input/MouseCodes.html +4 -4
  17. data/doc/api/DXOpal/Input/Touch.html +47 -47
  18. data/doc/api/DXOpal/Input.html +87 -81
  19. data/doc/api/DXOpal/RemoteResource.html +164 -33
  20. data/doc/api/DXOpal/Sound.html +22 -16
  21. data/doc/api/DXOpal/SoundEffect/WaveTypes.html +4 -4
  22. data/doc/api/DXOpal/SoundEffect.html +6 -6
  23. data/doc/api/DXOpal/Sprite/CollisionArea/Base.html +5 -5
  24. data/doc/api/DXOpal/Sprite/CollisionArea/Circle.html +4 -4
  25. data/doc/api/DXOpal/Sprite/CollisionArea/Point.html +4 -4
  26. data/doc/api/DXOpal/Sprite/CollisionArea/Rect.html +4 -4
  27. data/doc/api/DXOpal/Sprite/CollisionArea/Triangle.html +4 -4
  28. data/doc/api/DXOpal/Sprite/CollisionArea.html +4 -4
  29. data/doc/api/DXOpal/Sprite/CollisionCheck/ClassMethods.html +7 -7
  30. data/doc/api/DXOpal/Sprite/CollisionCheck.html +8 -8
  31. data/doc/api/DXOpal/Sprite/Physics.html +4 -4
  32. data/doc/api/DXOpal/Sprite.html +10 -10
  33. data/doc/api/DXOpal/Window.html +120 -114
  34. data/doc/api/DXOpal.html +5 -5
  35. data/doc/api/Kernel.html +4 -4
  36. data/doc/api/_index.html +5 -5
  37. data/doc/api/file.README.html +23 -20
  38. data/doc/api/frames.html +10 -5
  39. data/doc/api/index.html +23 -20
  40. data/doc/api/method_list.html +214 -206
  41. data/doc/api/top-level-namespace.html +4 -4
  42. data/lib/dxopal/input.rb +5 -2
  43. data/lib/dxopal/remote_resource.rb +33 -1
  44. data/lib/dxopal/sound.rb +5 -2
  45. data/lib/dxopal/version.rb +1 -1
  46. data/lib/dxopal/window.rb +6 -3
  47. data/lib/dxopal.rb +1 -0
  48. metadata +3 -3
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Documentation by YARD 0.9.26
9
+ &mdash; Documentation by YARD 0.9.36
10
10
 
11
11
  </title>
12
12
 
@@ -241,9 +241,9 @@
241
241
  </div>
242
242
 
243
243
  <div id="footer">
244
- Generated on Tue Dec 29 11:37:22 2020 by
245
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
246
- 0.9.26 (ruby-2.7.0).
244
+ Generated on Tue Jul 9 22:42:33 2024 by
245
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
246
+ 0.9.36 (ruby-3.2.2).
247
247
  </div>
248
248
 
249
249
  </div>
data/lib/dxopal/input.rb CHANGED
@@ -93,7 +93,7 @@ module DXOpal
93
93
  # stolen by DXOpal.) If canvas element is set to this, only key events
94
94
  # happend on canvas are processed by DXOpal.
95
95
  def self.keyevent_target=(target)
96
- if @@keyevent_target
96
+ if keyevent_target
97
97
  %x{
98
98
  #{@@keyevent_target}.removeEventListener('keydown', #{ON_KEYDOWN_});
99
99
  #{@@keyevent_target}.removeEventListener('keyup', #{ON_KEYUP_});
@@ -110,7 +110,10 @@ module DXOpal
110
110
  end
111
111
 
112
112
  # Return DOM element set by `keyevent_target=`
113
- def self.keyevent_target; @@keyevent_target; end
113
+ def self.keyevent_target
114
+ return nil unless class_variable_defined?(:@@keyevent_target)
115
+ @@keyevent_target
116
+ end
114
117
 
115
118
  #
116
119
  # Mouse
@@ -11,6 +11,8 @@ module DXOpal
11
11
  @@promises = Hash.new{|h,k| h[k] = {}}
12
12
  # Contains instances of Image, Sound
13
13
  @@instances = Hash.new{|h,k| h[k] = {}}
14
+ # `true` if the resource is loaded
15
+ @@loaded = Hash.new{|h,k| h[k] = {}}
14
16
 
15
17
  # Subclasses of RemoteResource
16
18
  @@klasses = {}
@@ -41,7 +43,11 @@ module DXOpal
41
43
  if !@@promises[klass_name][name]
42
44
  instance, promise = klass._load(*args, &block2)
43
45
  @@instances[klass_name][name] = instance
44
- @@promises[klass_name][name] = promise
46
+ @@loaded[klass_name][name] = false
47
+ @@promises[klass_name][name] = promise.JS.then{
48
+ @@loaded[klass_name][name] = true
49
+ RemoteResource._update_loading_status
50
+ }
45
51
  end
46
52
  end
47
53
  end
@@ -63,5 +69,31 @@ module DXOpal
63
69
  def self._klass_name
64
70
  return self.name.split(/::/).last
65
71
  end
72
+
73
+ # Update loading status if `dxopal-loading` is defined.
74
+ def self._update_loading_status
75
+ done = true
76
+ report = "DXOpal loading...\n" +
77
+ @@promises.map{|klass_name, promises|
78
+ n_total = @@resources[klass_name].count
79
+ n_loaded = @@loaded[klass_name].values.count(true)
80
+ done = false if n_loaded < n_total
81
+ "#{klass_name}: #{n_loaded}/#{n_total}\n"
82
+ }.join
83
+ div = `document.getElementById('dxopal-loading')`
84
+ if `div`
85
+ %x{
86
+ let pre = div.firstChild;
87
+ if (!pre) {
88
+ pre = document.createElement('pre');
89
+ div.appendChild(pre);
90
+ }
91
+ pre.textContent = #{report};
92
+ if (#{done}) {
93
+ div.style.display = 'none';
94
+ }
95
+ }
96
+ end
97
+ end
66
98
  end
67
99
  end
data/lib/dxopal/sound.rb CHANGED
@@ -38,14 +38,17 @@ module DXOpal
38
38
  end
39
39
  attr_accessor :decoded
40
40
 
41
- # Play this sound once
42
- def play
41
+ # Play this sound
42
+ def play(loop_ = false)
43
43
  raise "Sound #{path_or_url} is not loaded yet" unless @decoded
44
44
  source = nil
45
45
  %x{
46
46
  var context = #{Sound.audio_context};
47
47
  source = context.createBufferSource();
48
48
  source.buffer = #{@decoded};
49
+ if (#{loop_}) {
50
+ source.loop = true;
51
+ }
49
52
  source.connect(context.destination);
50
53
  source.start(0);
51
54
  }
@@ -1,3 +1,3 @@
1
1
  module DXOpal
2
- VERSION = "1.5.2"
2
+ VERSION = "1.6.0"
3
3
  end
data/lib/dxopal/window.rb CHANGED
@@ -29,7 +29,8 @@ module DXOpal
29
29
  already_running = !!@@block
30
30
  @@block = block
31
31
  return if already_running
32
- `window`.JS.requestAnimationFrame{|time| _loop(time) }
32
+ self_ = self
33
+ `window`.JS.requestAnimationFrame{|time| self_._loop(time) }
33
34
  end
34
35
 
35
36
  # (DXOpal original) Pause & resume
@@ -61,7 +62,8 @@ module DXOpal
61
62
  if @@fps_ct >= frame_msec
62
63
  @@fps_ct -= frame_msec
63
64
  else
64
- `window`.JS.requestAnimationFrame{|time| _loop(time) }
65
+ self_ = self
66
+ `window`.JS.requestAnimationFrame{|time| self_._loop(time) }
65
67
  return
66
68
  end
67
69
 
@@ -110,7 +112,8 @@ module DXOpal
110
112
  end
111
113
  end
112
114
 
113
- `window`.JS.requestAnimationFrame{|time| _loop(time) }
115
+ self_ = self
116
+ `window`.JS.requestAnimationFrame{|time| self_._loop(time) }
114
117
  end
115
118
 
116
119
  def self._init
data/lib/dxopal.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # backtick_javascript: true
1
2
  require 'opal'
2
3
  require 'console'; def console; $console; end
3
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dxopal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yutaka HARA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-29 00:00:00.000000000 Z
11
+ date: 2024-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.1.2
148
+ rubygems_version: 3.4.10
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: Game development framework for Opal