Class: TEF::Animation::Value
- Inherits:
-
Object
- Object
- TEF::Animation::Value
- Defined in:
- lib/tef/Animation/Value.rb
Constant Summary collapse
- PARAM_TYPES =
[:add, :multiply, :dampen, :delay, :from, :jump, :velocity]
Instance Attribute Summary collapse
-
#add ⇒ Numeric
nil), or to specify an offset of the number grabbed from #from.
-
#dampen ⇒ Numeric
Dampening factor.
-
#delay ⇒ Numeric
Delay factor.
-
#from ⇒ String?
If not set to nil, defines the other Value that this Value will take the output from.
-
#ID ⇒ Integer
readonly
Hardware-Number of this Value.
-
#jump ⇒ Numeric
writeonly
Instantly jump to the given number, skipping animation and smoothing.
-
#module_id ⇒ String?
Module-ID of the Animatable that this Value belongs to.
-
#multiply ⇒ Numeric
Multiplication factor.
-
#velocity ⇒ Numeric
writeonly
Set the velocity of the value.
Instance Method Summary collapse
-
#configure(data) ⇒ Object
Configure the Value with a Hash.
-
#generic_set(key, value) ⇒ Object
Internal function to set any of the Value’s parameters.
- #has_changes? ⇒ Boolean
-
#initialize(value_num) ⇒ Value
constructor
Initialize a new Value.
-
#set_string ⇒ Object
Internal function to retrieve the list of changes for this Value.
-
#total_id ⇒ String
Total ID of this Value, in the form ‘SxxMxxVxx’.
Constructor Details
#initialize(value_num) ⇒ Value
Initialize a new Value.
62 63 64 65 66 67 68 69 |
# File 'lib/tef/Animation/Value.rb', line 62 def initialize(value_num) @ID = value_num; @current = Hash.new(0); @changes = {} @is_animated = false; end |
Instance Attribute Details
#add ⇒ Numeric
nil), or to specify an offset of the number grabbed from #from.
|
# File 'lib/tef/Animation/Value.rb', line 24
|
#dampen ⇒ Numeric
Returns dampening factor. Causes the actual output value to smoothly transition to the target value ((from + add) * multiply). Larger values take longer (higher dampening).
|
# File 'lib/tef/Animation/Value.rb', line 33
|
#delay ⇒ Numeric
|
# File 'lib/tef/Animation/Value.rb', line 38
|
#from ⇒ String?
Returns If not set to nil, defines the other TEF::Animation::Value that this Value will take the output from. Allows the user to follow some other parameter and create interesting linkages.
|
# File 'lib/tef/Animation/Value.rb', line 45
|
#ID ⇒ Integer (readonly)
Returns Hardware-Number of this Value.
18 19 20 |
# File 'lib/tef/Animation/Value.rb', line 18 def ID @ID end |
#jump=(value) ⇒ Numeric (writeonly)
Returns Instantly jump to the given number, skipping animation and smoothing. Will not reconfigure the actual target, and can thusly be used to temporarily “bump” the value.
|
# File 'lib/tef/Animation/Value.rb', line 50
|
#module_id ⇒ String?
Returns Module-ID of the Animatable that this Value belongs to.
22 23 24 |
# File 'lib/tef/Animation/Value.rb', line 22 def module_id @module_id end |
#multiply ⇒ Numeric
|
# File 'lib/tef/Animation/Value.rb', line 29
|
Instance Method Details
#configure(data) ⇒ Object
Configure the Value with a Hash.
This lets the user configure the Value by passing a Hash. The data will be passed into the six attributes of this Value according to their key.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/tef/Animation/Value.rb', line 125 def configure(data) if data.is_a? Numeric self.add = data elsif data.is_a? Hash data.each do |key, value| generic_set key, value end else self.from = data; end end |
#generic_set(key, value) ⇒ Object
Internal function to set any of the Value’s parameters.
This can be called by the user, but it is preferrable to use #configure or the matching parameter setter functions.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/tef/Animation/Value.rb', line 89 def generic_set(key, value) if key == :from self.from = value return end raise ArgumentError, 'Key does not exist!' unless PARAM_TYPES.include? key raise ArgumentError, "Input must be numeric!" unless value.is_a? Numeric return if (value == @current[key] && ![:jump, :velocity].include?(key)) if [:multiply, :dampen, :delay].include? key @is_animated = true end @current[key] = value @changes[key] = true end |
#has_changes? ⇒ Boolean
159 160 161 |
# File 'lib/tef/Animation/Value.rb', line 159 def has_changes? return !@changes.empty? end |
#set_string ⇒ Object
Do not call this as user unless you know what you are doing! This will delete the retrieved changes, which may cause loss of data if they are not properly sent to the animation slaves!
Internal function to retrieve the list of changes for this Value.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/tef/Animation/Value.rb', line 173 def set_string() return nil unless has_changes? if !@is_animated return nil unless @changes[:add] out_str = "J#{rcut(@current[:add])};" @changes = {} return out_str end out_str = []; out_str << "J#{rcut(@current[:jump])}" if @changes[:jump] out_str << "V#{rcut(@current[:velocity])}" if @changes[:velocity] out_str << @current[:from] if @changes[:from] config_strs = []; config_strs_out = []; [:add, :multiply, :dampen, :delay].each do |k| config_strs << rcut(@current[k]) config_strs_out = config_strs.dup if @changes[k] end @changes = {} (out_str + config_strs_out).join(' ') + ';' end |
#total_id ⇒ String
Returns Total ID of this Value, in the form ‘SxxMxxVxx’.
81 82 83 |
# File 'lib/tef/Animation/Value.rb', line 81 def total_id() "#{@module_id}V#{@ID.to_s(16)}" end |