Class: UIC::MetaData::AssetBase

Inherits:
Object
  • Object
show all
Defined in:
lib/ruic/assets.rb

Overview

The base class for all assets. All other classes are dynamically created when a MetaData.xml file is loaded.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(presentation, element) ⇒ AssetBase

Create a new asset. This is called for you automatically; you likely should not be using it.

Parameters:

  • presentation (Presentation)

    the presentation owning this asset.

  • element (Nokogiri::XML::Element)

    the internal XML element in the scene graph of the presentation.



59
60
61
62
# File 'lib/ruic/assets.rb', line 59

def initialize( presentation, element )
	@presentation = presentation
	@el = element
end

Class Attribute Details

.nameString (readonly)

Returns The scene graph name of the asset.

Returns:

  • (String)

    The scene graph name of the asset.



11
12
13
# File 'lib/ruic/assets.rb', line 11

def name
  @name
end

Instance Attribute Details

#elNokogiri::XML::Element

Returns the internal XML element in the scene graph of the presentation.

Returns:

  • (Nokogiri::XML::Element)

    the internal XML element in the scene graph of the presentation.



54
55
56
# File 'lib/ruic/assets.rb', line 54

def el
  @el
end

#presentationPresentation

Returns the presentation that this asset is part of.

Returns:

  • (Presentation)

    the presentation that this asset is part of.



51
52
53
# File 'lib/ruic/assets.rb', line 51

def presentation
  @presentation
end

Class Method Details

.propertiesHash

Returns a hash mapping attribute names to Property instances.

Returns:

  • (Hash)

    a hash mapping attribute names to Property instances.



14
15
16
# File 'lib/ruic/assets.rb', line 14

def properties
	(ancestors[1].respond_to?(:properties) ? ancestors[1].properties : {}).merge(@properties)
end

Instance Method Details

#[](attribute_name, slide_name_or_index = nil) ⇒ Object, ValuesPerSlide

Get the value(s) of an attribute. If slide_name_or_index is omitted, creates a ValuesPerSlide proxy for the specified attribute.

Examples:

 = app/"main:Scene.UI.Logo"
show .master?               #=> true  (it's a master object)
show ['endtime'].linked?    #=> false (the endtime property is unlinked)
show ['endtime'].values     #=> [10000,500,1000,750]
show ['endtime',0]          #=> 10000 (the master slide value)
show ['endtime',"Slide 1"]  #=> 500
show ['endtime',2]          #=> 1000

Parameters:

  • attribute_name (String, Symbol)

    the name of the attribute.

  • slide_name_or_index (Integer, String) (defaults to: nil)

    the slide number or name to find the value on.

Returns:

  • (Object)

    the value of the property on the given slide.

  • (ValuesPerSlide)

    if no slide is specified.

See Also:



206
207
208
209
210
211
212
213
214
# File 'lib/ruic/assets.rb', line 206

def [](attribute_name, slide_name_or_index=nil)
	if property = properties[attribute_name.to_s]
		if slide_name_or_index
			property.get( self, slide_name_or_index ) if has_slide?(slide_name_or_index)
		else
			UIC::ValuesPerSlide.new(@presentation,self,property)
		end
	end
end

#[]=(attribute_name, slide_name_or_index = nil, new_value) ⇒ Object

Set the value of an attribute, either across all slides, or on a particular slide.

Examples:

 = app/"main:Scene.UI.Logo"
show .master?               #=> true  (it's a master object)
show ['endtime'].linked?    #=> false (the endtime property is unlinked)
show ['endtime'].values     #=> [10000,500,1000,750]

['endtime',1] = 99
show ['endtime'].values     #=> [10000,99,1000,750]

['endtime'] = 42
show ['endtime'].values     #=> [42,42,42,42]
show ['endtime'].linked?    #=> false (the endtime property is still unlinked)

Parameters:

  • attribute_name (String, Symbol)

    the name of the attribute.

  • slide_name_or_index (Integer, String) (defaults to: nil)

    the slide number or name to set the value on.

  • new_value (Numeric, String)

    the new value for the attribute.

See Also:



235
236
237
238
239
# File 'lib/ruic/assets.rb', line 235

def []=( attribute_name, slide_name_or_index=nil, new_value )
	if property = properties[attribute_name.to_s] then
		property.set(self,new_value,slide_name_or_index)
	end
end

#at(sub_path) ⇒ MetaData::AssetBase Also known as: /

Find an asset by relative scripting path.

Examples:

preso = app.main
layer = preso/"Scene.Layer"
cam1  = app/"main:Scene.Layer.Camera"
cam2  = preso/"Scene.Layer.Camera"
cam3  = layer/"Camera"
cam4  = cam1/"parent.Camera"

assert cam1==cam2 && cam2==cam3 && cam3==cam4

Returns:

See Also:



45
46
47
# File 'lib/ruic/assets.rb', line 45

def at(sub_path)
	presentation.at(sub_path,@el)
end

#childrenArray<AssetBase>

Returns array of child assets in the scene graph. Children are in scene graph order.

Returns:

  • (Array<AssetBase>)

    array of child assets in the scene graph. Children are in scene graph order.

See Also:



77
78
79
# File 'lib/ruic/assets.rb', line 77

def children
	presentation.child_assets(self)
end

#componentAssetBase

Returns the component or scene that owns this asset. If this asset is a component, does not return itself.

Returns:

  • (AssetBase)

    the component or scene that owns this asset. If this asset is a component, does not return itself.

See Also:



104
105
106
# File 'lib/ruic/assets.rb', line 104

def component
	presentation.owning_component(self)
end

#component?Boolean

