Sha256: 9ad968487a3d9a0a8bd2748cb913ecc71fe7e5cecbf89a4b6dcbb0812d369f9d

Contents?: true

Size: 591 Bytes

Versions: 2

Compression:

Stored size: 591 Bytes

Contents

module Sound
  class << self
    @@sounds = {}

    def play(sound_name)
      locate_sound(sound_name).play
    end

    def locate_sound(sound_name)
      return @@sounds[sound_name] if @@sounds[sound_name]

      puts "Initialize Sound: '#{sound_name}'"

      base_path = "#{Dir.pwd}/sounds"
      file_name = Dir.entries(base_path).find { |e| e.start_with?("#{sound_name}.") }

      raise "Sound file not found with name '#{sound_name}'" if file_name.nil?

      @@sounds[sound_name] = Gosu::Sample.new("#{base_path}/#{file_name}")

      return @@sounds[sound_name]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fantasy-0.1.3 lib/fantasy/sound.rb
fantasy-0.1.1 lib/fantasy/sound.rb