ruby2d 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/assets/README.md +8 -0
  3. data/assets/ios/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
  4. data/assets/ios/Assets.xcassets/Contents.json +6 -0
  5. data/assets/ios/Base.lproj/LaunchScreen.storyboard +27 -0
  6. data/assets/ios/Info.plist +43 -0
  7. data/assets/ios/MRuby.framework/Headers/mrbconf.h +145 -0
  8. data/assets/ios/MRuby.framework/Headers/mruby.h +1279 -0
  9. data/assets/ios/MRuby.framework/Headers/mruby/array.h +279 -0
  10. data/assets/ios/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
  11. data/assets/ios/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
  12. data/assets/ios/MRuby.framework/Headers/mruby/boxing_word.h +136 -0
  13. data/assets/ios/MRuby.framework/Headers/mruby/class.h +94 -0
  14. data/assets/ios/MRuby.framework/Headers/mruby/common.h +72 -0
  15. data/assets/ios/MRuby.framework/Headers/mruby/compile.h +194 -0
  16. data/assets/ios/MRuby.framework/Headers/mruby/data.h +75 -0
  17. data/assets/ios/MRuby.framework/Headers/mruby/debug.h +66 -0
  18. data/assets/ios/MRuby.framework/Headers/mruby/dump.h +196 -0
  19. data/assets/ios/MRuby.framework/Headers/mruby/error.h +75 -0
  20. data/assets/ios/MRuby.framework/Headers/mruby/gc.h +91 -0
  21. data/assets/ios/MRuby.framework/Headers/mruby/hash.h +182 -0
  22. data/assets/ios/MRuby.framework/Headers/mruby/irep.h +62 -0
  23. data/assets/ios/MRuby.framework/Headers/mruby/istruct.h +47 -0
  24. data/assets/ios/MRuby.framework/Headers/mruby/khash.h +274 -0
  25. data/assets/ios/MRuby.framework/Headers/mruby/numeric.h +161 -0
  26. data/assets/ios/MRuby.framework/Headers/mruby/object.h +45 -0
  27. data/assets/ios/MRuby.framework/Headers/mruby/opcode.h +161 -0
  28. data/assets/ios/MRuby.framework/Headers/mruby/proc.h +131 -0
  29. data/assets/ios/MRuby.framework/Headers/mruby/range.h +49 -0
  30. data/assets/ios/MRuby.framework/Headers/mruby/re.h +16 -0
  31. data/assets/ios/MRuby.framework/Headers/mruby/string.h +440 -0
  32. data/assets/ios/MRuby.framework/Headers/mruby/throw.h +55 -0
  33. data/assets/ios/MRuby.framework/Headers/mruby/value.h +309 -0
  34. data/assets/ios/MRuby.framework/Headers/mruby/variable.h +138 -0
  35. data/assets/ios/MRuby.framework/Headers/mruby/version.h +110 -0
  36. data/assets/ios/MRuby.framework/Info.plist +20 -0
  37. data/assets/ios/MRuby.framework/MRuby +0 -0
  38. data/assets/ios/MyApp.xcodeproj/project.pbxproj +362 -0
  39. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  40. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
  41. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcuserdata/Tom.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  42. data/assets/ios/MyApp.xcodeproj/xcuserdata/Tom.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  43. data/assets/ios/main.c +1 -0
  44. data/assets/opal.js +8434 -6329
  45. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +12 -0
  46. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json +6 -0
  47. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json +17 -0
  48. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +12 -0
  49. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json +6 -0
  50. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +12 -0
  51. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json +6 -0
  52. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +12 -0
  53. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json +6 -0
  54. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json +17 -0
  55. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +12 -0
  56. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json +6 -0
  57. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +12 -0
  58. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json +6 -0
  59. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json +32 -0
  60. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json +12 -0
  61. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json +12 -0
  62. data/assets/tvos/Assets.xcassets/Contents.json +6 -0
  63. data/assets/tvos/Assets.xcassets/LaunchImage.launchimage/Contents.json +15 -0
  64. data/assets/tvos/Info.plist +30 -0
  65. data/assets/tvos/MRuby.framework/Headers/mrbconf.h +145 -0
  66. data/assets/tvos/MRuby.framework/Headers/mruby.h +1279 -0
  67. data/assets/tvos/MRuby.framework/Headers/mruby/array.h +279 -0
  68. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
  69. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
  70. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_word.h +136 -0
  71. data/assets/tvos/MRuby.framework/Headers/mruby/class.h +94 -0
  72. data/assets/tvos/MRuby.framework/Headers/mruby/common.h +72 -0
  73. data/assets/tvos/MRuby.framework/Headers/mruby/compile.h +194 -0
  74. data/assets/tvos/MRuby.framework/Headers/mruby/data.h +75 -0
  75. data/assets/tvos/MRuby.framework/Headers/mruby/debug.h +66 -0
  76. data/assets/tvos/MRuby.framework/Headers/mruby/dump.h +196 -0
  77. data/assets/tvos/MRuby.framework/Headers/mruby/error.h +75 -0
  78. data/assets/tvos/MRuby.framework/Headers/mruby/gc.h +91 -0
  79. data/assets/tvos/MRuby.framework/Headers/mruby/hash.h +182 -0
  80. data/assets/tvos/MRuby.framework/Headers/mruby/irep.h +62 -0
  81. data/assets/tvos/MRuby.framework/Headers/mruby/istruct.h +47 -0
  82. data/assets/tvos/MRuby.framework/Headers/mruby/khash.h +274 -0
  83. data/assets/tvos/MRuby.framework/Headers/mruby/numeric.h +161 -0
  84. data/assets/tvos/MRuby.framework/Headers/mruby/object.h +45 -0
  85. data/assets/tvos/MRuby.framework/Headers/mruby/opcode.h +161 -0
  86. data/assets/tvos/MRuby.framework/Headers/mruby/proc.h +131 -0
  87. data/assets/tvos/MRuby.framework/Headers/mruby/range.h +49 -0
  88. data/assets/tvos/MRuby.framework/Headers/mruby/re.h +16 -0
  89. data/assets/tvos/MRuby.framework/Headers/mruby/string.h +440 -0
  90. data/assets/tvos/MRuby.framework/Headers/mruby/throw.h +55 -0
  91. data/assets/tvos/MRuby.framework/Headers/mruby/value.h +309 -0
  92. data/assets/tvos/MRuby.framework/Headers/mruby/variable.h +138 -0
  93. data/assets/tvos/MRuby.framework/Headers/mruby/version.h +110 -0
  94. data/assets/tvos/MRuby.framework/Info.plist +20 -0
  95. data/assets/tvos/MRuby.framework/MRuby +0 -0
  96. data/assets/tvos/MyApp.xcodeproj/project.pbxproj +344 -0
  97. data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  98. data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
  99. data/assets/tvos/main.c +1 -0
  100. data/bin/ruby2d +219 -64
  101. data/ext/ruby2d/extconf.rb +1 -1
  102. data/ext/ruby2d/ruby2d.c +117 -19
  103. data/lib/ruby2d/color.rb +1 -1
  104. data/lib/ruby2d/version.rb +1 -1
  105. data/lib/ruby2d/window.rb +16 -10
  106. metadata +102 -5
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "self:MyApp.xcodeproj">
6
+ </FileRef>
7
+ </Workspace>
@@ -0,0 +1,30 @@
1
+ {
2
+ "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "C1BCA8F4805490F8BF8CC1BE1EB3C264D4847762",
3
+ "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : {
4
+
5
+ },
6
+ "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
7
+ "B56F7D52CF2ADA04A9756A36E4DD34AF636EFA07" : 9223372036854775807,
8
+ "C1BCA8F4805490F8BF8CC1BE1EB3C264D4847762" : 9223372036854775807
9
+ },
10
+ "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "A80DF1FC-28C2-438B-80A2-328C4DF456FB",
11
+ "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
12
+ "B56F7D52CF2ADA04A9756A36E4DD34AF636EFA07" : "",
13
+ "C1BCA8F4805490F8BF8CC1BE1EB3C264D4847762" : "deps\/"
14
+ },
15
+ "DVTSourceControlWorkspaceBlueprintNameKey" : "MyApp",
16
+ "DVTSourceControlWorkspaceBlueprintVersion" : 204,
17
+ "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "xcode\/tvos\/MyApp.xcodeproj",
18
+ "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [
19
+ {
20
+ "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/simple2d\/simple2d.git",
21
+ "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
22
+ "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "B56F7D52CF2ADA04A9756A36E4DD34AF636EFA07"
23
+ },
24
+ {
25
+ "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/simple2d\/deps.git",
26
+ "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
27
+ "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "C1BCA8F4805490F8BF8CC1BE1EB3C264D4847762"
28
+ }
29
+ ]
30
+ }
@@ -0,0 +1 @@
1
+ // Your Ruby 2D app here
data/bin/ruby2d CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
6
6
  class String
