Class: AdventureRL::Audio

Inherits:
FileGroup show all
Defined in:
lib/AdventureRL/Audio.rb

Constant Summary collapse

AUDIO_FILENAME_REGEX =
/\A\d+\.(flac|wav|ogg)\z/i
INTERNAL_DEFAULT_SETTINGS =
Settings.new({
  name:      :audio_name,
  directory: nil,
  fps:       24,
  volume:    1.0
})
@@default_settings =
nil
@@root_directory =
Pathname.new($0).dirname

Constants included from Helpers::Error

Helpers::Error::PADDING, Helpers::Error::STACK_TRACE_PADDING, Helpers::Error::STACK_TRACE_SIZE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FileGroup

#get_file, #get_file_directory, #get_files, #get_name, #get_settings, #has_file_index?

Methods included from Helpers::Error

directory_exists?, error, error_no_directory, error_no_file, file_exists?

Constructor Details

#initialize(settings) ⇒ Audio

Initialize with either a path to a YAML settings file as a String, or a Hash containing your settings.



58
59
60
# File 'lib/AdventureRL/Audio.rb', line 58

def initialize settings
  super
end

Class Method Details

.get_root_directoryObject Also known as: root

Returns the currently set root audio files directory.



25
26
27
# File 'lib/AdventureRL/Audio.rb', line 25

def get_root_directory
  return @@root_directory
end

.set_default_settings(settings) ⇒ Object Also known as: default_settings=

Set the default Settings. Pass either String to a YAML settings file, or a Hash with your default settings.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/AdventureRL/Audio.rb', line 33

def set_default_settings settings
  default_settings = nil
  if    ([String, Pathname].include? settings.class)
    filepath = settings
    filepath = Pathname.new filepath  unless (filepath.is_a? Pathname)
    if (filepath.absolute?)
      default_settings = Settings.new filepath
    else
      if (File.file?(filepath))
        default_settings = Settings.new filepath
      else
        default_settings = Settings.new get_root_directory.join(filepath)
      end
    end
  elsif (settings.is_a? Hash)
    default_settings = Settings.new settings
  end
  @@default_settings = default_settings
end

.set_root_directory(directory) ⇒ Object Also known as: root=

Set the root directory for the audio files directory. All settings ‘directory’ values will be relative to this. Defaults to the entry scripts (the script that was called, $0) directory. Pass either a String with the directory path, or an instance of Pathname.



18
19
20
21
# File 'lib/AdventureRL/Audio.rb', line 18

def set_root_directory directory
  directory = Pathname.new directory  unless (directory.is_a? Pathname)
  @@root_directory = Pathname.new directory
end