Module:API info/flavor ambox

From Warcraft Wiki
Jump to navigation Jump to search

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

local flavor_module = require("Module:API_info/flavor")
local patch_module = require("Module:API_info/patch")
local group_module = require("Module:API_info/group")
local m = {}

local info = {
	vanilla = {
		border = "yellow",
		image = "[[File:WoW Classic logo.png|128px|Classic Era|link=]]",
	},
	cata = {
		border = "blue",
		image = "[[File:WoW_Cataclysm_Classic_logo.png|80px|Cata Classic|link=]]",
	},
	none = {
		border = "red",
		image = "[[File:Inv mushroom 11.png|32px|shroom|link=]]",
		type = "'''This no longer exists on any flavor of the game.'''",
	}
}

function m:GetAmbox(f, name)
	local flags, mainline, vanilla, cata = flavor_module:GetFlavorInfo(f.args.t, name)
	local added = patch_module:GetPatches(f.args.t, name)
	-- dont show ambox when group infobox is already shown
	if #added > 0 and not group_module:GetData(name) then
		local template = {title = "Ambox"}
		if (vanilla or cata) and not mainline then
			template.args = info[cata and "cata" or vanilla and "vanilla"]
			local expansions = {}
			if cata then
				table.insert(expansions, "''[[World_of_Warcraft:_Cataclysm_Classic|Cata Classic]]''")
			end
			if vanilla then
				table.insert(expansions, "''[[World of Warcraft: Classic|Classic Era]]''")
			end
			template.args.type = string.format("'''This API only exists in %s.'''", table.concat(expansions, " and "))
		elseif not flags then
			template.args = info.none
		end
		if template.args then
			template.args.style = "width: auto; margin-left: 0.8em;"
			local expanded = f:expandTemplate(template)
			if template.args == info.none then
				expanded = "[[Category:API functions/Noflavor]]\n"..expanded
			end
			return expanded
		end
	end
end

return m