Module:Card

--[=[

Lua Module for Item Cards

--]=]

local p = {} local util = require("Module:Utility") local storylineData = mw.loadData( 'Module:Storyline/data' ) local EC = require("Module:EC").getEC local CHEST = require("Module:EnchantedChest").getChest local RARITY = require("Module:Rarity").rarity local TOK = require("Module:CharacterToken").getToken

local function costTable(cost, sale, alttext) local iCost = ' " end

function p.getCost(frame) local tArgs = util.getArgs(frame) return costTable(tArgs[1], nil, tArgs[2]) end

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

local iFile = "" local iLink = "" local iQuest = "" local iCost = "" local iDur = "" local span = "" local space = "" local iEvent = "default" if tArgs["event"] and storylineData["Colors"][tArgs["event"]:lower] then iEvent = tArgs["event"]:lower end

if tArgs["name"] then local name = tArgs["name"]

local conv = {["ch"] = "cp", ["cos"] = "cp"}

local iName, iDisp = mw.ustring.match(name, "^([^,]-)%s*#%s*(.-)$") if not iName then iName = name end local cData = mw.loadData("Module:ItemCollection/data")

if name:match(" Chests") then iFile = CHEST({name, 100}) iLink = CHEST({name, "L"}) elseif name:match("^XP") then iFile = EC({"XP", nil, nil, "I", 100}) iLink = "Level " .. (iDisp or "?") span = ' ' .. (iDisp or "?") .. ' '		elseif name:match("^EC%-") then iFile = EC({name, nil, nil, "I", 125}) iLink = EC({name, "L"}) elseif cData["Items"][iName] then local fName = iName:lower:gsub("[':%,%.]", ""):gsub(" ", "_") if cData["Items"][iName][2] == "pf" then fName = fName:gsub("_float$", "") else fName = fName:gsub("^([^%(]-)%/([^%(]-)$", "%1-%2") end local iDisp = iName:gsub("^([^%(]-)%/([^%(]-)$", "%2") iFile = "" if cData["Items"][iName]["C"] and cData["Categories"][cData["Items"][iName]["C"]] then local category = cData["Items"][iName]["C"] iFile = ' ' .. iFile .. '  '			end iLink =  .. (iDisp or iName) ..  else iFile = TOK({name, 125}) iLink = TOK({name, "L"}) if iEvent:match("^ts") then iFile = TOK({name, 60}) iLink = TOK({name, "S"}) iFile = ' ' .. iFile .. ' ' .. TOK({name, "C"}) .. ' '			end end end

if tArgs["quest"] then for onequest in mw.text.gsplit(tArgs["quest"], "%s*$%s*") do			local qName, qDisp = mw.ustring.match(onequest, "^([^,]-)%s*#%s*(.-)$") if not qName then qName = onequest end

if qDisp then qDisp = qName .. " Level " .. qDisp else if qName:match("^.+%#Part %d$") then local name, anch = qLink:match("^(.+)%#Part (%d+)$") if name:match("^.+ %(%d%)$") then qDisp = name:match("(.+) %(%d%)$") else qDisp = name end qDisp = qDisp .. ", Pt. " .. anch elseif qName:match("-" .. iEvent:upper) then qDisp = mw.ustring.gsub(qName, "-" .. iEvent:upper, "") elseif qName:match("^.+ %(%d%)$") then qDisp = qName:match("(.+) %(%d%)$") else qDisp = qName end end

iQuest = iQuest .. table.concat({space, "", qDisp, ""}) space = " " end iQuest = " " .. iQuest .. " "	elseif tArgs["text"] then iQuest = tArgs["text"] elseif tArgs["reward"] then iQuest = ' "	end

if tArgs["cost"] then local locked = require("Module:Available").unavailability iCost = locked(tArgs["duration"], costTable(tArgs["cost"], tArgs["sale"])) end

if tArgs["duration"] then local date = require('Dev:Date') if tArgs["duration"]:match("^%d%d%d%d%/%d%d%/%d%d$") then tArgs["duration"] = util.ordinal(date(tArgs["duration"]):fmt("%d")) .. " " .. date(tArgs["duration"]):fmt("%B") end iDur = ' ' end

local tOut = {'{| class="card ', iEvent, '" style="text-align: center; line-height: normal; border-spacing: 0px; color: white; text-shadow: 2.2px 2.2px 2px #020596; display: inline-table; margin: 0 3px 10px 0;"', '\n| style="width: 230px; height: 150px; background-size: cover; background-position: top; padding: 0 10px;"|', ' ' .. iFile .. ' ', '\n|-\n| style="width: 230px; height: 50px; background-size: cover; background-position: 0 -150px; padding: 0 10px;"|', " '''" .. iLink .. "''' ", '\n|-\n| style="width: 230px; height: 60px; background-size: cover; background-position: 0 -200px; padding: 0 10px;"|', iQuest, '\n|-\n| style="width: 230px; height: 75px; background-size: cover; background-position: 0 -260px; background-repeat: space; vertical-align: top; padding-top: 10px; padding: 0 10px;"|', iCost, '\n|-\n| style="background-size: cover;background-position: 0 -335px;background-repeat: space;"|', iDur, "\n|}"}

if iEvent:match("^ts") then tOut[ 2] = iEvent .. TOK({tArgs["name"], "R"}) tOut[ 4] = '\n| style="width: 230px; height: 80px; background-size: cover; background-position: top; padding: 0 10px;"|' tOut[ 5] = iFile tOut[ 6] = '\n|-\n| style="width: 230px; height: 55px; background-size: cover; background-position: 0 -80px; padding: 0 10px;"|' tOut[ 8] = '' tOut[10] = '\n|-\n| style="width: 230px; height: 60px; background-size: cover; background-position: 0 -140px; background-repeat: space; vertical-align: top; padding-top: 10px; padding: 0 10px;"|' tOut[11] = costTable(tArgs["cost"]) tOut[12] = '' end

if tArgs["name"]:match("^XP") then tOut[ 9] = iQuest tOut[11] = span end

return table.concat(tOut) end

return p