Returns true if this asset is a component or Scene.

Returns:

  • (Boolean)

    true if this asset is a component or Scene.



109
110
111
# File 'lib/ruic/assets.rb', line 109

def component?
	@el.name=='Component' || @el.name=='Scene'
end

#find(criteria = {}, &block) ⇒ Array<AssetBase>

Find descendant assets matching criteria. This method is the same as (but more convenient than) Presentation#find using the :_under criteria. See that method for documentation of the criteria.

Examples:

preso = app.main
group = preso/"Scene.Layer.Vehicle"
tires = group.find name:/^Tire/

# alternative
tires = preso.find name:/^Tire/, _under:group

Returns:

See Also:



96
97
98
99
# File 'lib/ruic/assets.rb', line 96

def find(criteria={},&block)
	criteria[:_under] ||= self
	presentation.find(criteria,&block)
end

#has_slide?(slide_name_or_index) ⇒ Boolean

Returns true if this asset is present on the specified slide.

Parameters:

  • slide_name_or_index (Integer, String)

    the slide number of name to check for presence on.

Returns:

  • (Boolean)

    true if this asset is present on the specified slide.

See Also:



127
128
129
# File 'lib/ruic/assets.rb', line 127

def has_slide?(slide_name_or_index)
	presentation.has_slide?(self,slide_name_or_index)
end

#master?Boolean

Returns true if this asset is on the master slide.

Returns:

  • (Boolean)

    true if this asset is on the master slide.

See Also:



115
116
117
# File 'lib/ruic/assets.rb', line 115

def master?
	presentation.master?(self)
end

#nameString

Returns the name of this asset in the scene graph.

Returns:

  • (String)

    the name of this asset in the scene graph.



177
178
179
# File 'lib/ruic/assets.rb', line 177

def name
	properties['name'].get( self, presentation.slide_index(self) )
end

#name=(new_name) ⇒ String

Change the name of the asset in the scene graph.

Parameters:

  • new_name (String)

    the new name for this asset.

Returns:

  • (String)

    the new name.



184
185
186
187
# File 'lib/ruic/assets.rb', line 184

def name=( new_name )
	@path = nil # invalidate the memoization
	properties['name'].set( self, new_name, presentation.slide_index(self) )
end

#on_slide(slide_name_or_index) ⇒ SlideValues

Returns a proxy that yields attribute values for a specific slide.

Examples:

 = app/"main:Scene.UI.Logo"
assert .master?             # It's a master object

show ['endtime'].values     #=> [10000,500,1000,750]
show ['opacity'].values     #=> [100,0,0,100]
logo1 = .on_slide(1)
logo2 = .on_slide(2)
show logo1['endtime']           #=> 500
show logo2['endtime']           #=> 1000
show logo1['opacity']           #=> 0
show logo2['opacity']           #=> 0

logo2['opacity'] = 66
show ['opacity'].values     #=> [100,0,66,100]

Parameters:

  • slide_name_or_index (Integer, String)

    the slide number or name to create the proxy for.

Returns:

  • (SlideValues)

    a proxy that yields attribute values for a specific slide.



155
156
157
158
159
# File 'lib/ruic/assets.rb', line 155

def on_slide(slide_name_or_index)
	if has_slide?(slide_name_or_index)
		UIC::SlideValues.new( self, slide_name_or_index )
	end
end

#parentAssetBase

Returns the parent of this asset in the scene graph.

Returns:

  • (AssetBase)

    the parent of this asset in the scene graph.

See Also:



71
72
73
# File 'lib/ruic/assets.rb', line 71

def parent
	presentation.parent_asset(self)
end

#pathString

Returns the script path to this asset.

Returns:

  • (String)

    the script path to this asset.

See Also:



164
165
166
# File 'lib/ruic/assets.rb', line 164

def path
	@path ||= @presentation.path_to(self)
end

#path_to(other_asset) ⇒ String

Returns the script path to another asset, relative to this one.

Parameters:

  • other_asset (AssetBase)

    the asset to find the relative path to.

Returns:

  • (String)

    the script path to another asset, relative to this one.

See Also:



172
173
174
# File 'lib/ruic/assets.rb', line 172

def path_to(other_asset)
	@presentation.path_to(other_asset,self)
end

#propertiesHash

Returns a hash mapping attribute names to Property instances.

Returns:

  • (Hash)

    a hash mapping attribute names to Property instances.



25
26
27
# File 'lib/ruic/assets.rb', line 25

def properties
	self.class.properties
end

#slide?Boolean

Returns true if this asset is a Slide.

Returns:

  • (Boolean)

    true if this asset is a Slide.



120
121
122
# File 'lib/ruic/assets.rb', line 120

def slide?
	false
end

#slidesSlideCollection

Returns an array-like collection of all slides that the asset is available on.

Returns:

  • (SlideCollection)

    an array-like collection of all slides that the asset is available on.

See Also:



133
134
135
# File 'lib/ruic/assets.rb', line 133

def slides
	presentation.slides_for(self)
end

#to_xmlString

Returns the XML representation of the scene graph element.

Returns:

  • (String)

    the XML representation of the scene graph element.



242
243
244
# File 'lib/ruic/assets.rb', line 242

def to_xml
	@el.to_xml
end

#typeString

Returns the type of this asset. For example: "Model", "Material", "ReferencedMaterial", "PathAnchorPoint", etc.

Returns:

  • (String)

    the type of this asset. For example: "Model", "Material", "ReferencedMaterial", "PathAnchorPoint", etc.



65
66
67
# File 'lib/ruic/assets.rb', line 65

def type
	self.class.name
end