Module:UIText

--Get Required Modules local getArgs = require('Module:Arguments').getArgs local multiRequire = require('Module:MultiRequire').multiRequire local string, table, lu, yesno = multiRequire('Module:String', 'Module:Table', 'Module:LibraryUtil', 'Module:Yesno') local statAliases, rarityAliases, rarityData, data = multiRequire('Module:Statname/aliases', 'Module:RarityTier/Aliases', 'Module:RarityTier/Data', 'Module:UIText/Data') local potionAliases, potionData, enchantData, enchantAliases, colorAliases = multiRequire('Module:Link/potion/Aliases', 'Module:Link/potion/Data', 'Module:Link/enchantmentsLink/Data', 'Module:Link/enchantmentsLink/Aliases', "Module:Color/Aliases") --Begin Exports local p = {}

local characters = data.characters				-- p.getStatCharacter local statColors = data.statColors				-- p.getStatColor local rarityColors = data.rarityColors			-- p.getRarityColor local tooltipFormatting = data.tooltipFormatting-- p.getTooltipFormatting -- p.getColorCodes

for k, v in ipairs(potionData) do	potionData[k].color = v.color:gsub('([A-Z])', function(l)		return '_'..l:lower	end) end

function p.applyReplacements(val) local function replaceRarities(rarityName) local rarity = rarityAliases[string.trim((rarityName:lower:gsub('%s', ' ')))] if not stat then return "\\rarity{" ..rarityName.. "}"		end return ('&%s&l%s&r'):format(p.getRarityColor(rarity), rarityData[rarity].name) end local function replaceStats(statname) local prefix = statname:match('^([%-%+]?[%.%dkm,]+%%?)%s*') statname = string.trim((statname:gsub('^([%-%+]?[%.%dkm,]+%%?)%s*', ''))) stat = statAliases[statname:lower:gsub('%s', ' ')] if not stat then return "\\stat{" ..statname.. "}"		end return ('&%s%s%s %s&r'):format(tooltipFormatting[statColors[stat]], prefix and prefix..' ' or '', characters[stat], string.ucfirst(stat)) end local function replacePotions(potionName) local oldPot = potion local suffix = potion:match('%s+([ivxIVX%d]+)') local potPrefix = potion:match('%s*[Pp]oti?o?n?') local potion = potionAliases[string.trim(potionName:gsub('%s+([ivxIVX%d]+)', ):gsub('%s+[Pp]oti?o?n?', ):lower)] local n = string._toNumber(suffix or '') if not potion or (n and n > potionData[potion].maxLevel) then return '\\potion{'..potionName..'}' end return ('&%s%s%s%s&r'):format(tooltipFormatting[potionData[potion].color:lower], potion, suffix and ' '..string._toRoman(suffix) or , potPrefix and ' Potion' or ) end local function replaceEnchants(enchantName) local oldEnch = enchantName local suffix = enchantName:match('%s+([ivxIVX%d]+)') local enchant = enchantAliases[string.trim(enchantName:gsub('%s+[Ee]ncha?n?t?m?e?n?t?s?', ):gsub('%s+([ivxIVX%d]+)', ):lower)] local n = string._toNumber(suffix or '') if not enchant then return '\\enchant{'..enchantName..'}' end assertFalse(n and n > enchantData[enchant].max, 'Enchantment escape "\\enchant{%s}" is out of range (max is %s, got %s)', 4, oldEnch, enchantData[enchant].max, n)		return ('&9%s%s&r'):format(enchant, suffix and ' '..string._toRoman(suffix) or '') end return (string.unicodeConvert(val)		:gsub('\\sta?t?%{(.-)%}', replaceStats)		:gsub('\\poti?o?n?%{(.-)%}', replacePotions)		:gsub('\\ra?r?i?t?y?%{(.-)%}', replaceRarities)		:gsub('\\ench?a?n?t?m?e?n?t?%{(.-)%}', replaceEnchants)	) end - -- Temlate: UIText -- -- Makes making UI's alot easier - function p.main(frame) local args = getArgs(frame) local val = args[1] or args["t"] or args["text"]

return string.pcall(p._main, val) end - -- Template: UIText Module access point - function p._main(val) checkType(1, val, 'string') return (p.applyReplacements(val)		:gsub('/', '\\/')		:gsub('\n', '/')		:gsub('\\r', '\r')		:gsub('\\t', '\t')		:gsub('\\v', '\v')		:gsub('\\b', '\b')		:gsub('\\n', '/')	) end

- -- function: getStatCharacter(statname: string) -- -- Gets the unicode character of a stat - function p.getStatCharacter(statname) checkType(1, statname, { 'string' }) return tooltipFormatting[characters[statAliases[string.trim(statname:lower):gsub('%s', ' ')]]] end

- -- function: getStatColor(statname: string, raw: boolean) -- -- Gets the In-game color code of a stat (if raw, returns the color instead) - function p.getStatColor(statname, raw) checkType(1, statname, { 'string' }) raw = raw or false local statColor = statColors[statAliases[string.trim(statname:lower):gsub('%s', ' ')]] return raw and statColor or tooltipFormatting[statColor] end

- -- function: getRarityColor(rarity: string, raw: boolean) -- -- Gets the In-game color code of a rarity (if raw, returns the color instead) - function p.getRarityColor(rarity, raw) checkType(1, rarity, { 'string' }) raw = raw or false local rarityColor = rarityColors[rarityAliases[string.trim(rarity:lower):gsub('%s', ' ')]] return raw and rarityColor or tooltipFormatting[rarityColor] end

- -- function: getColorCode(color: string) -- -- Gets the In-game color code of a color (if raw, returns the color instead) - function p.getColorCode(color, raw) checkType(1, color, { 'string' }) raw = raw or false local color = colorAliases[string.trim(color:lower):gsub('%s', '_')] return raw and color or tooltipFormatting[color] end

- -- function: getTooltipFormatting(color: string, text: string, ampersand: boolean) -- -- Gets the In-game tooltip formatting -- (If there is text, will wrap with &..color..text, this can be overridden) -- Also works for stats, rarities and colors - function p.getTooltipFormatting(color, text, ampersand) checkType(1, color, { 'string', 'table' }) checkType(2, text, { 'string', 'table', 'number' }, true) amp = ampersand or (text and true or false) local code color = string.trim(string.lower(color)) code = tooltipFormatting[string.gsub(color, '%s', '_')] or p.getStatColor(color) or p.getRarityColor(color) return (amp and code and '&' or )..(code or color)..(text or ) end

--Finish Module/Exports return p