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 getCard(name, text, rewards, quest, cost, sale, duration, event) local iFile = "" local iLink = "" local iQuest = text or "" local iReward = nil local iCost = "" local iDur = "" local iEvent = "default" if event and storylineData["Colors"][event:lower] then iEvent = event:lower elseif event and (event:match("^ts") or event:match("token$")) then iEvent = event end

local span = "" local space = ""

if name then 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("^EC%-") then iFile = EC({iName, nil, nil, "C", 60}) iLink = iDisp or EC({iName, "L"}) elseif cData["Items"][iName] then local fname = mw.ustring.gsub(mw.ustring.lower(iName), "[':\"%,%.]", "")			fname = fname:gsub(" ", "_")			if cData["Items"][iName][2] == "pf" then				fname = fname:gsub("_float$", "")			else				fname = fname:gsub("^([^%(]-)%/([^%(]-)$", "%1-%2")				fname = mw.ustring.gsub(fname, "^([^%(]-) *%(([^%(]-)%)$", "%1_%2")			end			local iDisp = (iDisp or 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, 55})			iLink = TOK({name, "S"})			iFile = ' ' .. iFile .. ' ' .. TOK({name, "C"}) .. '  '			if not iEvent:match("^ts") then iEvent = iEvent .. "token" end		end	end

if quest and quest:match("^Limit\:") then iQuest = "'" .. quest .. "'"	elseif quest then for onequest in mw.text.gsplit(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 rewards then iReward = ' "	end

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

if duration then local date = require('Dev:Date') if duration:match("^%d%d%d%d%/%d%d%/%d%d$") then duration = util.ordinal(date(duration):fmt("%d")) .. " " .. date(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: 210px; height: 140px; background-size: cover; background-position: top; padding: 0 9px 0 4px; padding: 5px 0 0 0;"|', ' ' .. iFile .. ' ', '\n|-\n| style="width: 210px; height: 45px; background-size: cover; background-position: 0 -140px; padding: 0 9px 0 4px; vertical-align: top;"|', " '''" .. iLink .. "''' ", '\n|-\n| style="width: 210px; height: 60px; background-size: cover; background-position: 0 -185px; padding: 0 9px 0 4px; vertical-align: top;"|', iReward or iQuest, '\n|-\n| style="width: 210px; height: 60px; background-size: cover; background-position: 0 -245px; background-repeat: space; vertical-align: top; padding-top: 10px; padding: 0 9px 0 4px; line-height: 1.0;"|', iCost, '\n|-\n| style="background-size: cover;background-position: 0 -305px;background-repeat: space;"|', iDur, "\n|}"}

if iEvent:match("^ts") or iEvent:match("token$") then tOut[ 4] = '\n| style="width: 210px; height: 65px; background-size: cover; background-position: top; padding: 0 9px 0 4px; vertical-align: bottom;"|' tOut[ 5] = iFile tOut[ 6] = '\n|-\n| style="width: 210px; height: 17px; background-size: cover; background-position: 0 -65px; padding: 0 9px 0 4px;"|' tOut[ 7] = (iQuest~="" and (" ''" .. iQuest .. "'' ") or RARITY({TOK({name, "R"}), "S", 15})) tOut[ 8] = '\n|-\n| style="width: 210px; height: 40px; background-size: cover; background-position: 0 -82px; padding: 0 9px 0 4px;"|' tOut[ 9] = " '''" .. iLink .. "''' "		tOut[10] = '\n|-\n| style="width: 210px; height: 54px; background-size: cover; background-position: 0 -126px; padding: 0 9px 0 4px; vertical-align: top;"|' tOut[11] = iReward or iCost tOut[12] = '\n|-\n| style="background-size: cover;background-position: 0 -180px;background-repeat: space;"|' end

return table.concat(tOut) end

function getTSCards(tArgs) local tOut = {}

for arg, value in pairs(tArgs) do		if arg ~= "event" then local tRow = {"===", arg, " Tokens===\n"} for token in mw.text.gsplit(value, "%s*$%s*") do if arg == "Fabric" or arg == "Relic" then token = arg .. " " .. token end table.insert(tRow, getCard(token, nil, nil, nil, ("EC-Elixirs #" .. TOK({token, "E"})), nil, nil, ("ts" .. TOK({token, "R"})))) table.insert(tRow, "\n") end table.insert(tOut, table.concat(tRow)) end end

return " \n" .. table.concat(tOut) .. " \n" end

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

if tArgs["event"] and tArgs["event"] == "ts" then return getTSCards(tArgs) else return getCard(tArgs["name"], tArgs["text"], tArgs["reward"], tArgs["quest"], tArgs["cost"], tArgs["sale"], tArgs["duration"], tArgs["event"]) end end

return p