dxopal 1.3.0 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/Gemfile +2 -2
  4. data/Gemfile.lock +22 -11
  5. data/HACKING.md +18 -0
  6. data/Rakefile +30 -42
  7. data/TODO.md +2 -2
  8. data/build/dxopal.js +26126 -18430
  9. data/build/dxopal.min.js +1 -1
  10. data/config.ru +2 -2
  11. data/doc/api/_index.html +7 -138
  12. data/doc/api/class_list.html +3 -3
  13. data/doc/api/css/style.css +2 -2
  14. data/doc/api/file.README.html +6 -6
  15. data/doc/api/file_list.html +2 -2
  16. data/doc/api/frames.html +2 -2
  17. data/doc/api/index.html +6 -6
  18. data/doc/api/js/app.js +25 -3
  19. data/doc/api/method_list.html +2 -970
  20. data/doc/api/top-level-namespace.html +6 -16
  21. data/doc/en/index.html +3 -2
  22. data/doc/ja/index.html +3 -2
  23. data/dxopal.gemspec +2 -2
  24. data/exe/dxopal +13 -1
  25. data/{opal → lib}/dxopal.rb +1 -0
  26. data/{opal → lib}/dxopal/constants/colors.rb +0 -0
  27. data/{opal → lib}/dxopal/font.rb +5 -0
  28. data/{opal → lib}/dxopal/image.rb +40 -9
  29. data/{opal → lib}/dxopal/input.rb +55 -0
  30. data/{opal → lib}/dxopal/input/key_codes.rb +64 -66
  31. data/lib/dxopal/patches/require_dxopal.rb +30 -0
  32. data/{opal → lib}/dxopal/patches/require_remote.rb +0 -0
  33. data/{opal → lib}/dxopal/remote_resource.rb +2 -2
  34. data/{opal → lib}/dxopal/sound.rb +0 -0
  35. data/{opal → lib}/dxopal/sound_effect.rb +0 -0
  36. data/{opal → lib}/dxopal/sprite.rb +0 -0
  37. data/{opal → lib}/dxopal/sprite/collision_area.rb +0 -0
  38. data/{opal → lib}/dxopal/sprite/collision_check.rb +0 -0
  39. data/{opal → lib}/dxopal/sprite/collision_checker.rb +0 -0
  40. data/{opal → lib}/dxopal/sprite/physics.rb +0 -0
  41. data/lib/dxopal/version.rb +3 -0
  42. data/{opal → lib}/dxopal/window.rb +0 -0
  43. metadata +24 -23
  44. data/opal/dxopal/version.rb +0 -3
@@ -6,15 +6,15 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Documentation by YARD 0.9.16
9
+ &mdash; Documentation by YARD 0.9.24
10
10
 
11
11
  </title>
12
12
 
13
- <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
14
 
15
- <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
16
 
17
- <script type="text/javascript" charset="utf-8">
17
+ <script type="text/javascript">
18
18
  pathId = "";
19
19
  relpath = '';
20
20
  </script>
@@ -78,16 +78,6 @@
78
78
 
79
79
  </div>
80
80
 
81
- <h2>Defined Under Namespace</h2>
82
- <p class="children">
83
-
84
-
85
- <strong class="modules">Modules:</strong> <span class='object_link'><a href="DXOpal.html" title="DXOpal (module)">DXOpal</a></span>
86
-
87
-
88
-
89
-
90
- </p>
91
81
 
92
82
 
93
83
 
@@ -100,9 +90,9 @@
100
90
  </div>
101
91
 
102
92
  <div id="footer">
103
- Generated on Sat Sep 29 15:56:47 2018 by
93
+ Generated on Sat Jan 18 14:57:06 2020 by
104
94
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
- 0.9.16 (ruby-2.5.1).
95
+ 0.9.24 (ruby-2.5.5).
106
96
  </div>
107
97
 
108
98
  </div>
@@ -49,9 +49,8 @@
49
49
  <h3>If you have Ruby installed:</h3>
50
50
  <p>
