Category: Libraries
Addon Information
Works with 3.2
Download Latest Version.
To add favorites please register for a free account. If you already have one you need to login. How do I install this? (FAQ)
Author:
Version:
1.0.1
Date:
09-27-2009 01:01 PM
Size:
4.03 Kb
Downloads:
72
Favorites:
1
MD5:
LibStateDriver-1.0
An alternative to using Blizzard's SecureStateDriver for non-secure code and may also be modified in combat without issue. As new macro-style parameters are encountered, they are parsed to determine the best way to handle them (OnEvent/OnUpdate). A running count of the number of enabled parameters utilizing a particular event is kept in order to ensure all unused events are unregistered to prevent unnecessary event processing.

Parameters are also checked for early outs such as with "[mod][ ]0; 1" or "[combat] 0; [group] 1; [mod][ ] 2; [pet] 3; [stealth] 4; 5". In those examples the "[ ]" would cause event processing for everything after to be ignored. Further, cases like "[mod][ ] 0; 1" or even "0; 1" are detected as not being able to change state so after the initial state is evaluated no further processing is wasted on them. NOTE: Cases such as "[combat][nocombat] 0; 1" are not checked for.

Example - Hide/Show a frame in/out of combat:
Code:
local frame = CreateFrame('Frame', nil, UIParent)

local function handler(frame, method)
	frame[method](frame)
end

local stateDriver = LibStub('LibStateDriver-1.0'):New("[combat] Hide; Show", handler, frame)
Example - Hide a frame in a raid, dim it in combat or in a party:
Code:
local frame = CreateFrame('Frame', nil, UIParent)

local function handler(frame, alpha)
	alpha = tonumber(alpha)
	if alpha == 0 then
		frame:Hide()
	else
		frame:SetAlpha(alpha)
		frame:Show()
	end
end

local stateDriver = LibStub('LibStateDriver-1.0'):New("[group:raid] 0; [combat][group:party] 0.5; 1", handler, frame)

API

stateDriver = lib:New(parameters, callback [, arg [, disable]])

Create a new state driver object.

Arguments:
parameters - (string) The macro-style parameters to be evaluated for state changes.

callback - (function) The function to be called when a state change occurs. Two arguments are passed: arg, state.

arg - (any) An optional parameter to be passed to the callback handler. If not provided then nil will still be passed in it's place.

disable - (boolean) If true then the state driver will not be enabled upon creation.
Returns:
stateDriver - (table) The state driver object to be used by the calling code (see State Drivers below).

State Drivers

The object returned by lib:New() is an empty table with a metatable that provides several methods. The table itself is not utilized by the library and is completely at the disposal of the calling code to use as needed. The object may be treated like a function, doing so forces a state update and callback. The methods provided are:

stateDriver:Disable()

Stop the state driver from monitoring for state changes and triggering callbacks. Being disabled will not prevent stateDriver() from generating a callback.


stateDriver:Enable()

Start the state driver monitoring for state changes and triggering callbacks, also immediately triggers a state update and callback. The state driver is automatically enabled upon creation unless the disable field was set.


arg = stateDrive:GetArg()

Get the value currently assigned to be passed as the first argument of a callback.

Returns:
arg - (any) The assigned arg.

callback = stateDriver:GetCallback()

Get the callback function currently assigned to the state driver.

Returns:
callback - (function) The assigned callback.

parameters = stateDriver:GetParameters()

Get the parameters currently assigned to the state driver.

Returns:
parameters - (string) The assigned parameters.

state = stateDriver:GetState()

Get the state currently associated with the state driver.

Returns:
state - (any) The state of the state driver as determined by the last evaluation of it's assigned parameters.

enabled = stateDriver:IsEnabled()

Get the enabled status of the state driver.

Returns:
enabled - (boolean) The current status of the state driver, true if enabled.

stateDriver:SetArg(arg)

Set the value to be passed as the first argument of a callback.

Arguments:
arg - (any) The value to assign as the first argument of a callback.

stateDriver:SetCallback(callback)

Set the function to be called when state changes occur.

Arguments:
callback - (function) The function to be called when a state change occurs.

stateDriver:SetParameters(parameters)

Set the macro-style parameters that are to be evaluated for state changes. Changing parameters immediately causes the state to be re-evaluated and if it changed a callback is triggered, unless the state driver is disabled.

Arguments:
parameters - (string) The parameters that are to be monitored for state changes.

stateDriver:Toggle()

Switch the status of the state driver from enabled to disabled or vice-versa.
  Change Log - LibStateDriver-1.0
Version 1.0.1 (09/27/2009)
- Added MMOUI Minion support to TOC file (X-WoWI-ID)
- Changed the event used to detect spec changes to ACTIVE_TALENT_GROUP_CHANGED (from PLAYER_TALENT_UPDATE)

Version 1.0 (07/22/2009)
- Initial release
  Optional Files - LibStateDriver-1.0
Sorry, there are currently no optional files available.
  Comments - LibStateDriver-1.0
There have been no comments posted to this file.
Be the first to add one.



Category Jump:




The Network:
EQInterface | EQ2Interface | LoTROInterface | MMOInterface | War.MMOUI | WoWInterface | VGInterface | Allakhazam | Thottbot | Wowhead | Zam


©2009 MMOUI / ZAM Network
vBulletin - Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.