LibStormEarthAndFire-1.0

3.8k Downloads

Library to track Storm, Earth, and Fire spirits.

This library requires both LibStub and CallbackHandler-1.0.

This library exposes a set of functions to query the current state, and embeds CallbackHandler-1.0 to provide callbacks when the state changes. These callbacks can be registered with the usual RegisterCallback(), UnregisterCallback(), and UnregisterAllCallbacks() methods.


Functions

:Enabled()

Returns whether the tracker is enabled. The tracker is enabled when the player is a monk in Windwalker spec.

Returns

enabled
Boolean - Returns true if tracking is enabled, false otherwise

:SpiritInfoByTargetGUID(guid)

Returns info about a spirit targeting that GUID.

Arguments

guid
String - GUID of the target

Returns

If no spirit has that target, nothing is returned. Otherwise:

name
String - Name of the spirit
guid
String - GUID of the spirit
icon
String - Texture for the spirit icon

:NumSpirits()

Returns the number of active spirits.

Returns

count
Number - Number of active spirits, or 0 if none

:SpiritInfoByIndex(index)

Returns info about a spirit by index from 1 to NumSpirits().

Arguments

index
Number - Index from 1 to NumSpirits()

Returns

If no spirit by that index, nothing is returned. Otherwise:

name
String - Name of the spirit
guid
String - GUID of the spirit
target
String - Name of the spirit's target
targetGUID
String - GUID of the spirit's target
icon
String - Texture for the spirit's icon

Callbacks

ENABLED

Called when the tracker enables itself. This is generally in response to PLAYER_ENTERING_WORLD or PLAYER_SPECIALIZATION_CHANGED.

DISABLED

Called when the tracker disables itself. This is generally in response to PLAYER_SPECIALIZATION_CHANGED.

NEW_SPIRIT

Called when a new Storm, Earth, or Fire spirit is summoned.

Arguments

name
String - Name of the spirit (e.g. "Storm Spirit")
guid
String - GUID of the spirit
target
String - Name of the spirit's target
targetGUID
String - GUID of the spirit's target
icon
String - Texture for the spirit's icon

DEAD_SPIRIT

Called when a spirit disappears (is killed, kills its target, or is cancelled).

Arguments

name
String - Name of the spirit
guid
String - GUID of the spirit

SPIRIT_TARGET

Called when the player targets the same mob as one of the summoned spirits. If the player summons a spirit on their current target, this event will fire immediately after NEW_SPIRIT.

If the player is targeting one of their spirits' targets and switches to the other spirit's target, this event is fired a second time without an intervening SPIRIT_TARGET_END. Therefore do not expect them to always be balanced.

Arguments

name
String - Name of the spirit
guid
String - GUID of the spirit
target
String - Name of the spirit's target
targetGUID
String - GUID of the spirit's target

SPIRIT_TARGET_END

Called when the player is no longer targeting the same mob as one of the summoned spirits. This may be due to the player changing their target or the spirit dying.

When the spirit with the same target dies, this is fired after DEAD_SPIRIT.


Examples

Using callbacks

local tracker = LibStub("LibStormEarthAndFire-1.0")
tracker.RegisterCallback(myAddon, "ENABLED", function(event)
    print("LibStormEarthAndFire-1.0: enabled")
end)
tracker.RegisterCallback(myAddon, "DISABLED", function(event)
    print("LibStormEarthAndFire-1.0: disabled")
end)
tracker.RegisterCallback(myAddon, "NEW_SPIRIT", function(event, name, guid, target, targetGUID, icon)
    print("LibStormEarthAndFire-1.0: |T"..icon..":0|t " .. name .. " summoned on " .. target)
end)
tracker.RegisterCallback(myAddon, "DEAD_SPIRIT", function(event, name, guid)
    print("LibStormEarthAndFire-1.0: " .. name .. " died")
end)
tracker.RegisterCallback(myAddon, "SPIRIT_TARGET", function(event, name, guid, target, targetGUID)
    print("LibStormEarthAndFire-1.0: sharing a target with " .. name)
end)
tracker.RegisterCallback(myAddon, "SPIRIT_TARGET_END", function(event)
    print("LibStormEarthAndFire-1.0: no longer sharing a target")
end)