Module:EC

--[==[ Lua script to get Currency Icon Numbered Parameters: 1: Currency = (Currency,count) count is optional count can include "," only first "," separates fields multiple separated by "$" (dollar sign) 2: Include Name/Text Link (Optional) N = Currency Name E = "Event Currency" e = "event currency" A = Alternate Text L = Currency Name link (without Icon) uses Alternate Text if present T = Currency Name text only (without Icon) 3: Alternate Text (Optional) 4: Icon or Image (Optional) Display Image file if present 5: Size in pixels (Optional) for Icon default 25 for Image default 50 Other Parameters: S: If present then use Singular Name as text

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:EC/data' ) local util = require("Module:Utility")

function p.getEC(frame) local tArgs = util.getArgs(frame)

local currency = tArgs[1] or "" local inclName = tArgs[2] or "" local altText = tArgs[3] or "" local imgType = tArgs[4] or "" local size    = tArgs[5]

if not size or size == "" then size = "27" if imgType ~= "" then size = "50" end end

local imgSize = ".png|" .. size .. "x" .. size .. "px|"

if not imgType or imgType == "" then imgType = "I" end

if imgType == "C" then imgSize = ".png|x" .. size .. "px|" end

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

local currencyFileAll = "" local space = "" local singular = nil

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

local cName, count = mw.ustring.match(cur,                            "^([^,]-)%s*[,%#]%s*([%/%,%d%?%-]*)$")

if not cName then cName = cur end -- strip "EC-" from start of name cName = mw.ustring.gsub(cName, "^ec%-", "")

local imageFile = "work_in_progress" .. imgSize       local imageLink = cName .. "" local nameText = "Work In Progress"

if currencyData[cName] then local data = currencyData[cName]

-- check for Alias, switch to Alias if present if data.A and currencyData[data.A] then data = currencyData[data.A]       	end

imageFile = "[[File:" .. mw.ustring.gsub(data[imgType] or data["I"], " ", "_")

if data.N then nameText = data.N               imageLink = nameText .. "|link=" .. nameText .. "]]"           end

if data.D then dispText = data.D           end

singular = data.S       end

local nameLink = "" local dispIcon = 1 local bracket = nil

if mw.ustring.match(inclName, "^[NEeALTP]$") then if inclName == "N" then nameLink = "" .. nameText .. "" elseif inclName == "E" then nameLink = "Event Currency" elseif inclName == "e" then nameLink = "event currency" elseif inclName == "T" then nameLink = nameText if tArgs.S and not singular then nameLink = nameText:gsub("[Ss]$", "") end elseif inclName == "A" or inclName == "L" then nameLink = "" .. dispText               elseif altText ~= "" then                    nameLink = nameLink .. "|" .. altText                elseif tArgs.S and not singular then                	nameLink = nameLink .. "|" .. nameText:gsub("[Ss]$", "")                end                nameLink = nameLink .. "" end

if inclName == "L" or inclName == "T" then dispIcon = nil elseif inclName ~= "P" then bracket = 1 end end

currencyFileAll = currencyFileAll .. space .. nameLink

if dispIcon then if bracket then currencyFileAll = currencyFileAll .. " ("           end

currencyFileAll = currencyFileAll .. imageFile .. imgSize .. imageLink

if bracket then currencyFileAll = currencyFileAll .. ") "           end

local pName = mw.title.getCurrentTitle.text

if count and count ~= "" then currencyFileAll = ' ' .. currencyFileAll .. " " .. count .. ' '           end end if inclName == "P" then currencyFileAll = currencyFileAll .. " " .. nameText .. " " space = " " elseif count or inclName == "L" or inclName == "T" then space = ", " else space = " " end end return currencyFileAll end

-- function to get link to Last EC page function p.getLastEC

local lteData = mw.loadData( 'Module:LTEvent/data' ) local lastMegaID = "" local lastDate = ""

for k, v in pairs(lteData["N"]) do   	if lastDate == "" then lastDate = v[3] end if (lastDate <= (v[3] or "")) then lastDate = v[3] lastMegaID = k       end end

return p.getEC({lastMegaID, "L"}) end

return p