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')

-- Gemstone Data local slots = { -- Normal Slots ruby = { icon="❤", color="#F55", ttColor="&c", slotName="Ruby" }, amethyst = { icon="❈", color="#A0A", ttColor="&5", slotName="Amethyst" }, jade = { icon="☘", color="#5F5", ttColor="&a", slotName="Jade" }, sapphire = { icon="✎", color="#5FF", ttColor="&b", slotName="Sapphire" }, amber = { icon="⸕", color="#FA0", ttColor="&6", slotName="Amber" }, topaz = { icon="✧", color="#FF5", ttColor="&e", slotName="Topaz" }, jasper = { icon="❁", color="#F5F", ttColor="&d", slotName="Jasper" }, -- Special Slots combat = { icon="⚔", color="#A00", ttColor="&4", slotName="Combat", applicable={ "&cRuby&r", "&5Amethyst&r", "&bSapphire&r", "&dJasper&r" } }, offensive = { icon="☠", color="#55F", ttColor="&9", slotName="Offensive", applicable={ "&bSapphire&r", "&dJasper&r" } }, defensive = { icon="☤", color="#5F5", ttColor="&a", slotName="Defensive", applicable={ "&cRuby&r", "&5Amethyst&r" } }, mining = { icon="✦", color="#A0A", ttColor="&5", slotName="Mining", applicable={ "&aJade&r", "&6Amber&r", "&eTopaz&r" } }, universal = { icon="❂", color="white", ttColor="&f", slotName="Universal", applicable={ "&aAny&r" } }, } -- note: these should match the slot names above local gemstone_names = { 'ruby', 'amethyst', 'jade', 'sapphire', 'amber', 'topaz', 'jasper' }

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[slotName:lower] local applicableText = '' if slot.applicable then applicableText = "Applicable Gemstones:/"..table.concat(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', style={ ['color'] = slot.color }, ['data-minetip-title']=table.concat{ slot.ttColor, slot.icon, " ", slot.slotName, " Gemstone Slot" }, ['data-minetip-text']=applicableText..costText, }	} end

return p