Class: Metro::Model::TextProperty

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

Overview

A text property maintains a string of text

Text is stored as text in properties. When retrieving the text, the contents of the text will be evaluated within the instance of the model’s scene. Which means that text may contain escaped variables referencing anything in the scene or the game.

Examples:

Defining a text property


class Scoreboard < Metro::Model
  property :font
  property :position
  property :color
  property :scale
  property :text

  def draw
    font.draw text, x, y, z_order, x_factor, y_factor, color
  end

end

Defining with a default and text that will be instance evaluated.


class ScoreBoard < Metro::Model
  property :score
  property :text, default: 'Score is #{score}'
end

Using a text property with a different property name


class Hero < Metro::Model
  proeprty :font
  property :position
  property :color
  property :scale
  property :description, type: :text

  def draw
    font.draw description, x, y, z_order, x_factor, y_factor, color
  end
end

Constant Summary

Constants included from Units

Units::Bounds

Instance Attribute Summary

Attributes inherited from Property

#block, #model, #options

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

Instance Method Details

#default_textObject



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

def default_text
  options[:default] || 'TEXT NOT SPECIFIED!'
end

#evalute_within_scene(text) ⇒ Object



64
65
66
# File 'lib/metro/models/properties/text_property.rb', line 64

def evalute_within_scene(text)
  model.scene.instance_eval( "\"#{text}\"" )
end