51
51
  <pre><code>$ gem install dxopal
52
- $ mkdir game1
52
+ $ dxopal new game1
53
53
  $ cd game1
54
- $ dxopal init
55
54
  $ dxopal server</code></pre>
56
55
  </p>
57
56
  <p>
@@ -61,6 +60,7 @@ $ dxopal server</code></pre>
61
60
  Then edit main.rb and reload browser.
62
61
  </p>
63
62
 
63
+ <!--
64
64
  <h3>If you don't want to install Ruby:</h3>
65
65
  <p>
66
66
  If you have Git command, clone <a href='https://github.com/yhara/dxopal-starter-kit'>yhara/dxopal-starter-kit</a>.
@@ -72,6 +72,7 @@ $ dxopal server</code></pre>
72
72
  <p>
73
73
  Then edit main.rb and reload the browser tab.
74
74
  </p>
75
+ -->
75
76
 
76
77
  <h2>Resources</h2>
77
78
  <ul>
@@ -49,9 +49,8 @@
49
49
  <h3>Rubyがインストール済みのとき</h3>
50
50
  <p>
51
51
  <pre><code>$ gem install dxopal
52
- $ mkdir game1
52
+ $ dxopal new game1
53
53
  $ cd game1
54
- $ dxopal init
55
54
  $ dxopal server</code></pre>
56
55
  </p>
57
56
  <p>
@@ -61,6 +60,7 @@ $ dxopal server</code></pre>
61
60
  main.rbを編集してブラウザをリロードすると動くはずです。
62
61
  </p>
63
62
 
63
+ <!--
64
64
  <h3>Rubyをインストールしたくないとき</h3>
65
65
  <p>
66
66
  Gitコマンドが使える場合は<a href='https://github.com/yhara/dxopal-starter-kit'>yhara/dxopal-starter-kit</a>をgit cloneしてください。そうでない場合は<a href='https://github.com/yhara/dxopal-starter-kit/releases'>releases</a>から最新のzipをダウンロードして展開してください。
@@ -71,6 +71,7 @@ $ dxopal server</code></pre>
71
71
  <p>
72
72
  main.rbを編集してブラウザをリロードすると動くはずです。
73
73
  </p>
74
+ -->
74
75
 
75
76
  <h2>リンク</h2>
76
77
  <ul>
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require_relative 'opal/dxopal/version.rb'
4
+ require_relative 'lib/dxopal/version.rb'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "dxopal"
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_runtime_dependency "thor", "~> 0.19.1"
26
+ spec.add_runtime_dependency "thor", "~> 0.20"
27
27
  spec.add_runtime_dependency "rack", "~> 2.0"
28
28
  end
data/exe/dxopal CHANGED
@@ -2,12 +2,24 @@
2
2
  require 'fileutils'
3
3
  require 'rack'
4
4
  require 'thor'
5
- require_relative '../opal/dxopal/version' # Import DXOpal::VERSION
5
+ require_relative '../lib/dxopal/version' # Import DXOpal::VERSION
6
6
 
7
7
  module DXOpal
8
8
  class Cli < Thor
9
9
  GEM_ROOT = "#{__dir__}/../"
10
10
 
11
+ desc "new APP_PATH", "Create a DXOpal project"
12
+ def new(app_path)
13
+ if File.exist?(app_path)
14
+ puts "Already exists: #{app_path}"
15
+ return
16
+ end
17
+ FileUtils.mkdir_p(app_path)
18
+ Dir.chdir(app_path) do
19
+ init
20
+ end
21
+ end
22
+
11
23
  desc "init", "Copy template files into this directory"
12
24
  def init
13
25
  FileUtils.cp("#{GEM_ROOT}/template/index.html", Dir.pwd)
@@ -26,6 +26,7 @@ require 'time'
26
26
 
27
27
  # Patches
28
28
  require 'dxopal/patches/require_remote'
29
+ require 'dxopal/patches/require_dxopal'
29
30
 
30
31
  module DXOpal
31
32
  include DXOpal::Constants::Colors