7
7
  def colorize(c); "\e[#{c}m#{self}\e[0m" end
8
8
  def bold; colorize('1') end
9
- def error; colorize('4;31') end
9
+ def error; colorize('1;31') end
10
10
  end
11
11
 
12
12
  # The installed gem directory
@@ -32,11 +32,14 @@ end
32
32
  'music'
33
33
  ]
34
34
 
35
+ # Debugging command-line flag
36
+ @debug = false
37
+
35
38
 
36
39
  # Check if source file provided is good
37
40
  def check_build_src_file(rb_file)
38
41
  if !rb_file
39
- puts "Please provide a Ruby file to build."
42
+ puts "Please provide a Ruby file to build"
40
43
  exit
41
44
  elsif !File.exists? rb_file
42
45
  puts "Can't find file: #{rb_file}"
@@ -76,6 +79,7 @@ end
76
79
 
77
80
  # Build a native version of the provided Ruby application
78
81
  def build_native(rb_file)
82
+ check_build_src_file(rb_file)
79
83
 
80
84
  # Check if MRuby exists; if not, quit
81
85
  if `which mruby`.empty?
@@ -88,11 +92,7 @@ def build_native(rb_file)
88
92
  `mrbc -Bruby2d_lib -obuild/lib.c build/lib.rb`
