Module:UIText

--Get Required Modules local getArgs = require('Module:Arguments').getArgs local multiRequire = require('Module: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 = multiRequire('Module:Link/potion/Aliases', 'Module:Link/potion/Data', 'Module:Link/enchantmentsLink/Data', 'Module:Link/enchantmentsLink/Aliases')

--Begin Exports local p = {}

local characters = data.characters local statColors = data.statColors local conversions = data.conversions local rarityColors = data.rarityColors

for k, v in ipairs(potionData) do	potionData[k].color = v.color:gsub('([A-Z])', function(l)		return '_'..l:lower	end) 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') local function replaceRarities(rarity) local rarity = rarityAliases[string.trim((rarity:lower:gsub('%s', ' ')))] or formattedError('Invalid rarity escape "\\rarity{%s}"', 4, rarity) 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', ' ')] or formattedError('Invalid stat escape "\\stat{%s}"', 4, statname) return ('&%s%s%s %s&r'):format(conversions[statColors[stat]], prefix and prefix..' ' or '', characters[stat], string.ucfirst(stat)) end local function replacePotions(potion) local oldPot = potion local suffix = potion:match('%s+([ivxIVX%d]+)') local potPrefix = potion:match('%s*[Pp]oti?o?n?') local potion = potionAliases[string.trim(potion:gsub('%s+([ivxIVX%d]+)', ):gsub('%s+[Pp]oti?o?n?', ):lower)] or formattedError('Invalid potion escape "\\potion{%s}"', 4, potion) local n = string._toNumber(suffix or '') assertFalse(n and n > potionData[potion].maxLevel, 'Potion escape "\\potion{%s}" is out of range (max is %s, got %s)', 4, oldPot, potionData[potion].maxLevel, n)		return ('&%s%s%s%s&r'):format(conversions[potionData[potion].color:lower], potion, suffix and ' '..string._toRoman(suffix) or , potPrefix and ' Potion' or ) end local function replaceEnchants(enchant) local oldEnch = enchant local suffix = enchant:match('%s+([ivxIVX%d]+)') local enchant = enchantAliases[string.trim(enchant:gsub('%s+[Ee]ncha?n?t?m?e?n?t?s?', ):gsub('%s+([ivxIVX%d]+)', ):lower)] or formattedError('Invalid enchantment escape "\\enchant{%s}"', 4, enchant) local n = string._toNumber(suffix or '') 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)		:gsub('/', '\\/')		:gsub('\n', '/')		:gsub('\\r', '\r')		:gsub('\\t', '\t')		:gsub('\\v', '\v')		:gsub('\\b', '\b')		:gsub('\\n', '/')) end

- -- function: getRarityColor(rarity: string) -- -- Gets the In-game color code of a rarity - function p.getRarityColor(rarity) checkType(1, rarity, { 'string' }) return conversions[rarityColors[rarityAliases[string.trim((rarity:lower:gsub('%s', ' ')))]]] end --Finish Module/Exports return p