File without changes
@@ -14,6 +14,11 @@ module DXOpal
14
14
  def size; @size; end
15
15
  def fontname; @orig_fontname; end
16
16
 
17
+ def get_width(string)
18
+ canvas = Native(`document.getElementById('dxopal-canvas')`)
19
+ canvas.getContext('2d').measureText(string).width
20
+ end
21
+
17
22
  # Return a string like "48px serif"
18
23
  def _spec_str
19
24
  "#{@size}px #{@fontname}"
@@ -28,6 +28,37 @@ module DXOpal
28
28
  return img, img_promise
29
29
  end
30
30
 
31
+ attr_accessor :promise, :loaded
32
+ def loaded?; loaded; end
33
+
34
+ def self.load(path_or_url)
35
+ return new(1, 1).load(path_or_url)
36
+ end
37
+
38
+ def load(path_or_url)
39
+ raw_img = `new Image()`
40
+ @promise = %x{
41
+ new Promise(function(resolve, reject) {
42
+ raw_img.onload = function() {
43
+ self.$_resize(raw_img.width, raw_img.height);
44
+ self.$_draw_raw_image(0, 0, raw_img);
45
+ self.loaded = #{true};
46
+ resolve();
47
+ };
48
+ raw_img.src = path_or_url;
49
+ });
50
+ }
51
+ return self
52
+ end
53
+
54
+ def onload(&block)
55
+ %x{
56
+ #{@promise}.then(function(response){
57
+ #{block.call()}
58
+ });
59
+ }
60
+ end
61
+
31
62
  # Create an instance of Image
32
63
  def initialize(width, height, color=C_DEFAULT, canvas: nil)
33
64
  @width, @height = width, height
@@ -153,8 +184,8 @@ module DXOpal
153
184
  %x{
154
185
  ctx.beginPath();
155
186
  ctx.strokeStyle = #{_rgba(color)};
156
- ctx.moveTo(x1, y1);
157
- ctx.lineTo(x2, y2);
187
+ ctx.moveTo(x1+0.5, y1+0.5);
188
+ ctx.lineTo(x2+0.5, y2+0.5);
158
189
  ctx.stroke();
159
190
  }
160
191
  return self
@@ -166,7 +197,7 @@ module DXOpal
166
197
  %x{
167
198
  ctx.beginPath();
168
199
  ctx.strokeStyle = #{_rgba(color)};
169
- ctx.rect(x1, y1, x2-x1+1, y2-y1+1);
200
+ ctx.rect(x1+0.5, y1+0.5, x2-x1, y2-y1);
170
201
  ctx.stroke();
171
202
  }
172
203
  return self
@@ -178,7 +209,7 @@ module DXOpal
178
209
  %x{
179
210
  ctx.beginPath();
180
211
  ctx.fillStyle = #{_rgba(color)};
181
- ctx.fillRect(x1, y1, x2-x1+1, y2-y1+1);
212
+ ctx.fillRect(x1, y1, x2-x1, y2-y1);
182
213
  }
183
214
  return self
184
215
  end
@@ -189,7 +220,7 @@ module DXOpal
189
220
  %x{
190
221
  ctx.beginPath();
191
222
  ctx.strokeStyle = #{_rgba(color)};
192
- ctx.arc(x, y, r, 0, Math.PI*2, false)
223
+ ctx.arc(x+0.5, y+0.5, r, 0, Math.PI*2, false)
193
224
  ctx.stroke();
194
225
  }
195
226
  return self
@@ -213,10 +244,10 @@ module DXOpal
213
244
  %x{
214
245
  ctx.beginPath();
215
246
  ctx.strokeStyle = #{_rgba(color)};
216
- ctx.moveTo(x1, y1);
217
- ctx.lineTo(x2, y2);
218
- ctx.lineTo(x3, y3);
219
- ctx.lineTo(x1, y1);
247
+ ctx.moveTo(x1+0.5, y1+0.5);
248
+ ctx.lineTo(x2+0.5, y2+0.5);
249
+ ctx.lineTo(x3+0.5, y3+0.5);
250
+ ctx.lineTo(x1+0.5, y1+0.5);
220
251
  ctx.stroke();
221
252
  }
