Class: Metro::Model::SongProperty

Inherits:
Property
  • Object
show all
Defined in:
lib/metro/models/properties/song_property.rb

Overview

A song property maintains a Gosu::Song.

A song is stored in the properties as the path in the assets folder and is converted into a Gosu::Song when it is retrieved within the system. When retrieving a song the Song Property will attempt to use a song that already exists that meets that criteria.

The songs are cached within the song property to help performance by reducing the unncessary creation of similar song.

Examples:

Defining a song property


class Song < Metro::Model
  property :song
end

Defining a song property providing a default


class Song < Metro::Model
  property :song, path: 'happy-song.wav'
end

Using a song property with a different property name


class Song < Metro::Model
  property :intro, type: :song, path: 'intro-song.wav'
end

Constant Summary

Constants included from Units

Units::Bounds

Instance Attribute Summary

Attributes inherited from Property

#block, #model, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Property

define_property, defined_properties, get, #get, get_or_set, gets, hash_with_default_to_nil, inherited, #initialize, properties, properties_hash, property, #set, set, sets

Constructor Details

This class inherits a constructor from Metro::Model::Property

Class Method Details

.song_for(options) ⇒ Object

Returns a Metro::Song. This is composed of the metadata provided and a Gosu::Song.

Songs are cached within the property to increase performance.

Parameters:

  • options (Hash)

    the path, window, and other parameters necessary to generate a song.



83
84
85
# File 'lib/metro/models/properties/song_property.rb', line 83

def self.song_for(options)
  Song.find_or_create(options)
end

Instance Method Details

#default_songObject

Returns the default song for the song property. This is based on the default song name.

Returns:

  • the default song for the song property. This is based on the default song name.



63
64
65
# File 'lib/metro/models/properties/song_property.rb', line 63

def default_song
  self.class.song_for path: default_song_name, window: model.window
end

#default_song_nameObject

Returns a string song name that is default. If the property was not created with a default value the the default song is the missing song found in Metro.

Returns:

  • a string song name that is default. If the property was not created with a default value the the default song is the missing song found in Metro.



71
72
73
# File 'lib/metro/models/properties/song_property.rb', line 71

def default_song_name
  options[:path] or 'missing.ogg'
end