89
93
 
90
94
  # Read the provided Ruby source file, copy to build dir and compile to bytecode
91
-
92
- File.open('build/src.rb', 'w') do |file|
93
- file << strip_require(rb_file)
94
- end
95
-
95
+ File.open('build/src.rb', 'w') { |file| file << strip_require(rb_file) }
96
96
  `mrbc -Bruby2d_app -obuild/src.c build/src.rb`
97
97
 
98
98
  # Combine contents of C source files and bytecode into one file
@@ -103,9 +103,12 @@ def build_native(rb_file)
103
103
  f << File.read("#{@gem_dir}/ext/ruby2d/ruby2d.c")
104
104
  end
105
105
 
106
- # Compile to native executable
106
+ # Compile to a native executable
107
107
  `cc build/app.c -lmruby \`simple2d --libs\` -o build/app`
108
108
 
109
+ # Clean up
110
+ clean_up unless @debug
111
+
109
112
  # Success!
110
113
  puts "Native app created at `build/app`"
111
114
  end
@@ -113,19 +116,15 @@ end
113
116
 
114
117
  # Build a web-based version of the provided Ruby application
115
118
  def build_web(rb_file)
119
+ check_build_src_file(rb_file)
116
120
 
117
121
  # Assemble the Ruby 2D library in one `.rb` file and compile to JS
118
122
  make_lib
119
123
  `opal --compile --no-opal build/lib.rb > build/lib.js`
120
124
 
121
125
  # Read the provided Ruby source file, copy to build dir, and compile to JS
122
-
123
- File.open('build/src.rb', 'w') do |file|
124
- file << strip_require(rb_file)
125
- end
126
-
126
+ File.open('build/src.rb', 'w') { |file| file << strip_require(rb_file) }
127
127
  `opal --compile --no-opal build/src.rb > build/src.js`
128
-
129
128
  FileUtils.cp "#{@gem_dir}/ext/ruby2d/ruby2d-opal.rb", "build/"
130
129
  `opal --compile --no-opal build/ruby2d-opal.rb > build/ruby2d-opal.js`
131
130
 
@@ -141,56 +140,127 @@ def build_web(rb_file)
141
140
  # Copy over HTML template
142
141
  FileUtils.cp "#{@gem_dir}/assets/template.html", "build/app.html"
