dxopal 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/dxopal.gemspec CHANGED
@@ -10,7 +10,10 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["yutaka.hara+github@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Game development framework for Opal}
13
- spec.homepage = "https://github.com/yhara/dxopal"
13
+ spec.homepage = "https://yhara.github.io/dxopal/"
14
+ spec.metadata = {
15
+ "source_code_uri" => "https://github.com/yhara/dxopal"
16
+ }
14
17
  spec.license = "MIT"
15
18
 
16
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
@@ -26,5 +29,6 @@ Gem::Specification.new do |spec|
26
29
  spec.add_development_dependency "bundler", "~> 1.14"
27
30
  spec.add_development_dependency "rake", "~> 10.0"
28
31
  spec.add_development_dependency "yard", "~> 0.9.12"
32
+ spec.add_development_dependency "puma", "~> 3.11.2"
29
33
  spec.add_development_dependency "opal-sprockets", "~> 0.4.1"
30
34
  end
data/opal/dxopal.rb CHANGED
@@ -26,8 +26,14 @@ def require_remote(url)
26
26
  eval `r.responseText`
27
27
  end
28
28
 
29
- # These libraries will be included in dxopal.js:
29
+ # These opal stdlibs will be embedded in dxopal.js.
30
+ require 'singleton'
31
+ require 'delegate'
32
+ require 'forwardable'
30
33
  require 'pp'
34
+ require 'promise'
35
+ require 'set'
36
+ require 'time'
31
37
 
32
38
  module DXOpal
33
39
  include DXOpal::Constants::Colors
data/opal/dxopal/input.rb CHANGED
@@ -69,7 +69,7 @@ module DXOpal
69
69
  # (private) JS keydown event handler
70
70
  ON_KEYDOWN_ = %x{
71
71
  function(ev){
72
- #{Input._pressing_keys}[ev.keyCode] = #{@@tick};
72
+ #{Input._pressing_keys}[ev.code] = #{@@tick};
73
73
  ev.preventDefault();
74
74
  ev.stopPropagation();
75
75
  }
@@ -77,7 +77,7 @@ module DXOpal
77
77
  # (private) JS keyup event handler
78
78
  ON_KEYUP_ = %x{
79
79
  function(ev){
80
- #{Input._pressing_keys}[ev.keyCode] = -#{@@tick};
80
+ #{Input._pressing_keys}[ev.code] = -#{@@tick};
81
81
  ev.preventDefault();
82
82
  ev.stopPropagation();
83
83
  }
@@ -1,64 +1,70 @@
1
1
  module DXOpal
2
2
  module Input
3
+ # List of key codes (event.code)
4
+ # https://developer.mozilla.org/ja/docs/Web/API/KeyboardEvent
3
5
  module KeyCodes
4
- K_ESCAPE = 27
5
- # K_1 1
6
- # K_2 2
7
- # K_3 3
8
- # K_4 4
9
- # K_5 5
10
- # K_6 6
11
- # K_7 7
12
- # K_8 8
13
- # K_9 9
14
- # K_0 0
15
- K_MINUS = 189
16
- #K_EQUALS = "="
17
- K_BACK = 8 # Backspace
18
- K_TAB = 9
19
- K_Q = 81
20
- K_W = 87
21
- K_E = 69
22
- K_R = 82
23
- K_T = 84
24
- K_Y = 89
25
- K_U = 85
26
- K_I = 73
27
- K_O = 79
28
- K_P = 80
29
- K_LBRACKET = 219
30
- K_RBRACKET = 221
31
- K_RETURN = 13
32
- #K_LCONTROL Ctrl
33
- K_A = 65
34
- K_S = 83
35
- K_D = 68
36
- K_F = 70
37
- K_G = 71
38
- K_H = 72
39
- K_J = 74
40
- K_K = 75
41
- K_L = 76
42
- K_SEMICOLON = 186
43
- #K_APOSTROPHE = "'"
6
+ # TODO: add more keycodes (pull request welcome)
7
+ # especially keypads and us-keyboards
8
+
9
+ K_ESCAPE = 'Escape'
10
+ K_1 = 'Digit1'
11
+ K_2 = 'Digit2'
12
+ K_3 = 'Digit3'
13
+ K_4 = 'Digit4'
14
+ K_5 = 'Digit5'
15
+ K_6 = 'Digit6'
16
+ K_7 = 'Digit7'
17
+ K_8 = 'Digit8'
18
+ K_9 = 'Digit9'
19
+ K_0 = 'Digit0'
20
+ K_MINUS = 'Minus'
21
+ K_EQUALS = 'Equal'
22
+ K_BACK = 'Backspace'
23
+ K_TAB = 'Tab'
24
+ K_Q = 'KeyQ'
25
+ K_W = 'KeyW'
26
+ K_E = 'KeyE'
27
+ K_R = 'KeyR'
28
+ K_T = 'KeyT'
29
+ K_Y = 'KeyY'
30
+ K_U = 'KeyU'
31
+ K_I = 'KeyI'
32
+ K_O = 'KeyO'
33
+ K_P = 'KeyP'
34
+ K_LBRACKET = 'BracketLeft'
35
+ K_RBRACKET = 'BracketRight'
36
+ K_RETURN = 'Enter'
37
+ K_ENTER = 'Enter' # Alias; not in DXRuby
38
+ K_LCONTROL = 'ControlLeft'
39
+ K_A = 'KeyA'
40
+ K_S = 'KeyS'
41
+ K_D = 'KeyD'
42
+ K_F = 'KeyF'
43
+ K_G = 'KeyG'
44
+ K_H = 'KeyH'
45
+ K_J = 'KeyJ'
46
+ K_K = 'KeyK'
47
+ K_L = 'KeyL'
48
+ K_SEMICOLON = 'Semicolon'
49
+ K_APOSTROPHE = 'Quote' # '
44
50
  #K_GRAVE = "`"
45
- #K_LSHIFT Shift
46
- K_BACKSLASH = 0
47
- K_Z = 90
48
- K_X = 88
49
- K_C = 67
50
- K_V = 86
51
- K_B = 66
52
- K_N = 78
53
- K_M = 77
54
- K_COMMA = 188
55
- K_PERIOD = 190
56
- K_SLASH = 191
57
- #K_RSHIFT Shift
51
+ K_LSHIFT = 'ShiftLeft'
52
+ K_BACKSLASH = 'BackSlash' # Note: different to K_YEN
53
+ K_Z = 'KeyZ'
54
+ K_X = 'KeyX'
55
+ K_C = 'KeyC'
56
+ K_V = 'KeyV'
57
+ K_B = 'KeyB'
58
+ K_N = 'KeyN'
59
+ K_M = 'KeyM'
60
+ K_COMMA = 'Comma'
61
+ K_PERIOD = 'Period'
62
+ K_SLASH = 'Slash'
63
+ K_RSHIFT = 'ShiftRight'
58
64
  #K_MULTIPLY = "*"
59
65
  #K_LMENU Alt
60
- K_SPACE = 32
61
- #K_CAPITAL Caps Lock
66
+ K_SPACE = 'Space'
67
+ #K_CAPITAL
62
68
  K_F1 = 112
63
69
  K_F2 = 113
64
70
  K_F3 = 114
@@ -94,20 +100,20 @@ module DXOpal
94
100
  #K_ABNT_C1
95
101
  #K_CONVERT
96
102
  #K_NOCONVERT
97
- #K_YEN
103
+ K_YEN = 'IntlYen'
98
104
  #K_ABNT_C2
99
105
  #K_NUMPADEQUALS = *3 *1
100
- K_PREVTRACK = 187 # ^
101
- K_AT = 219 # @
102
- K_COLON = 186
103
- K_UNDERLINE = 189 # _
106
+ #K_PREVTRACK
107
+ #K_AT
108
+ K_COLON = 'Colon'
109
+ K_UNDERLINE = 'IntlRo' # _
104
110
  #K_KANJI
105
111
  #K_STOP
106
112
  #K_AX
107
113
  #K_UNLABELED
108
114
  #K_NEXTTRACK
109
115
  #K_NUMPADENTER Enter *3
110
- #K_RCONTROL Ctrl
116
+ K_RCONTROL = 'ControlRight'
111
117
  #K_MUTE
112
118
  #K_CALCULATOR
113
119
  #K_PLAYPAUSE
@@ -121,12 +127,12 @@ module DXOpal
121
127
  #K_RMENU Alt
122
128
  #K_PAUSE = "Pause"
123
129
  #K_HOME "Home"
124
- K_UP = 38
130
+ K_UP = 'ArrowUp'
125
131
  #K_PRIOR
126
- K_LEFT = 37
127
- K_RIGHT = 39
132
+ K_LEFT = 'ArrowLeft'
133
+ K_RIGHT = 'ArrowRight'
128
134
  #K_END = "End"
129
- K_DOWN = 40
135
+ K_DOWN = 'ArrowDown'
130
136
  #K_NEXT
131
137
  #K_INSERT = "Insert"
132
138
  #K_DELETE = "Delete"
@@ -145,20 +151,20 @@ module DXOpal
145
151
  #K_MYCOMPUTER
146
152
  #K_MAIL
147
153
  #K_MEDIASELECT
148
- K_BACKSPACE = 8
154
+ K_BACKSPACE = 'Backspace'
149
155
  #K_NUMPADSTAR * *3
150
156
  #K_LALT Alt
151
- #K_CAPSLOCK CapsLock
157
+ K_CAPSLOCK = 'CapsLock'
152
158
  #K_NUMPADMINUS - *3
153
159
  #K_NUMPADPLUS + *3
154
160
  #K_NUMPADPERIOD . *3
155
161
  #K_NUMPADSLASH / *3
156
162
  #K_RALT Alt
157
- K_UPARROW = 38
163
+ K_UPARROW = 'ArrowUp'
158
164
  #K_PGUP = "PageUp"
159
- K_LEFTARROW = 37
160
- K_RIGHTARROW = 39
161
- K_DOWNARROW = 40
165
+ K_LEFTARROW = 'ArrowLeft'
166
+ K_RIGHTARROW = 'ArrowRight'
167
+ K_DOWNARROW = 'ArrowDown'
162
168
  #K_PGDN = "PageDown"
163
169
  end
164
170
  end
data/opal/dxopal/sound.rb CHANGED
@@ -41,13 +41,22 @@ module DXOpal
41
41
  # Play this sound once
42
42
  def play
43
43
  raise "Sound #{path_or_url} is not loaded yet" unless @decoded
44
+ source = nil
44
45
  %x{
45
46
  var context = #{Sound.audio_context};
46
- var source = context.createBufferSource();
47
+ source = context.createBufferSource();
47
48
  source.buffer = #{@decoded};
48
49
  source.connect(context.destination);
49
50
  source.start(0);
50
51
  }
52
+ @source = source
53
+ end
54
+
55
+ # Stop playing this sound (if playing)
56
+ def stop
57
+ return unless @decoded
58
+ return unless @source
59
+ @source.JS.stop()
51
60
  end
52
61
  end
53
62
  end
@@ -1,3 +1,3 @@
1
1
  module DXOpal
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -75,7 +75,7 @@ module DXOpal
75
75
 
76
76
  # Draw
77
77
  @@img.box_fill(0, 0, @@width, @@height, @@bgcolor)
78
- sorted = @@draw_queue.sort{|a, b| a[0] == b[0] ? a[1] <=> b[1] : a[0] <=> a[1] }
78
+ sorted = @@draw_queue.sort{|a, b| a[0] == b[0] ? a[1] <=> b[1] : a[0] <=> b[0] }
79
79
  sorted.each do |item|
80
80
  case item[2]
81
81
  when :image then @@img.draw(*item.drop(3))
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.1.0
4
+ version: 1.2.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: 2018-02-05 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.9.12
97
+ - !ruby/object:Gem::Dependency
98
+ name: puma
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.11.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.11.2
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: opal-sprockets
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -178,10 +192,11 @@ files:
178
192
  - opal/dxopal/window.rb
179
193
  - template/index.html
180
194
  - template/main.rb
181
- homepage: https://github.com/yhara/dxopal
195
+ homepage: https://yhara.github.io/dxopal/
182
196
  licenses:
183
197
  - MIT
184
- metadata: {}
198
+ metadata:
199
+ source_code_uri: https://github.com/yhara/dxopal
185
200
  post_install_message:
186
201
  rdoc_options: []
187
202
  require_paths:
@@ -198,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
213
  version: '0'
199
214
  requirements: []
200
215
  rubyforge_project:
201
- rubygems_version: 2.6.13
216
+ rubygems_version: 2.7.6
202
217
  signing_key:
203
218
  specification_version: 4
204
219
  summary: Game development framework for Opal