From f69598768e9a3002d9e7c2acbed109016fac6ae9 Mon Sep 17 00:00:00 2001 From: Tom Black Date: Fri, 19 May 2017 22:24:02 -0400 Subject: Check if audio file exists for `Sound` and `Music` --- lib/ruby2d/music.rb | 8 +++++++- lib/ruby2d/sound.rb | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/ruby2d/music.rb b/lib/ruby2d/music.rb index 410c82f..e0fdf11 100644 --- a/lib/ruby2d/music.rb +++ b/lib/ruby2d/music.rb @@ -7,7 +7,13 @@ module Ruby2D attr_reader :path def initialize(path) - # TODO: Check if file exists + + unless RUBY_ENGINE == 'opal' + unless File.exists? path + raise Error, "Cannot find audio file `#{path}`" + end + end + init(path) @path = path @loop = false diff --git a/lib/ruby2d/sound.rb b/lib/ruby2d/sound.rb index 1049eee..4e0c385 100644 --- a/lib/ruby2d/sound.rb +++ b/lib/ruby2d/sound.rb @@ -7,7 +7,13 @@ module Ruby2D attr_reader :path def initialize(path) - # TODO: Check if file exists + + unless RUBY_ENGINE == 'opal' + unless File.exists? path + raise Error, "Cannot find audio file `#{path}`" + end + end + init(path) @path = path end -- cgit v1.2.3