143
142
 
143
+ # Clean up
144
+ clean_up unless @debug
145
+
144
146
  # Success!
145
147
  puts "Web app created at `build/app.js`",
146
148
  " Run by opening `build/app.html`"
147
149
  end
148
150
 
149
151
 
150
- # Build an application package for the current platform
151
- def build_package
152
- require 'fileutils'
153
-
154
- icon_path = "#{@gem_dir}/assets/app.icns"
155
-
156
- FileUtils.mkpath "build/App.app/Contents/MacOS"
157
- FileUtils.mkpath "build/App.app/Contents/Resources"
158
- FileUtils.cp icon_path, "build/App.app/Contents/Resources"
159
-
160
- info_plist = %(
161
- <?xml version="1.0" encoding="UTF-8"?>
162
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
163
- <plist version="1.0">
164
- <dict>
165
- <key>CFBundleExecutable</key>
166
- <string>app</string>
167
- <key>CFBundleIconFile</key>
168
- <string>app.icns</string>
169
- <key>CFBundleInfoDictionaryVersion</key>
170
- <string>1.0</string>
171
- <key>CFBundlePackageType</key>
172
- <string>APPL</string>
173
- <key>CFBundleSignature</key>
174
- <string>????</string>
175
- <key>CFBundleVersion</key>
176
- <string>1.0</string>
177
- </dict>
178
- </plist>
179
- )
180
-
181
- File.open("build/App.app/Contents/Info.plist", 'w') { |f| f.write(info_plist) }
182
- FileUtils.cp "build/app", "build/App.app/Contents/MacOS/"
183
- puts "App written to `build/App.app`."
152
+ # Build an iOS or tvOS app
153
+ def build_apple(rb_file, device)
154
+ check_build_src_file(rb_file)
155
+
156
+ # Check for Simple 2D framework,
157
+ unless File.exists?('/usr/local/Frameworks/Simple2D/iOS/Simple2D.framework') && File.exists?('/usr/local/Frameworks/Simple2D/tvOS/Simple2D.framework')
158
+ puts "#{'Error:'.error} Simple 2D iOS and tvOS frameworks not found. Install them and try again.\n"
159
+ exit
160
+ end
161
+
162
+ # Check if MRuby exists; if not, quit
163
+ if `which mruby`.empty?
164
+ puts "#{'Error:'.error} Can't find MRuby, which is needed to build native Ruby 2D applications.\n"
165
+ exit
166
+ end
167
+
168
+ # Assemble the Ruby 2D library in one `.rb` file and compile to bytecode
169
+ make_lib
170
+ `mrbc -Bruby2d_lib -obuild/lib.c build/lib.rb`
171
+
172
+ # Read the provided Ruby source file, copy to build dir and compile to bytecode
173
+ File.open('build/src.rb', 'w') { |file| file << strip_require(rb_file) }
174
+ `mrbc -Bruby2d_app -obuild/src.c build/src.rb`
175
+
176
+ # Copy over iOS project
177
+ FileUtils.cp_r "#{@gem_dir}/assets/#{device}", "build"
178
+
179
+ # Combine contents of C source files and bytecode into one file
180
+ File.open("build/#{device}/main.c", 'w') do |f|
181
+ f << "#define RUBY2D_IOS_TVOS 1" << "\n\n"
182
+ f << "#define MRUBY 1" << "\n\n"
183
+ f << File.read("build/lib.c") << "\n\n"
184
+ f << File.read("build/src.c") << "\n\n"
185
+ f << File.read("#{@gem_dir}/ext/ruby2d/ruby2d.c")
186
+ end
187
+
188
+ # Build the Xcode project
189
+ `simple2d build --#{device} build/#{device}/MyApp.xcodeproj`
190
+
191
+ # Clean up
192
+ clean_up unless @debug
193
+
194
+ # Success!
195
+ puts "App created at `build/#{device}`"
184
196
  end
185
197
 
186
198
 
187
199
  # Clean up unneeded build files
188
- def clean_up
200
+ def clean_up(cmd = nil)
189
201
  FileUtils.rm(
190
202
  Dir.glob('build/{src,lib}.{rb,c,js}') +
191
203
  Dir.glob('build/ruby2d-opal.{rb,js}') +
192
204
  Dir.glob('build/app.c')
193
205
  )
