AddOn Bazaar
From WoWWiki
Bazaar is an addon that makes syncing addon configurations between users easier by doing the heavy lifting of communicating the syncs and changing the data into a format that can be sent through addon channels.
This is not a library and cannot be embedded, you will have to add Bazaar as an optional dependency to your TOC file and check if it was loaded before registering, users can download Bazaar at the below link if they are using an addon that supports Bazaar.
Download Bazaar at WoWInterface
Contents |
Bazaar API
Bazaar:RegisterAddOn(name)
Args
| Arg | Type | Details |
|---|---|---|
| key | string | Category key for seeing if it was selected |
| name | string | Addon folder name |
Returns
| Return | Type | Details |
|---|---|---|
| BazaarObj | table | The Bazaar Object encapsulating the Bazaar API's. |
Bazaar Object API
BazaarObj:RegisterCategory(key, displayName)
Args
| Arg | Type | Details |
|---|---|---|
| key | string | Category key for seeing if it was selected |
| displayName | string | Display name for the category when selected categories to sync |
Remarks
Registers a category of configuration for this BazaarObj.
The characters \001 - \004 are reserved for communications handling.
Bazaar specifically makes sure the categories are valid before syncing them, meaning if in the future you add another one or remove it we won't let the user sync those categories with someone using a newer or older version.
BazaarObj:RegisterSendHandler(handler[, func])
Args
| Arg | Type | Details |
|---|---|---|
| handler | string/function/table | Function/method to call. |
| func | string/function | (Optional) Function to call if you're using a handler |
Remarks
Registers the passed handler/function to be called when we need the data that should be serialized and synced.
If you passed just a function it'll be called as func(categories) If you passed a handler and a function it'll be called as handler[func](handler, categories)
categories is a dictionary table of the category keys that were selected.
The send handler MUST return either a string, number, table or boolean it's recommended you use a table as that's easier to work with when you need to load the data in the receive handler.
BazaarObj:RegisterReceiveHandler(handler[, func])
Args
| Arg | Type | Details |
|---|---|---|
| handler | string/function/table | Function/method to call. |
| func | string/function | (Optional) Function to call if you're using a handler |
Remarks
Registers the passed handler/function to be called when we have data that was packed from the send handler
If you passed just a function it'll be called as func(data, categories) If you passed a handler and a function it'll be called as handler[func](handler, data, categories)
categories is a dictionary table of the category keys that were selected.
If you return a string from the receive handler then a custom message will be displayed when the configuration syncing is done, you can use this if you need to give any additional information to the user like they might have to reload the interface.
Example
The below is an example of a simple implementation of Bazaar support.
if( IsAddOnLoaded("Bazaar") ) then
local Config = {}
function Config:Receive(data, categories)
for key in pairs(categories) do
Foo.db.profile[key] = data[key]
end
Foo:Reload()
end
function Config:Send(categories)
local config = {}
for key in pairs(categories) do
config[key] = CopyTable(Foo.db.profile[key])
end
return config
end
local obj = Bazaar:RegisterAddOn("Afflicted")
obj:RegisterCategory("general", "General")
obj:RegisterCategory("frames", "Frames")
obj:RegisterCategory("apples", "Apples")
obj:RegisterReceiveHandler(Config, "Receive")
obj:RegisterSendHandler(Config, "Send")
end
