Class: Metro::Model::SampleProperty

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

Overview

A sample property maintains a Gosu::Sample.

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

Examples:

Defining a sample property


class Hero < Metro::Model
  property :sample
end

Defining a sample property providing a default


class Hero < Metro::Model
  property :sample, path: 'pickup.wav'
end

Using a sample property with a different property name


class Hero < Metro::Model
  property :pickup_sample, type: :sample, path: 'pickup.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

.sample_for(options) ⇒ Object

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

Parameters:

  • options (Hash)

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



78
79
80
# File 'lib/metro/models/properties/sample_property.rb', line 78

def self.sample_for(options)
  Metro::Sample.create(options)
end

Instance Method Details

#default_sampleObject

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

Returns:

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



60
61
62
# File 'lib/metro/models/properties/sample_property.rb', line 60

def default_sample
  self.class.sample_for path: default_sample_filename, window: model.window
end

#default_sample_filenameObject

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

Returns:

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



68
69
70
# File 'lib/metro/models/properties/sample_property.rb', line 68

def default_sample_filename
  options[:path] or "missing.wav"
end