206
+ if cmd == :all
207
+ puts "cleaning up..."
208
+ FileUtils.rm_f 'build/app'
209
+ FileUtils.rm_f 'build/app.js'
210
+ FileUtils.rm_f 'build/app.html'
211
+ FileUtils.rm_rf 'build/ios'
212
+ FileUtils.rm_rf 'build/tvos'
213
+ end
214
+ end
215
+
216
+
217
+ # Launch a native app
218
+ def launch_native
219
+ if !File.exists? 'build/app'
220
+ puts "No native app built!"
221
+ exit
222
+ end
223
+ `( cd build && ./app )`
224
+ end
225
+
226
+
227
+ # Launch a web app
228
+ def launch_web
229
+ if !File.exists? 'build/app.html'
230
+ puts "No web app built!"
231
+ exit
232
+ end
233
+ open_cmd = 'open'
234
+ case RUBY_PLATFORM
235
+ when /linux/
236
+ open_cmd = "xdg-#{open_cmd}"
237
+ when /mingw/
238
+ open_cmd = "start"
239
+ end
240
+ system "#{open_cmd} build/app.html"
241
+ end
242
+
243
+
244
+ # Launch an iOS or tvOS app in a simulator
245
+ def launch_apple(device)
246
+ case device
247
+ when 'ios'
248
+ if !File.exists? 'build/ios/build/Release-iphonesimulator/MyApp.app'
249
+ puts "No iOS app built!"
250
+ exit
251
+ end
252
+ puts `simple2d simulator --open "iPhone 8" &&
253
+ simple2d simulator --install "build/ios/build/Release-iphonesimulator/MyApp.app" &&
254
+ simple2d simulator --launch "Ruby2D.MyApp"`
255
+ when 'tvos'
256
+ if !File.exists? 'build/tvos/build/Release-appletvsimulator/MyApp.app'
257
+ puts "No tvOS app built!"
258
+ exit
259
+ end
260
+ puts `simple2d simulator --open "Apple TV" &&
261
+ simple2d simulator --install "build/tvos/build/Release-appletvsimulator/MyApp.app" &&
262
+ simple2d simulator --launch "Ruby2D.MyApp"`
263
+ end
194
264
  end
195
265
 
196
266
 
@@ -201,31 +271,116 @@ Usage: ruby2d <command> <options>
201
271
  [-v|--version]
202
272
 
203
273
  Summary of commands and options:
204
- build Build the application both natively and for the web
205
- --native Build only native
206
- --web Build only web
207
- --debug Build native and web, keeping all intermediate files
208
- package Create application package for distribution (experimental)
274
+ build Build a Ruby source file
275
+ launch Launch a built Ruby 2D application
276
+ simulator Interact with iOS and tvOS simulators
209
277
  -v|--version Prints the installed version\n\n"
210
278
 
279
+ usage_build = "
280
+ Use the #{"build".bold} command to compile or build Ruby 2D apps.
281
+
282
+ To compile and create a native executable, use:
283
+ build --native <ruby_file>
284
+
285
+ To build for the web, creating a JavaScript and HTML package, use:
286
+ build --web <ruby_file>
287
+
288
+ To build an iOS or tvOS app, use the following:
289
+ build --ios <ruby_file>
290
+ build --tvos <ruby_file>
291
+
292
+ To build for every platform supported by the current system, use:
293
+ build --all <ruby_file>
294
+
295
+ To clean up the build directory, use:
296
+ build --clean
297
+
298
+ Add the #{"--debug".bold} option to print debugging info
299
+ and keep all intermediate files generated.\n\n"
300
+
301
+ usage_launch = "
302
+ Use the #{"launch".bold} command to run a Ruby 2D app that has been built.
303
+ Choose one of the following options to select the kind of app to run:
304
+
305
+ --native
306
+ --web
307
+ --ios
308
+ --tvos\n\n"
309
+
310
+ usage_simulator = "
311
+ Choose an option with the #{"simulator".bold} command:
312
+
313
+ --list List available devices
314
+ --booted Show currently booted devices
315
+
316
+ --open <device_name> Open a simulator device with a given device name
317
+
318
+ --install <app_file> Install an app on the booted simulator given the path
319
+ to the app e.g. \"Release-iphonesimulator/MyApp.app\"
320
+
321
+ --launch <bundle_id> Launch an app given the app bundle's identifier,
322
+ e.g. \"Ruby2D.MyApp\"
323
+
324
+ --log Stream log of the booted simulator
325
+ --log <app> Stream log for the app only, given the app name
326
+ --log-errors Stream log containing only error messages\n\n"
327
+
328
+ # puts ARGV.inspect
329
+
211
330
  case ARGV[0]
