class TEF::Animation::Color
Constants
- PARAM_TYPES
Attributes
ID[R]
@return [Integer] Hardware-Number of this Color
module_id[R]
@return [String, nil] Module-ID of the {Animatable} that this
color belongs to.
Public Class Methods
new(value_num)
click to toggle source
Public Instance Methods
configure(data)
click to toggle source
Configure the color with a hash.
This lets the user configure the color by passing a hash. The data will be passed into the five attributes of this color according to their key. @example
a_color.configure({ delay_a: 10, target: 0xFF0000 })
# File lib/tef/Animation/Color.rb, line 120 def configure(data) if data.is_a? Numeric self.target = data elsif data.is_a? Hash data.each do |key, value| generic_set key, value end else raise ArgumentError, 'Config data must be Hash or Numeric' end end
generic_set(key, value)
click to toggle source
Internal function to set any of the Color's parameters.
This can be called by the user, but it is preferrable to use {#configure} or the matching parameter setter functions.
# File lib/tef/Animation/Color.rb, line 89 def generic_set(key, value) raise ArgumentError, 'Key does not exist!' unless PARAM_TYPES.include? key raise ArgumentError, "Input must be numeric!" unless value.is_a? Numeric return if ![:jump, :velocity].include?(key) && value == @current[key] if [:delay_a, :delay_b].include? key @is_animated = true end @current[key] = value @changes[key] = true end
has_changes?()
click to toggle source
# File lib/tef/Animation/Color.rb, line 132 def has_changes? return !@changes.empty? end
module_id=(new_id)
click to toggle source
# File lib/tef/Animation/Color.rb, line 71 def module_id=(new_id) @module_id = new_id PARAM_TYPES.each do |key| @changes[:key] = true if @current[key] != 0 end end
set_string()
click to toggle source
@private Internal function to retrieve the list of changes for this color. @note 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!
# File lib/tef/Animation/Color.rb, line 146 def set_string() return nil unless has_changes? if !@is_animated return nil unless @changes[:target] out_str = "V#{@ID} J#{@current[:target].to_s(16)};" @changes = {} return out_str end out_str = ["V#{@ID}"]; out_str << "J#{@current[:jump].to_s(16)}" if @changes[:jump] out_str << "V#{@current[:velocity].to_s(16)}" if @changes[:velocity] config_strs = []; config_strs_out = []; [:target, :delay_a, :delay_b].each do |k| if k == :target config_strs << @current[k].to_s(16) else config_strs << rcut(@current[k]) end config_strs_out = config_strs.dup if @changes[k] end @changes = {} (out_str + config_strs_out).join(' ') + ';' end
Private Instance Methods
rcut(value)
click to toggle source
Internal function to strip trailing zeroes for floats
# File lib/tef/Animation/Color.rb, line 137 def rcut(value) value.to_s.gsub(/(\.)0+$/, '') end