class TEF::Animation::Value

Constants

PARAM_TYPES

Attributes

ID[R]

@return [Integer] Hardware-Number of this Value

module_id[R]

@return [String, nil] Module-ID of the {Animatable} that this

Value belongs to.

Public Class Methods

new(value_num) click to toggle source

Initialize a new Value. @param [Integer] value_num The hardware ID of this Value.

must match the ID defined in the animation slaves.
# File lib/tef/Animation/Value.rb, line 62
def initialize(value_num)
        @ID = value_num;

        @current = Hash.new(0);
        @changes = {}

        @is_animated = false;
end

Public Instance Methods

configure(data) click to toggle source

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. @example

a_color.configure({ add: 2, dampen: 10 })
# 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
from() click to toggle source
# File lib/tef/Animation/Value.rb, line 137
def from() return @current[:from] end
from=(target) click to toggle source
# File lib/tef/Animation/Value.rb, line 139
def from=(target)
        if target.is_a? Value
                target = target.total_id
        end

        if target.nil?
                target = 'S0M0V0'
        end

        unless target =~ /^S[\d]{1,3}M[\da-f]{1,3}V\d+$/
                raise ArgumentError, 'Target must be a valid Animation Value'
        end

        return if target == @current[:from]

        @current[:from] = target
        @changes[:from] = true
        @is_animated = true
end
generic_set(key, value) click to toggle source

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.

# 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?() click to toggle source
# File lib/tef/Animation/Value.rb, line 159
def has_changes?
        return !@changes.empty?
end
module_id=(new_id) click to toggle source
# File lib/tef/Animation/Value.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 Value. @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/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() click to toggle source

@return [String] Total ID of this Value, in the form

'SxxMxxVxx'
# File lib/tef/Animation/Value.rb, line 81
def total_id()
        "#{@module_id}V#{@ID.to_s(16)}"
end

Private Instance Methods

rcut(value) click to toggle source

Internal function to strip trailing zeroes for floats

# File lib/tef/Animation/Value.rb, line 164
        def rcut(value)
        value.to_s.gsub(/(\.)0+$/, '')
end