Module:EC

-- -- LUA script to get Currency for Enchanted Chests -- -- Parameters: -- 1: Currency = (Currency,count) --           count is optional -- 2: Size in pixels --     optional, defaults to 25 -- The list of available currency is kept in the module data -- -- Unknown Currency is returned if Currency Type is not in data. --

local p = {}

local currencyData = mw.loadData( 'Module:Currency/data' )

function p.getCurrency(frame)

local tArgs

if frame == mw.getCurrentFrame then fParent = frame:getParent tArgs = fParent.args

if (fParent.args[1]) then tArgs = fParent.args else tArgs = frame.args end else tArgs = frame end

local currency = tArgs[1] or "" local size = tArgs[2] if not size or size == "" then size = "25" end

currency = mw.ustring.gsub(mw.ustring.lower(currency),               "^%s*(.-)%s*$", "%1") or ''

local currencyFileAll = "" local space = ""

for cur in mw.text.gsplit(currency, "%s*!%s*") do

local currencyFile local currencyLink local cName, count = mw.ustring.match(cur,                            "^([^,]-)%s*,%s*(%d+)%s*,*%s*([\/%d]*)$")

if not cName then cName, count = mw.ustring.match(cur, "^([^,]-)%s*,%s*,*%s*([\/%d]*)$") if not cName then cName = cur end end

if currencyData[cName] and currencyData[cName][currencyType] then if currencyData[cName]["F"] then currencyFile = "[[File:" .. currencyData[cName]["F"]           else                currencyFile = "[[File:" .. currencyData[cName]            end            currencyFile = mw.ustring.gsub(currencyFile, " ", "_")            currencyLink = "|" .. currencyData[cName]["E"]                .. "|link="                .. currencyData[cName]["E"]                .. "]]"        else            currencyFile = "work_in_progress"            currencyLink = ""        end        currencyFileAll = currencyFileAll .. space            .. currencyFile .. ".png|x"            .. size            .. "px"            .. currencyLink

if count and count ~= "" then currencyFileAll = currencyFileAll .. "'''" .. count .. "'''"       end

space = " " end return currencyFileAll end

return p