diff options
| author | Tom Black <[email protected]> | 2017-04-26 22:16:19 -0400 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2017-04-28 18:08:26 -0400 |
| commit | 8d39db97fd82e99015d31fa38436fea6c1530a87 (patch) | |
| tree | f5303da94a6986cc6d72371d125755eb3e282ad9 /lib | |
| parent | 10d9acbe39a6e649e8752c3d06d1157d43b6e73a (diff) | |
| download | ruby2d-8d39db97fd82e99015d31fa38436fea6c1530a87.tar.gz ruby2d-8d39db97fd82e99015d31fa38436fea6c1530a87.zip | |
Add `File.exists?` to MRuby
This also enables file checking to the `Image` class for MRI and MRuby
(on the web, a “failed to load resource” already appears). Also, all
exceptions will now be printed in MRuby, yay!
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ruby2d/exceptions.rb | 9 | ||||
| -rw-r--r-- | lib/ruby2d/image.rb | 11 |
2 files changed, 5 insertions, 15 deletions
diff --git a/lib/ruby2d/exceptions.rb b/lib/ruby2d/exceptions.rb index 84880e1..687ab11 100644 --- a/lib/ruby2d/exceptions.rb +++ b/lib/ruby2d/exceptions.rb @@ -2,14 +2,5 @@ module Ruby2D class Error < StandardError - def colorize(msg, c); "\e[#{c}m#{msg}\e[0m" end - def error(msg); colorize(msg, '4;31') end - def bold(msg); colorize(msg, '1') end - - def initialize(msg) - super(msg) - puts error("\nRuby 2D Error:") << " #{msg}" << - bold("\nOccurred in:\n #{caller.last}\n") - end end end diff --git a/lib/ruby2d/image.rb b/lib/ruby2d/image.rb index 7938bea..587a3c0 100644 --- a/lib/ruby2d/image.rb +++ b/lib/ruby2d/image.rb @@ -9,12 +9,11 @@ module Ruby2D def initialize(x, y, path) - # TODO: Check if file exists - # `File.exists?` is not available in MRuby - # Ideally would do: - # unless File.exists? path - # raise Error, "Cannot find image file `#{path}`" - # end + unless RUBY_ENGINE == 'opal' + unless File.exists? path + raise Error, "Cannot find image file `#{path}`" + end + end @type_id = 3 @x, @y, @path = x, y, path |
