Strict Standards: Non-static method phpbb_feed_factory::init() should not be called statically in /home/jacius/rubygame/forums/feed.php on line 66
[phpBB Debug] PHP Notice: in file /feed.php on line 171: Cannot modify header information - headers already sent by (output started at /feed.php:66)
[phpBB Debug] PHP Notice: in file /feed.php on line 172: Cannot modify header information - headers already sent by (output started at /feed.php:66)
Rubygame Forums 2010-04-18T20:42:58+00:00 http://rubygame.org/forums/feed.php?f=5&t=113 2010-04-18T20:42:58+00:00 http://rubygame.org/forums/viewtopic.php?t=113&p=474#p474 <![CDATA[Re: Ruby Track Selector]]>

Statistics: Posted by jacius — Sun Apr 18, 2010 8:42 pm


]]>
2010-04-18T19:24:10+00:00 http://rubygame.org/forums/viewtopic.php?t=113&p=473#p473 <![CDATA[Ruby Track Selector]]> 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:
require "rubytrackselector"
rts = RTS::Rts.new

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

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

this code will output
Code:
/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:
# 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:
~ (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:
/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:
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:
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:
gem install rubytrackselector

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

Statistics: Posted by tape0 — Sun Apr 18, 2010 7:24 pm


]]>