Class: RTS::Rts
- Inherits:
-
Struct
- Object
- Struct
- RTS::Rts
- Defined in:
- lib/rubytrackselector/utp.rb
Overview
Main RTS Class.
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
The current track being played by
Rts#play
. -
#enable_local ⇒ Object
Returns the value of attribute enable_local.
-
#local ⇒ Object
Returns the value of attribute local.
-
#tag ⇒ Object
Returns the value of attribute tag.
Instance Method Summary collapse
-
#files ⇒ Object
Returns a list of all music files in the selected tag.
-
#initialize ⇒ Rts
constructor
Initializes a new RTS.
-
#play(opts = {}) ⇒ Object
Selects a random music file and plays it.
Constructor Details
#initialize ⇒ Rts
Initializes a new RTS.
63 64 65 66 |
# File 'lib/rubytrackselector/utp.rb', line 63 def initialize self.local = [] self.enable_local = false end |
Instance Attribute Details
#current ⇒ Object (readonly)
The current track being played by Rts#play
.
60 61 62 |
# File 'lib/rubytrackselector/utp.rb', line 60 def current @current end |
#enable_local ⇒ Object
Returns the value of attribute enable_local
58 59 60 |
# File 'lib/rubytrackselector/utp.rb', line 58 def enable_local @enable_local end |
#local ⇒ Object
Returns the value of attribute local
58 59 60 |
# File 'lib/rubytrackselector/utp.rb', line 58 def local @local end |
#tag ⇒ Object
Returns the value of attribute tag
58 59 60 |
# File 'lib/rubytrackselector/utp.rb', line 58 def tag @tag end |
Instance Method Details
#files ⇒ Object
Returns a list of all music files in the selected tag.
69 70 71 72 73 74 |
# File 'lib/rubytrackselector/utp.rb', line 69 def files a = [RTS.user_music] a += self.local if self.enable_local join_string = (self.tag ? "#{self.tag}/" : "") + "*.{ogg,wav,mid,midi,mod}" return a.collect { |x| Dir[File.join(x, join_string)] }.inject(:+) end |
#play(opts = {}) ⇒ Object
Selects a random music file and plays it. The option hash passed to this method gets forwarded to Rubygame::Music#play
. See docs.rubygame.org/rdoc/current/classes/Rubygame/Music.html#M000407 for more information.
80 81 82 83 84 85 86 87 88 |
# File 'lib/rubytrackselector/utp.rb', line 80 def play(opts = {}) if fn = files.sample @current = Rubygame::Music.load(files.sample) @current.play(opts) return @current else return nil end end |