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 iCost = "" local iDur = "" local iEvent = "default" if event and storylineData["Colors"][event:lower] then iEvent = event:lower elseif event and event:match("^ts") and not name:match("^XP") 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("^XP") then iFile = EC({"XP", nil, nil, "I", 90}) iLink = "Level " .. (iDisp or "?")

iFile = ' ' .. iFile .. ' ' .. (tonumber(iDisp)<10 and (iDisp .. ".") or 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 = 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, 125})			iLink = TOK({name, "L"})			if iEvent:match("^ts") then				iFile = TOK({name, 55})				iLink = TOK({name, "S"})				iFile = ' ' .. iFile .. ' ' .. TOK({name, "C"}) .. '  '			end		end	end

if quest and quest:match("^Limit\:") then --		iQuest = ' .. quest .. ' '		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 iQuest = ' "	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 10px; padding: 5px 0 0 0;"|', ' ' .. iFile .. ' ', '\n|-\n| style="width: 210px; height: 45px; background-size: cover; background-position: 0 -140px; padding: 0 10px; vertical-align: top;"|', " '''" .. iLink .. "''' ", '\n|-\n| style="width: 210px; height: 60px; background-size: cover; background-position: 0 -185px; padding: 0 10px; vertical-align: top;"|', 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 10px;"|', iCost, '\n|-\n| style="background-size: cover;background-position: 0 -305px;background-repeat: space;"|', iDur, "\n|}"}

if iEvent:match("^ts") then tOut[ 4] = '\n| style="width: 210px; height: 80px; background-size: cover; background-position: top; padding: 0 10px;"|' tOut[ 5] = iFile tOut[ 6] = '\n|-\n| style="width: 210px; height: 45px; background-size: cover; background-position: 0 -80px; padding: 0 10px;"|' tOut[ 8] = '' tOut[ 9] = '' tOut[10] = '\n|-\n| style="width: 210px; height: 60px; background-size: cover; background-position: 0 -125px; background-repeat: space; vertical-align: top; padding-top: 10px; padding: 0 10px;"|' tOut[12] = '' end

if name:match("^XP") then tOut[ 2] = "tsuncommon" tOut[ 4] = '\n| style="width: 210px; height: 100px; background-size: cover; background-position: top; padding: 5px 10px 0 10px;"|' tOut[ 5] = iFile tOut[ 6] = '\n|-\n| style="width: 210px; height: 25px; background-size: cover; background-position: 0 -100px; padding: 0 10px; vertical-align: top;"|' tOut[ 8] = '' tOut[ 9] = '' tOut[10] = '\n|-\n| style="width: 210px; height: 65px; background-size: cover; background-position: 0 -120px; background-repeat: space; vertical-align: top; padding-top: 10px; padding: 0 10px;"|' tOut[11] = iQuest 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