222
253
  return self
@@ -17,12 +17,15 @@ module DXOpal
17
17
  @@pressing_keys = `new Object()`
18
18
  @@mouse_info = `{x: 0, y: 0}`
19
19
  @@pressing_mouse_buttons = `new Object()`
20
+ @@touch_info = `{x: 0, y: 0}`
21
+ @@pressing_touch = `new Object()`
20
22
 
21
23
  rect = `canvas.getBoundingClientRect()`
22
24
  @@canvas_x = `rect.left + window.pageXOffset`
23
25
  @@canvas_y = `rect.top + window.pageYOffset`
24
26
 
25
27
  self._init_mouse_events
28
+ self._init_touch_events
26
29
  self.keyevent_target = `window` unless Input.keyevent_target
27
30
  end
28
31
 
@@ -166,5 +169,57 @@ module DXOpal
166
169
  def self.mouse_release?(mouse_code)
167
170
  return `#{@@pressing_mouse_buttons}[mouse_code] == -(#{@@tick}-1)`
168
171
  end
172
+
173
+ #
174
+ # Touch
175
+ #
176
+
177
+ # (internal) initialize touch events
178
+ def self._init_touch_events
179
+ %x{
180
+ document.addEventListener('touchmove', function(ev){
181
+ #{@@touch_info}.x = ev.changedTouches[0].pageX - #{@@canvas_x};
182
+ #{@@touch_info}.y = ev.changedTouches[0].pageY - #{@@canvas_y};
183
+ });
184
+ document.addEventListener('touchstart', function(ev){
185
+ #{@@touch_info}.x = ev.changedTouches[0].pageX - #{@@canvas_x};
186
+ #{@@touch_info}.y = ev.changedTouches[0].pageY - #{@@canvas_y};
187
+ #{@@pressing_touch}[0] = #{@@tick};
188
+ });
189
+ document.addEventListener('touchend', function(ev){
190
+ #{@@touch_info}.x = ev.changedTouches[0].pageX - #{@@canvas_x};
191
+ #{@@touch_info}.y = ev.changedTouches[0].pageY - #{@@canvas_y};
192
+ #{@@pressing_touch}[0] = -#{@@tick};
193
+ });
194
+ }
195
+ end
196
+
197
+ # Return position of touch
198
+ # (0, 0) is the top-left corner of the canvas
199
+ def self.touch_x
200
+ return `#{@@touch_info}.x`
201
+ end
202
+ def self.touch_y
203
+ return `#{@@touch_info}.y`
204
+ end
205
+ class << self
206
+ alias touch_pos_x touch_x
207
+ alias touch_pos_y touch_y
208
+ end
209
+
210
+ # Return true if the touch is being pressed
211
+ def self.touch_down?
212
+ return `#{@@pressing_touch}[0] > 0`
213
+ end
214
+
215
+ # Return true if the touch is pressed in the last tick
216
+ def self.touch_push?
217
+ return `#{@@pressing_touch}[0] == -(#{@@tick}-1)`
218
+ end
219
+
220
+ # Return true if the touch is released in the last tick
221
+ def self.touch_release?
222
+ return `#{@@pressing_touch}[0] == -(#{@@tick}-1)`
223
+ end
169
224
  end
170
225
  end
@@ -3,9 +3,7 @@ module DXOpal
3
3
  # List of key codes (event.code)
4
4
  # https://developer.mozilla.org/ja/docs/Web/API/KeyboardEvent
5
5
  module KeyCodes
6
- # TODO: add more keycodes (pull request welcome)
7
- # especially keypads and us-keyboards
8
-
6
+ # TODO: add event.code for those commented out (pull request welcome)
9
7
  K_ESCAPE = 'Escape'
10
8
  K_1 = 'Digit1'
11
9
  K_2 = 'Digit2'
@@ -47,7 +45,7 @@ module DXOpal
47
45
  K_L = 'KeyL'
