SharedMedia-1.0

From WowAce Wiki
Jump to: navigation, search

SharedMediaLib is a library for shared handling of media data (fonts, sounds, textures, ...) between addons.

API Documentation

:Register(type, handle, data)

Registers a new handle of given type.

Args

type 
string - the type of the data, eg. font or statusbar
handle 
string - the handle to get the data from the lib
data 
string - the data to associate with the handle; normaly a filename

Returns

none

:Fetch(type, handle)

Fetches the data for the given handle and type.

Args

type 
string - the type of the data, eg. font or statusbar
handle  
string - the handle to get the data from the lib

Returns

string or nil - the current overrite handle's data, the requested handle's data, the default handle's data or nil

:HashTable(type)

Gets a hash table {data -> handle} to eg. iterate over.

Args

type 
string - the type of the data, eg. font or statusbar

Returns

table - hash table for the given type

:List(type)

Gets a sorted list of handles.

Args

type  
string - the type of the data, eg. font or statusbar

Returns

table - list of handles for the given type

:SetGlobal(type [, handle])

Sets or clears a handle that will be returned on fetch instead of the requested handle

Args

type  
string - the type of the data, eg. font or statusbar
[handle] 
string - the handle of the data

Returns

none

:GetGlobal(type)

Returns the prior set overrite handle.

Args

type 
string - the type of the data, eg. font or statusbar

Returns

string or nil - the current overrite handle for the given type

:Usage(type)

Returns a concatenated string of handles.

Args

type 
string - the type of the data, eg. font or statusbar

Returns

string - a concatenation of the handles for the given type; form: {handle || handle || handle} [edit]

:IsValid(type [, handle])

Checks if the given type (and handle) is valid.

Args

type 
string - the type of the data, eg. font or statusbar
[handle] 
string - the handle of the data

Returns

boolean - true if the type (and handle) is valid

:SetDefault(type, handle)

Sets a default return value for nonexistant handles. Won't replace an already set default.

Args

type 
string - the type of the data, eg. font or statusbar
handle 
string - the handle of the data

Returns

none

AceEvent events fired

SharedMedia_Registered

fires when a new handle was successfully registered

Args

type 
the type of the new handle
handle 
the name of the handle

SharedMedia_SetGlobal

fires when a overrite handle was set/cleared

Args

type 
the type of the new handle
handle 
the name of the handle; nil if the overrite handle was cleared

MediaType constants

The library has some build-in constants for media types that can be used in an addon. These are only some official suggestions on types. Feel free to suggest more.

constantvalueused for
<lib>.MediaType.FONT          font                     fonts
<lib>.MediaType.STATUSBAR     statusbar                statusbar textures

Predefined data

The following data is predefined inside the library. There is no need to define it again yourself. (default handle)

MediaType FONT

Arial Narrow             Fonts\\ARIALN.TTF
Friz Quadrata TT         Fonts\\FRIZQT__.TTF
Morpheus                 Fonts\\MORPHEUS.TTF
Skurri                   Fonts\\SKURRI.TTF

MediaType STATUSBAR

Blizzard                 Interface\\TargetingFrame\\UI-StatusBar

Naming Conventions

General

  • Don't create subnamespaces by prefixing names.
  • Try to give descriptive handle names. Example: "Alert" wouldn't be a good name for a sound even if you intend it for alerting the user.

MediaType FONT

Fonts should be added with the exact name defined in the ttf as handle.