212
331
  when 'build'
213
- puts "Building..."
332
+ if ARGV.delete '--debug' then @debug = true end
214
333
  case ARGV[1]
215
334
  when '--native'
216
335
  build_native(ARGV[2])
217
336
  when '--web'
218
337
  build_web(ARGV[2])
338
+ when '--ios'
339
+ build_apple(ARGV[2], 'ios')
340
+ when '--tvos'
341
+ build_apple(ARGV[2], 'tvos')
342
+ when '--all'
343
+ build_native(ARGV[2])
344
+ build_web(ARGV[2])
345
+ build_apple(ARGV[2], 'ios')
346
+ build_apple(ARGV[2], 'tvos')
347
+ when '--clean'
348
+ clean_up(:all)
349
+ else
350
+ puts usage_build
351
+ end
352
+ when 'launch'
353
+ case ARGV[1]
354
+ when '--native'
355
+ launch_native
356
+ when '--web'
357
+ launch_web
358
+ when '--ios'
359
+ launch_apple('ios')
360
+ when '--tvos'
361
+ launch_apple('tvos')
219
362
  else
220
- if ARGV[2]; puts usage; exit end
221
- check_build_src_file(ARGV[1])
222
- build_native(ARGV[1])
223
- build_web(ARGV[1])
224
- end
225
- unless ARGV.include? '--debug'; clean_up end
226
- when 'package'
227
- puts "Running package..."
228
- build_package
363
+ puts usage_launch
364
+ end
365
+ when 'simulator'
366
+ case ARGV[1]
367
+ when '--list'
368
+ puts `simple2d simulator --list`
369
+ when '--booted'
370
+ puts `simple2d simulator --booted`
371
+ when '--open'
372
+ puts `simple2d simulator --open "#{ARGV[2]}"`
373
+ when '--install'
374
+ puts `simple2d simulator --install "#{ARGV[2]}"`
375
+ when '--launch'
376
+ puts `simple2d simulator --launch "#{ARGV[2]}"`
377
+ when '--log'
378
+ puts `simple2d simulator --log`
379
+ when '--log-errors'
380
+ puts `simple2d simulator --log-errors`
381
+ else
382
+ puts usage_simulator
383
+ end
229
384
  when '-v', '--version'
230
385
  puts Ruby2D::VERSION
231
386
  else
@@ -1,6 +1,6 @@
1
1
  require 'mkmf'
2
2
 
3
- S2D_VERSION = '0.7.0' # Simple 2D minimum version required
3
+ S2D_VERSION = '0.8.0' # Simple 2D minimum version required
4
4
  $errors = []
5
5
 
6
6
  class String
@@ -1,7 +1,11 @@
1
1
  // ruby2d.c – Native C extension for Ruby and MRuby
2
2
 
3
3
  // Simple 2D includes
4
- #include <simple2d.h>
4
+ #if RUBY2D_IOS_TVOS
5
+ #include <Simple2D/simple2d.h>
6
+ #else
7
+ #include <simple2d.h>
8
+ #endif
5
9
 
6
10
  // Ruby includes
7
11
  #if MRUBY
@@ -64,7 +68,7 @@
64
68
  #define r_args_none (MRB_ARGS_NONE())
65
69
  #define r_args_req(n) MRB_ARGS_REQ(n)
66
70
  // Helpers
67
- #define r_char_to_sym(str) mrb_check_intern_cstr(mrb, str)
71
+ #define r_char_to_sym(str) mrb_symbol_value(mrb_intern_cstr(mrb, str))
68
72
  #else
69
73
  // Ruby
70
74
  #define R_VAL VALUE
