Ruby Re-Volt Tools

A library for easy managing of Re-Volt’s files in various ways.

Requirements

gem install rubyzip

Install

gem install revolt

Summary

For the moment the library mostly has functionality related to track management. This may extend in the future.

Using the library users can easily create automated tasks. Some of the major features are:

  • Install track packages from WWW server or local file

  • Create track packages from locally installed tracks

  • Move, copy, rename and delete tracks

  • Search tracks with various criteria

  • Create alternative track repositories

Documentation

Most of the important API documentation is in ReVolt::Levels and ReVolt::Level classes. The rest of the library is usually accessed through them.

Conventions:

  • methods that return files return Pathname objects.

Examples

Here is a listing of some very simple, but illustrative examples of how the library could be used.

Listing all installed track names

require 'revolt'
levels = ReVolt::Levels.installed
levels.each_level do |level|
  puts "Level: " + level.name
end

Installing a track from a web-site

require 'revolt'
levels = ReVolt::Levels.installed
levels.install('http://url.for.track/trackname.zip')

Moving all non-favorite custom tracks to c:/removed

Note that in this example the c:/removed folder has to exist. The favorite array has the level names of all your favorite tracks that you want to keep, other custom tracks are removed. If a filename given as a parameter, reads the leves from there. Since the favorite tracks are as strings and not as symbol, the level id is changed to string before comparison (favorites.member?(level.id.to_s)

require 'revolt'
favorites = [
  'alderon',
  'sakura',
  're-ville'
]
if ARGV[0]
  favorites = open(ARGV[0]).readlines.map {|l| l.chomp}
end
levels  = ReVolt::Levels.installed
removed = ReVolt::Levels.at('c:/removed')
removed.create_dir_structure
levels.each_custom do |level|
  level.move_to(removed) if !favorites.member?(level.id.to_s)
end

Installing everything that looks like URL

A bit more complex example. Reads input from the user and tries installing everything that looks like an URL first to a temporary directory. From there copies tracks to installed tracks that do not exist already. This example is useful as it stands for example to install track URLs that are copy pasted to a chat.

require 'revolt'
levels    = ReVolt::Levels.installed
tmplevels = ReVolt::Levels.at('./tmp')
tmplevels.create_dir_structure
# Read input from console line by line
STDIN.each_line do |possible_urls|
  tmplevels.install_urls(possible_urls)
end
# Copy the levels that have arrived to tmplevels
# into installed levels
tmplevels.each do |level|
  # Install only levels that do not exist already
  if levels.member? level
    puts "Skipping installing of " + level.to_s + " because it exists"
  else 
    puts "Installing level " + level.to_s
    level.copy_to levels
  end
end

Applications

There are a couple of applications distributed with the library that are useful on their own

rv_install_level_urls.rb

Reads from the console everything that looks like an URL and tries to install it. Useful for installing easily tracks that are copy pasted to a chat. Use the -h switch to see more usage options.

rv_install_levels.rb

Installs track packages that are given as command line parameters. The tracks can be on a web-server or on the file system. For example if you have in my_tracks directory sakura.zip and happy_track.zip that are track packages, you can install them both with:

rv_install_levels.rb my_tracks/sakura.zip my_tracks/happy_track.zip

Or if you want to get a track from web-site use:

rv_install_levels.rb 'http://somesite.com/the_track_url'

rv_find_levels.rb

Finds levels by various criteria from installed levels. Basically you can find tracks by any property defined in the tracks .inf file. The easiest way to use it is to just enter the part of the name of the track you want to find. For examples:

rv_find_levels.rb temple

If you want to find a level by it’s exact folder name, you can prepend with ‘:’ (or use the –id switch), for example:

rv_find_levels.rb :temple

That would search for all levels whose name contains ‘temple’ (case insensitive). Another more complex example is to find all custom tracks that can be raced in reverse mode that have FARCLIP more than 10000:

rv_find_levels.rb -m 'custom?,reverse?,farclip>10000'

The match rules separated by ‘,’ are AND. To create OR rules you can specify several matching rules. For example to find all tracks that are raceable in reverse or whose name is ‘RV Temple’:

rv_find_levels.rb -m 'custom?,reverse?' -m 'name=RV Temple'

Use the -h option to get more help. The output format is:

<level id> (<level name>) [<matched_attribute>=<matched_value>]

Trying it in practice should clear the syntax if that seems weird.

rv_info_levels.rb

Displays information about levels, such as if it’s a custom track, stock track, can be raced in reverse, or is a so called “Full Custom” track. Also the contents INF file can be output. The same match format can be used as for rv_find_levels.rb

For more information and options:

rv_info_levels.rb -h

rv_delete_levels.rb

Deletes levels. Before deleting confirms by default. Match options format is similar as rv_find_levels.rb

For more information and options:

rv_info_levels.rb -h

rv_package_levels.rb

Creates packages of levels. The parameters are, as in the above matching level names. Use the ‘:’ in front to pack using folder names of the levels. From each level a separate package is created. Matching options can be used with -m as with rv_find_levels.rb

Example:

rv_package_levels_level.rb :rvt :chilled

This would create rvt.zip and chilled.zip of corresponding levels.

For more information and options:

rv_rename_level.rb -h

rv_rename_level.rb

Renames a level. Changes the directory name and necessary file names to the one specified. Confirms by default before doing the operation.

Example:

rv_rename_level.rb USER678 global_race

The parameters must be level ids, that is, they are the folder names of the level. The above command would rename USER678 to global_race.

The matching parameters can be used with -m option for the level to be renamed, but only one level can be matched or error is produced.

For more information and options:

rv_rename_level.rb -h