48
46
  K_SEMICOLON = 'Semicolon'
49
47
  K_APOSTROPHE = 'Quote' # '
50
- #K_GRAVE = "`"
48
+ K_GRAVE = "Backquote" # `
51
49
  K_LSHIFT = 'ShiftLeft'
52
50
  K_BACKSLASH = 'BackSlash' # Note: different to K_YEN
53
51
  K_Z = 'KeyZ'
@@ -61,45 +59,45 @@ module DXOpal
61
59
  K_PERIOD = 'Period'
62
60
  K_SLASH = 'Slash'
63
61
  K_RSHIFT = 'ShiftRight'
64
- #K_MULTIPLY = "*"
62
+ K_MULTIPLY = "NumpadMultiply"
65
63
  #K_LMENU Alt
66
64
  K_SPACE = 'Space'
67
65
  #K_CAPITAL
68
- K_F1 = 112
69
- K_F2 = 113
70
- K_F3 = 114
71
- K_F4 = 115
72
- K_F5 = 116
73
- K_F6 = 117
74
- K_F7 = 118
75
- K_F8 = 119
76
- K_F9 = 120
77
- K_F10 = 121
78
- #K_NUMLOCK = "NumLock"
79
- #K_SCROLL = "ScrollLock"
80
- #K_NUMPAD7 7 *3
81
- #K_NUMPAD8 8 *3
82
- #K_NUMPAD9 9 *3
83
- #K_SUBTRACT - *3
84
- #K_NUMPAD4 4 *3
85
- #K_NUMPAD5 5 *3
86
- #K_NUMPAD6 6 *3
87
- #K_ADD + *3
88
- #K_NUMPAD1 1 *3
89
- #K_NUMPAD2 2 *3
90
- #K_NUMPAD3 3 *3
91
- #K_NUMPAD0 0 *3
92
- #K_DECIMAL . *3
66
+ K_F1 = "F1"
67
+ K_F2 = "F2"
68
+ K_F3 = "F3"
69
+ K_F4 = "F4"
70
+ K_F5 = "F5"
71
+ K_F6 = "F6"
72
+ K_F7 = "F7"
73
+ K_F8 = "F8"
74
+ K_F9 = "F9"
75
+ K_F10 = "F10"
76
+ K_NUMLOCK = "NumLock"
77
+ K_SCROLL = "ScrollLock"
78
+ K_NUMPAD7 = "Numpad7"
79
+ K_NUMPAD8 = "Numpad8"
80
+ K_NUMPAD9 = "Numpad9"
81
+ K_SUBTRACT = "NumpadSubtract"
82
+ K_NUMPAD4 = "Numpad4"
83
+ K_NUMPAD5 = "Numpad5"
84
+ K_NUMPAD6 = "Numpad6"
85
+ K_ADD = "NumpadAdd"
86
+ K_NUMPAD1 = "Numpad1"
87
+ K_NUMPAD2 = "Numpad2"
88
+ K_NUMPAD3 = "Numpad3"
89
+ K_NUMPAD0 = "Numpad0"
90
+ K_DECIMAL = "NumpadDecimal"
93
91
  #K_OEM_102
94
- K_F11 = 122
95
- K_F12 = 123
96
- K_F13 = 124
97
- K_F14 = 125
98
- K_F15 = 126
99
- #K_KANA
92
+ K_F11 = "F11"
93
+ K_F12 = "F12"
94
+ K_F13 = "F13"
95
+ K_F14 = "F14"
96
+ K_F15 = "F15"
97
+ K_KANA = "KanaMode"
100
98
  #K_ABNT_C1
101
- #K_CONVERT
102
- #K_NOCONVERT
99
+ K_CONVERT = "Convert"
100
+ K_NOCONVERT = "NonConvert"
103
101
  K_YEN = 'IntlYen'
104
102
  #K_ABNT_C2
105
103
  #K_NUMPADEQUALS = *3 *1
@@ -112,60 +110,60 @@ module DXOpal
112
110
  #K_AX
