Skip to content

Commit

Permalink
Remove current web backend
Browse files Browse the repository at this point in the history
Preparing for WebAssembly
  • Loading branch information
blacktm committed Dec 12, 2018
1 parent 80a2c9b commit 0f52b21
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 404 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -39,7 +39,7 @@ rake test:int testcard
# Build `test/audio.rb` natively using MRuby and run
rake test:native audio

# Build `test/mouse.rb` for the web using Opal and run in the default browser
# Build `test/mouse.rb` for the web using WebAssembly and run in the default browser
rake test:web mouse
```

Expand Down Expand Up @@ -67,7 +67,7 @@ Whether adding a feature or fixing a bug, try to do the following to ensure your

- **Check if there is an existing issue, and if not, open a new one to start a discussion.** Before dedicating time and energy to an idea or fix, let's make sure it's consistent with the principles and goals of the project, and that we have a solid strategy in place to implement and test.

- **Use a subset of Ruby that works everywhere.** Ruby 2D applications are, of course, written in Ruby. Some users may choose to harness the full power of the language, standard library, and ecosystem of gems by writing interpreted apps targeting the standard implementation, [MRI](https://en.wikipedia.org/wiki/Ruby_MRI). Others may want to target the web via [Opal](http://opalrb.org), so their app can be run in any browser. And others still may want to compile their app to native code via [MRuby](http://mruby.org), so they can embed it on platforms like the [Raspberry Pi](https://www.raspberrypi.org), or run it on mobile platforms like iOS and Android, or on the big screen with Apple TV or Amazon Fire TV. Or even further, some may want to do all three! Ruby 2D aims to support all of these use cases, even with the same app codebase. Your code contribution to this gem has to support a subset of Ruby that is compatible and behaves similarly across MRI, MRuby, and Opal. Beyond reading the documentation for each Ruby implementation, you can also try out code snippets on the command line using their respective REPLs: `irb` (MRI), `mirb` (MRuby), and `opal-repl` (Opal).
- **Use a subset of Ruby that works everywhere.** Ruby 2D applications are, of course, written in Ruby. Some users may choose to harness the full power of the language, standard library, and ecosystem of gems by writing interpreted apps targeting the standard implementation, [MRI](https://en.wikipedia.org/wiki/Ruby_MRI). Others may want to target the web via [WebAssembly](https://webassembly.org), mobile devices, or build native desktop applications, all which make use of a different Ruby implementation called [MRuby](http://mruby.org). Ruby 2D aims to support all of these use cases, even with the same app codebase. Your contribution must support a subset of Ruby that is compatible with and behaves similarly across MRI and MRuby. Beyond reading the documentation for each Ruby implementation, you can also try out code snippets on the command line using their respective REPLs: `irb` for MRI, and `mirb` for MRuby.

- **Comprehensively test your change.** Unlike other Ruby libraries, not everything here can be easily covered with unit tests alone. We also need to make sure things look and sound right, inputs work as expected, and behavior is consistent across all [platforms Ruby 2D supports](http://www.ruby2d.com/platforms).

Expand Down
33 changes: 0 additions & 33 deletions bin/ruby2d
Expand Up @@ -115,38 +115,6 @@ end
# Build a web-based version of the provided Ruby application
def build_web(rb_file)
puts "Warning: ".warn + "This feature is currently disabled while it's being upgraded."
return

check_build_src_file(rb_file)

# Assemble the Ruby 2D library in one `.rb` file and compile to JS
make_lib
`opal --compile --no-opal build/lib.rb > build/lib.js`

# Read the provided Ruby source file, copy to build dir, and compile to JS
File.open('build/src.rb', 'w') { |file| file << strip_require(rb_file) }
`opal --compile --no-opal build/src.rb > build/src.js`
FileUtils.cp "#{@gem_dir}/ext/ruby2d/ruby2d-opal.rb", "build/"
`opal --compile --no-opal build/ruby2d-opal.rb > build/ruby2d-opal.js`

# Combine contents of JS source files and compiled JS into one file
open('build/app.js', 'w') do |f|
f << File.read("#{@gem_dir}/assets/simple2d.js") << "\n\n"
f << File.read("#{@gem_dir}/assets/opal.js") << "\n\n"
f << File.read("build/lib.js") << "\n\n"
f << File.read("build/ruby2d-opal.js") << "\n\n"
f << File.read("build/src.js") << "\n\n"
end

# Copy over HTML template
FileUtils.cp "#{@gem_dir}/assets/template.html", "build/app.html"

# Clean up
clean_up unless @debug

# Success!
puts "Web app created at `build/app.js`",
" Run by opening `build/app.html`"
end


Expand Down Expand Up @@ -204,7 +172,6 @@ end
def clean_up(cmd = nil)
FileUtils.rm(
Dir.glob('build/{src,lib}.{rb,c,js}') +
Dir.glob('build/ruby2d-opal.{rb,js}') +
Dir.glob('build/app.c')
)
if cmd == :all
Expand Down
289 changes: 0 additions & 289 deletions ext/ruby2d/ruby2d-opal.rb

This file was deleted.

11 changes: 3 additions & 8 deletions lib/ruby2d/image.rb
Expand Up @@ -8,22 +8,17 @@ class Image
attr_accessor :x, :y, :width, :height, :rotate, :data

def initialize(path, opts = {})
@path = path

unless RUBY_ENGINE == 'opal'
unless File.exist? @path
raise Error, "Cannot find image file `#{@path}`"
end
unless File.exist? path
raise Error, "Cannot find image file `#{path}`"
end

@path = path
@x = opts[:x] || 0
@y = opts[:y] || 0
@z = opts[:z] || 0
@width = opts[:width] || nil
@height = opts[:height] || nil
@rotate = opts[:rotate] || 0
self.color = opts[:color] || 'white'

ext_init(@path)
add
end
Expand Down
8 changes: 2 additions & 6 deletions lib/ruby2d/music.rb
Expand Up @@ -7,13 +7,9 @@ class Music
attr_accessor :loop, :data

def initialize(path)

unless RUBY_ENGINE == 'opal'
unless File.exist? path
raise Error, "Cannot find audio file `#{path}`"
end
unless File.exist? path
raise Error, "Cannot find audio file `#{path}`"
end

@path = path
@loop = false
ext_init(path)
Expand Down

0 comments on commit 0f52b21

Please sign in to comment.