Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
No edit summary
No edit summary
Line 43: Line 43:
 
if bit.band(flags, v.id) > 0 then
 
if bit.band(flags, v.id) > 0 then
 
local baseName = GetApiBaseName(name)
 
local baseName = GetApiBaseName(name)
local url = v.url:formatbaseName()
+
v.url = v.url:format(baseName)
v.icon = v.icon:format(url)
+
v.icon = v.icon:format(v.url)
 
table.insert(t, v)
 
table.insert(t, v)
 
end
 
end

Revision as of 07:22, 10 June 2021

Documentation for this module may be created at Module:API info/flavor/doc

local bit = require "bit32"
local data = {
	a = mw.loadData("Module:API_info/flavor_api"),
	e = mw.loadData("Module:API_info/flavor_event"),
}
local m = {}

-- cant use dots in github search
-- https://docs.github.com/en/github/searching-for-information-on-github/searching-on-github/searching-code#considerations-for-code-search
local function GetApiBaseName(v)
	if v:find("%.") then
		v = v:match(".-%.(.+)")
	end
	return v
end

local flavors = {
	{
		id = 0x1,
		label = "retail",
		icon = "[[File:Shadowlands-Logo-Small.png|32px|link=%s]]",
		url = "https://github.com/Gethe/wow-ui-source/search?q=%s",
	},
	{ -- show bcc before classic_era
		id = 0x4,
		label = "bcc",
		icon = "[[File:Bc icon.gif|32px|link=%s]]",
		url = "https://github.com/Ketho/wow-ui-source-bcc/search?q=%s",
	},
	{
		id = 0x2,
		label = "classic_era",
		icon = "[[File:WoW Icon update.png|link=%s]]",
		url = "https://github.com/Ketho/wow-ui-source-classic-era/search?q=%s",
	},
}

function m:GetFlavors(name, apiType)
	local flags = data[apiType][name]
	if flags then
		local t = {}
		for _, v in pairs(flavors) do
			if bit.band(flags, v.id) > 0 then
				local baseName = GetApiBaseName(name)
				v.url = v.url:format(baseName)
				v.icon = v.icon:format(v.url)
				table.insert(t, v)
			end
		end
		return t
	end
end

return m