Page 1 of 1

Ruby Track Selector

PostPosted: Sun Apr 18, 2010 7:24 pm
by tape0
You know the problem:
You are really into Black Metal and your next ├╝ber-realistic 3d shooter written in Rubygame will have black metal in every single level and every single menu. However, after your game has won the first awards, people start complaining that they don't like the music. What now? (Note: "Chainsaw them" is not a valid option.)

Ruby Track Selector to the rescue!
RTS allows users to put the music they like into their home directory, and RTS will create a list containing all music files in the user's home directory and (optionally) all music files in the application's music directory. Of course, the files are organized into tags to seperate the calm loading music from the black metal fighting music.

As a bonus, all files in ~/.rubytracks are shared between all games using RTS.

Examples:

Example #1:
Code: Select all
require "rubytrackselector"
rts = RTS::Rts.new

rts.tag = RTS::MENU
puts rts.files.join("\n")

Assuming this directory structure:
Code: Select all
~ (home / userprofile)
+- .rubytracks
|  +- menu
|  |  +- iriepathie_hoer_nicht_auf.ogg
|  |  +- rick_astley_never_gonna_give_you_up.ogg
|  |  |

this code will output
Code: Select all
/your_home_dir/.rubytracks/menu/iriepathie_hoer_nicht_auf.ogg
/your_home_dir/.rubytracks/menu/rick_astley_never_gonna_give_you_up.ogg


Example #2:
Code: Select all
# Note: this file is /script_dir/script.rb
require "rubytrackselector"
rts = RTS::Rts.new
rts.local << "music"
rts.enable_local = true

rts.tag = RTS::MENU
puts rts.files.join("\n")

Assuming this directory structure:
Code: Select all
~ (home / userprofile)
+- .rubytracks
|  +- menu
|  |  +- iriepathie_hoer_nicht_auf.ogg
|  |  +- rick_astley_never_gonna_give_you_up.ogg
|  |  |

+- script_dir
|  +- script.rb
|  +- music
|  |  +- menu
|  |  |  +- immortal_call_of_the_wintermoon.ogg
|  |  |  +- dimmu_borgir_burn_in_hell.ogg
|  |  |  |

this code will output
Code: Select all
/your_home_dir/.rubytracks/menu/iriepathie_hoer_nicht_auf.ogg
/your_home_dir/.rubytracks/menu/rick_astley_never_gonna_give_you_up.ogg
/script_dir/music/menu/immortal_call_of_the_wintermoon.ogg
/script_dir/music/menu/dimmu_borgir_burn_in_hell.ogg


Getting a random song:
As easy as (note: assume the same directory structure as in Example #2)
Code: Select all
rts.files.sample
# => /script_dir/music/menu/immortal_call_of_the_wintermoon.ogg


Rubygame integration:
As easy as (note: assume the same directory structure as in Example #2)
Code: Select all
require "rubytrackselector"
require "rubygame"

rts = RTS::Rts.new
rts.local << "music"
rts.enable_local = true

rts.tag = RTS::MENU
rts.play(:repeat => -1)

This code will select a random file and plays it forever using Rubygame::Music.

Final Note:
There's only one option in RTS, enable_local. If this is off, RTS will not report any files in the application specific directories (specified by local). You should add it to your game's configuration screen. Why? Because if a player doesn't like the music that comes with your game, he can turn it off with one configuration option. Oh, and for me, "Chainsaw them" IS a valid option.

Give me!
Code: Select all
gem install rubytrackselector

Or on github: http://github.com/raphaelr/rubytrackselector
RDoc: http://raphaelr.github.com/rubytrackselector/rdoc

Re: Ruby Track Selector

PostPosted: Sun Apr 18, 2010 8:42 pm
by jacius
This is awesome! :D