@@ -140,6 +144,14 @@ static void free_window() {
140
144
  }
141
145
 
142
146
 
147
+ /*
148
+ * Normalize controller axis values to 0.0...1.0
149
+ */
150
+ double normalize_controller_axis(int val) {
151
+ return val > 0 ? val / 32767.0 : val / 32768.0;
152
+ }
153
+
154
+
143
155
  /*
144
156
  * File#exists? for MRuby
145
157
  */
@@ -692,7 +704,7 @@ void on_mouse(S2D_Event e) {
692
704
  // type, direction, delta_x, delta_y
693
705
  type = r_char_to_sym("scroll");
694
706
  direction = e.direction == S2D_MOUSE_SCROLL_NORMAL ?
695
- r_str_new("normal") : r_str_new("inverted");
707
+ r_char_to_sym("normal") : r_char_to_sym("inverted");
696
708
  break;
697
709
  case S2D_MOUSE_MOVE:
698
710
  // type, x, y, delta_x, delta_y
@@ -703,26 +715,23 @@ void on_mouse(S2D_Event e) {
703
715
  if (e.type == S2D_MOUSE_DOWN || e.type == S2D_MOUSE_UP) {
704
716
  switch (e.button) {
705
717
  case S2D_MOUSE_LEFT:
706
- button = r_str_new("left");
718
+ button = r_char_to_sym("left");
707
719
  break;
708
720
  case S2D_MOUSE_MIDDLE:
709
- button = r_str_new("middle");
721
+ button = r_char_to_sym("middle");
710
722
  break;
711
723
  case S2D_MOUSE_RIGHT:
712
- button = r_str_new("right");
724
+ button = r_char_to_sym("right");
713
725
  break;
714
726
  case S2D_MOUSE_X1:
715
- button = r_str_new("x1");
727
+ button = r_char_to_sym("x1");
716
728
  break;
717
729
  case S2D_MOUSE_X2:
718
- button = r_str_new("x2");
730
+ button = r_char_to_sym("x2");
719
731
  break;
720
732
  }
721
733
  }
722
734
 
723
- // Bug in MRuby: If `button` or `direction` are symbols (created with
724
- // r_char_to_sym), they will always both be `nil`. Use `r_str_new` for now.
725
-
726
735
  r_funcall(
727
736
  ruby2d_window, "mouse_callback", 7, type, button, direction,
728
737
  INT2NUM(e.x), INT2NUM(e.y), INT2NUM(e.delta_x), INT2NUM(e.delta_y)
@@ -735,23 +744,93 @@ void on_mouse(S2D_Event e) {
735
744
  */
736
745
  static void on_controller(S2D_Event e) {
737
746
 
738
- R_VAL type = R_NIL;
747
+ R_VAL type = R_NIL; R_VAL axis = R_NIL; R_VAL button = R_NIL;
739
748
 
740
749
  switch (e.type) {
741
750
  case S2D_AXIS:
742
751
  type = r_char_to_sym("axis");
752
+ switch (e.axis) {
753
+ case S2D_AXIS_LEFTX:
754
+ axis = r_char_to_sym("left_x");
755
+ break;
756
+ case S2D_AXIS_LEFTY:
757
+ axis = r_char_to_sym("left_y");
758
+ break;
759
+ case S2D_AXIS_RIGHTX:
760
+ axis = r_char_to_sym("right_x");
761
+ break;
762
+ case S2D_AXIS_RIGHTY:
763
+ axis = r_char_to_sym("right_y");
764
+ break;
765
+ case S2D_AXIS_TRIGGERLEFT:
766
+ axis = r_char_to_sym("trigger_left");
767
+ break;
768
+ case S2D_AXIS_TRIGGERRIGHT:
769
+ axis = r_char_to_sym("trigger_right");
770
+ break;
771
+ case S2D_AXIS_INVALID:
772
+ axis = r_char_to_sym("invalid");
773
+ break;
774
+ }
743
775
  break;
744
- case S2D_BUTTON_DOWN:
745
- type = r_char_to_sym("button_down");
746
- break;
747
- case S2D_BUTTON_UP:
748
- type = r_char_to_sym("button_up");
776
+ case S2D_BUTTON_DOWN: case S2D_BUTTON_UP:
777
+ type = e.type == S2D_BUTTON_DOWN ? r_char_to_sym("button_down") : r_char_to_sym("button_up");
778
+ switch (e.button) {
779
+ case S2D_BUTTON_A:
780
+ button = r_char_to_sym("a");
781
+ break;
782
+ case S2D_BUTTON_B:
783
+ button = r_char_to_sym("b");
784
+ break;
785
+ case S2D_BUTTON_X:
786
+ button = r_char_to_sym("x");
787
+ break;
788
+ case S2D_BUTTON_Y:
789
+ button = r_char_to_sym("y");
790
+ break;
791
+ case S2D_BUTTON_BACK:
792
+ button = r_char_to_sym("back");
793
+ break;
794
+ case S2D_BUTTON_GUIDE:
795
+ button = r_char_to_sym("guide");
796
+ break;
797
+ case S2D_BUTTON_START:
798
+ button = r_char_to_sym("start");
799
+ break;
800
+ case S2D_BUTTON_LEFTSTICK:
801
+ button = r_char_to_sym("left_stick");
802
+ break;
803
+ case S2D_BUTTON_RIGHTSTICK:
804
+ button = r_char_to_sym("right_stick");
805
+ break;
806
+ case S2D_BUTTON_LEFTSHOULDER:
807
+ button = r_char_to_sym("left_shoulder");
808
+ break;
809
+ case S2D_BUTTON_RIGHTSHOULDER:
810
+ button = r_char_to_sym("right_shoulder");
811
+ break;
812
+ case S2D_BUTTON_DPAD_UP:
813
+ button = r_char_to_sym("up");
814
+ break;
815
+ case S2D_BUTTON_DPAD_DOWN:
816
+ button = r_char_to_sym("down");
817
+ break;
818
+ case S2D_BUTTON_DPAD_LEFT:
819
+ button = r_char_to_sym("left");
820
+ break;
821
+ case S2D_BUTTON_DPAD_RIGHT:
822
+ button = r_char_to_sym("right");
823
+ break;
824
+ case S2D_BUTTON_INVALID:
825
+ button = r_char_to_sym("invalid");
826
+ break;
827
+ }
749
828
  break;
750
829
  }
751
830
 
752
831
  r_funcall(
753
- ruby2d_window, "controller_callback", 5, INT2NUM(e.which), type,
754
- INT2NUM(e.axis), INT2NUM(e.value), INT2NUM(e.button)
832
+ ruby2d_window, "controller_callback", 5, INT2NUM(e.which),
833
+ type, axis, DBL2NUM(normalize_controller_axis(e.value)), button
755
834
  );
756
835
  }
757
836
 
@@ -800,6 +879,22 @@ static void render() {
800
879
  }
801
880
 
802
881
 
882
+ /*
883
+ * Ruby2D::Window#ext_get_display_dimensions
884
+ */
885
+ #if MRUBY
886
+ static R_VAL ruby2d_window_ext_get_display_dimensions(mrb_state* mrb, R_VAL self) {
887
+ #else
888
+ static R_VAL ruby2d_window_ext_get_display_dimensions(R_VAL self) {
889
+ #endif
890
+ int w; int h;
891
+ S2D_GetDisplayDimensions(&w, &h);
892
+ r_iv_set(self, "@display_width" , INT2NUM(w));
893
+ r_iv_set(self, "@display_height", INT2NUM(h));
894
+ return R_NIL;
895
+ }
896
+
897
+
803
898
  /*
804
899
  * Ruby2D::Window#ext_show
805
900
  */
@@ -977,6 +1072,9 @@ void Init_ruby2d() {
977
1072
  // Ruby2D::Window
978
1073
  R_CLASS ruby2d_window_class = r_define_class(ruby2d_module, "Window");
979
1074
 
1075
+ // Ruby2D::Window#ext_get_display_dimensions
1076
+ r_define_method(ruby2d_window_class, "ext_get_display_dimensions", ruby2d_window_ext_get_display_dimensions, r_args_none);
1077
+
980
1078
  // Ruby2D::Window#ext_show
981
1079
  r_define_method(ruby2d_window_class, "ext_show", ruby2d_window_ext_show, r_args_none);
982
1080