113
111
  #K_UNLABELED
114
112
  #K_NEXTTRACK
115
- #K_NUMPADENTER Enter *3
113
+ K_NUMPADENTER = "NumpadEnter"
116
114
  K_RCONTROL = 'ControlRight'
117
- #K_MUTE
115
+ K_MUTE = "VolumeMute"
118
116
  #K_CALCULATOR
119
117
  #K_PLAYPAUSE
120
118
  #K_MEDIASTOP
121
- #K_VOLUMEDOWN
122
- #K_VOLUMEUP
123
- #K_WEBHOME
119
+ K_VOLUMEDOWN = "VolumeDown"
120
+ K_VOLUMEUP = "VolumeUp"
121
+ K_WEBHOME = "BrowserHome"
124
122
  #K_NUMPADCOMMA , *3 *1
125
- #K_DIVIDE / *3
123
+ K_DIVIDE = "NumpadDivide"
126
124
  #K_SYSRQ
127
125
  #K_RMENU Alt
128
- #K_PAUSE = "Pause"
129
- #K_HOME "Home"
126
+ K_PAUSE = "Pause"
127
+ K_HOME = "Home"
130
128
  K_UP = 'ArrowUp'
131
129
  #K_PRIOR
132
130
  K_LEFT = 'ArrowLeft'
133
131
  K_RIGHT = 'ArrowRight'
134
- #K_END = "End"
132
+ K_END = "End"
135
133
  K_DOWN = 'ArrowDown'
136
134
  #K_NEXT
137
- #K_INSERT = "Insert"
138
- #K_DELETE = "Delete"
139
- #K_LWIN Windows
140
- #K_RWIN Windows
135
+ K_INSERT = "Insert"
136
+ K_DELETE = "Delete"
137
+ #K_LWIN
138
+ #K_RWIN
141
139
  #K_APPS
142
140
  #K_POWER
143
141
  #K_SLEEP
144
142
  #K_WAKE
145
- #K_WEBSEARCH
146
- #K_WEBFAVORITES
147
- #K_WEBREFRESH
148
- #K_WEBSTOP
149
- #K_WEBFORWARD
150
- #K_WEBBACK
143
+ K_WEBSEARCH = "BrowserSearch"
144
+ K_WEBFAVORITES = "BrowserFavorites"
145
+ K_WEBREFRESH = "BrowserRefresh"
146
+ K_WEBSTOP = "BrowserStop"
147
+ K_WEBFORWARD = "BrowserForward"
148
+ K_WEBBACK = "BrowserBack"
151
149
  #K_MYCOMPUTER
152
150
  #K_MAIL
153
151
  #K_MEDIASELECT
154
152
  K_BACKSPACE = 'Backspace'
155
- #K_NUMPADSTAR * *3
156
- #K_LALT Alt
153
+ K_NUMPADSTAR = "NumpadMultiply"
154
+ K_LALT = "AltLeft"
157
155
  K_CAPSLOCK = 'CapsLock'
158
- #K_NUMPADMINUS - *3
159
- #K_NUMPADPLUS + *3
160
- #K_NUMPADPERIOD . *3
161
- #K_NUMPADSLASH / *3
162
- #K_RALT Alt
156
+ K_NUMPADMINUS = "NumpadSubtract"
157
+ K_NUMPADPLUS = "NumpadAdd"
158
+ K_NUMPADPERIOD = "NumpadDecimal"
159
+ K_NUMPADSLASH = "NumpadDivide"
160
+ K_RALT = "AltRight"
163
161
  K_UPARROW = 'ArrowUp'
164
- #K_PGUP = "PageUp"
162
+ K_PGUP = "PageUp"
165
163
  K_LEFTARROW = 'ArrowLeft'
166
164
  K_RIGHTARROW = 'ArrowRight'
167
165
  K_DOWNARROW = 'ArrowDown'
168
- #K_PGDN = "PageDown"
166
+ K_PGDN = "PageDown"
169
167
  end
170
168
  end
171
169
  end