Class: RTS::Rts

Inherits:
Struct
  • Object
show all
Defined in:
lib/rubytrackselector/utp.rb

Overview

Main RTS Class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRts

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

#currentObject (readonly)

The current track being played by Rts#play.



60
61
62
# File 'lib/rubytrackselector/utp.rb', line 60

def current
  @current
end

#enable_localObject

Returns the value of attribute enable_local

Returns:

  • (Object)

    the current value of enable_local



58
59
60
# File 'lib/rubytrackselector/utp.rb', line 58

def enable_local
  @enable_local
end

#localObject

Returns the value of attribute local

Returns:

  • (Object)

    the current value of local



58
59
60
# File 'lib/rubytrackselector/utp.rb', line 58

def local
  @local
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



58
59
60
# File 'lib/rubytrackselector/utp.rb', line 58

def tag
  @tag
end

Instance Method Details

#filesObject

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