--Use lib stub to figure out if the same or higher version was already used
local major, minor = "LibConstantMapper", 0.2
local lib = LibStub:NewLibrary(major, minor)
if not lib then
return
end
function lib:getMappedData(pattern, exclude)
--Sanity check on values
assert(pattern ~= nil and type(pattern) == "string", "pattern must not be nil and of type string")
assert(exlcude == nil or type(exclude) == "string", "exclude must be nil or of type string")
local result = {}
--For every entry in the Global table
for key, value in zo_insecurePairs(_G) do
--Compare it to the given mapping
if (key):find(pattern) and (exclude == nil or not(key):find(exclude)) then
--found a Value for this mapping, so store it in the result table
local newentry = { key = key, value = value}
table.insert(result, newentry)
end
end
return result
end
function lib:getDataByMapping(map_name)
local map = self:getMap(map_name)
assert (map ~= nil and map ~= {}, "A mapping named '" .. map_name .. "' could not be found")
--If all worked out so far, let getMappedData do it's job
return self:getMappedData(map.pattern, map.exclude)
end
--Functions and Data related to the maps
function lib:listMaps()
local result = {}
for key, value in pairs(self.__maps) do
table.insert(result, key)
end
return result
end
function lib:addMap(map, pattern, exclude)
if(self.__maps == nil) then
self.__maps = {}
end
assert(map ~= nil or type(map) == "string", "map must not be nil and of type string")
assert(pattern ~= nil and type(pattern) == "string", "pattern must not be nil and of type string")
assert(exlcude == nil or type(exclude) == "string", "exclude must be nil or of type string")
self.__maps[map] = { pattern = pattern, exclude = exclude }
end
function lib:getMap(map)
assert(map ~= nil or type(map) == "string", "map must not be nil and of type string")
return self.__maps[map]
end
--Predefined mappings
local ConstantMapperMappings = {
{ mapping = "ChatCategories", pattern = "^CHAT_CATEGORY_", exclude = "^CHAT_CATEGORY_HEADER" },
{ mapping = "ChatChannels", pattern = "^CHAT_CHANNEL_"},
{ mapping = "Events", pattern = "^EVENT_"},
{ mapping = "EventsAbility", pattern = "^EVENT_ABILITY_" },
{ mapping = "EventsAchievement", pattern = "^EVENT_ACHIEVEMENT_"},
{ mapping = "EventsAction", pattern = "^EVENT_ACTION_"},
{ mapping = "EventsActive", pattern = "^EVENT_ACTIVE_"},
{ mapping = "EventsAddOn", pattern "^EVENT_ADD_ON_" },
{ mapping = "EventsAgentChat", pattern "^EVENT_AGENT_CHAT_" },
{ mapping = "EventsAlliancePoint", pattern "^EVENT_ALLIANCE_POINT_" },
{ mapping = "EventsArtifact", pattern "^EVENT_ARTIFACT_" },
{ mapping = "EventsAssignedCampaign", pattern "^EVENT_ASSIGNED_CAMPAIGN_" },
{ mapping = "EventsAttribute", pattern "^EVENT_ATTRIBUTE_" },
{ mapping = "EventsAvenge", pattern "^EVENT_AVENGE_" },
{ mapping = "EventsBankIs", pattern "^EVENT_BANK_IS_" },
{ mapping = "EventsBankedMoney", pattern "^EVENT_BANKED_MONEY_" },
{ mapping = "EventsBattleStandards", pattern "^EVENT_BATTLE_STANDARDS_" },
{ mapping = "EventsBegin", pattern "^EVENT_BEGIN_" },
{ mapping = "EventsBosses", pattern "^EVENT_BOSSES_" },
{ mapping = "EventsBroadcast", pattern "^EVENT_BROADCAST" },
{ mapping = "EventsBuy", pattern "^EVENT_BUY_" },
{ mapping = "EventsBuyback", pattern "^EVENT_BUYBACK_" },
{ mapping = "EventsCampaign", pattern "^EVENT_CAMPAIGN_" },
{ mapping = "EventsCancel", pattern "^EVENT_CANCEL_" },
{ mapping = "EventsCannot", pattern "^EVENT_CANNOT_" },
{ mapping = "EventsCapsLock", pattern "^EVENT_CAPS_LOCK_STATE_" },
{ mapping = "EventsCaptureArea", pattern "^EVENT_CAPTURE_AREA_" },
{ mapping = "EventsChatChannel", pattern "^EVENT_CHAT_CHANNEL_" },
{ mapping = "EventsChatLog", pattern "^EVENT_CHAT_LOG_" },
{ mapping = "EventsChatMessage", pattern "^EVENT_CHAT_MESSAGE_" },
{ mapping = "EventsChatter", pattern "^EVENT_CHATTER_" },
{ mapping = "EventsClose", pattern "^EVENT_CLOSE_" },
{ mapping = "EventsCombat", pattern "^EVENT_COMBAT_" },
{ mapping = "EventsConfirm", pattern "^EVENT_CONFIRM_" },
{ mapping = "EventsConversation", pattern "^EVENT_CONVERSATION_" }
}
for i=1, #ConstantMapperMappings, 1 do
local currentMap = ConstantMapperMappings[i]
lib:addMap(currentMap.mapping, currentMap.pattern, currentMap.exclude)
end