Class: AdventureRL::Clip

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

Constant Summary collapse

IMAGE_FILENAME_REGEX =
/\A\d+\.(png|jpe?g)\z/i
INTERNAL_DEFAULT_SETTINGS =
Settings.new({
  name:      :clip_name,
  directory: nil,
  fps:       24,
  audio:     false
})
@@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) ⇒ Clip

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



57
58
59
60
61
# File 'lib/AdventureRL/Clip.rb', line 57

def initialize settings
  super
  audio_settings = get_settings :audio
  @audio = load_audio audio_settings  if (audio_settings)
end

Class Method Details

.get_root_directoryObject Also known as: root

Returns the currently set root images directory.



25
26
27
# File 'lib/AdventureRL/Clip.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/Clip.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 images 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/Clip.rb', line 18

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

Instance Method Details

#get_audioObject

Returns this Clip’s Audio, if one was provided at #new.



64
65
66
# File 'lib/AdventureRL/Clip.rb', line 64

def get_audio
  return @audio
end

#has_audio?Boolean

Returns true if this Clip has Audio.

Returns:

  • (Boolean)


69
70
71
# File 'lib/AdventureRL/Clip.rb', line 69

def has_audio?
  return !!get_audio
end