Module:Gemstone

local p = {}

local loader = require('Module:Loader') local getArgs = require('Module:Arguments').getArgs local mergeArgsSyntax = require('Module:Arguments').mergeArgsSyntax local string, table = loader.require('String', 'Table') local gemstoneData, gemstoneAliases = loader.loadData('Gemstone/Data', 'Gemstone/Aliases')

local slots = gemstoneData.slots local gemstone_names = gemstoneData.names

function p.gemstoneSlotText(frame) local args = getArgs(frame) return p._gemstoneSlotText(args[1]) end

function p._gemstoneSlotText(slotName) local slot = slots[gemstoneAliases[slotName:lower]] local str = (' %s %s Slot'):format(slot.colorClass, slot.icon, slot.slotName) return str end

function p.gemstoneSlot(frame) local args = getArgs(frame) local text = args[1] return p._gemstoneSlots(text) end

function p._gemstoneSlot(str) local noError = false local slotName = str, cost if slotName:match('^(.*) &(.*)&') then slotName, cost = slotName:match('^(.*) &(.*)&') end local slot = slots[gemstoneAliases[slotName:lower]] local applicableText = '' if slot.applicable then applicableText = 'Applicable Gemstones:/' .. slot.applicable end local costText = '' local lockedIcon = '' if cost then local splitCost = mw.text.split(cost, ',', true) for i, val in ipairs(splitCost) do			splitCost[i] = mw.text.trim(splitCost[i]) -- if it's a number the cost is coins if tonumber(splitCost[i], 10) then splitCost[i] = '&6' .. string._formatNum(splitCost[i]) .. ' coins&r' else -- otherwise it's a gemstone and should be colored to match for j, gemstone in ipairs(gemstone_names) do					if splitCost[i]:lower:find(gemstone, 0, true) then -- if cost contains gemstone name, use that color splitCost[i] = slots[gemstone].ttColor .. splitCost[i] .. '&r' end end end end costText = (applicableText ~=  and '//' or ) .. 'Cost to unlock:/' .. table.concat(splitCost, '/') lockedIcon = ' ' end return string.wrapHtml{  .. slot.icon .. lockedIcon .. , ' ', {			class = 'minetip gemstone-slot color-' .. slot.colorClass, ['data-minetip-title'] = table.concat{ slot.ttColor, slot.icon, ' ', slot.slotName, ' Gemstone Slot' }, ['data-minetip-text'] = applicableText .. costText, }	} end

return p