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 date = require('Dev:Date')

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, rewards, requirements, cost, sale, duration, event, smallcard) local cType = "default"

local iFile = "" local iLink = "" local iRequ = "" local iReward = nil local iCost = "" local iDur = ""

local iEvent = "default" if event and storylineData["Colors"][event:lower] then iEvent = event:lower if event~="ms" and event~="old" then cType = "event" end elseif event and event:match("^ts") then iEvent = event end

if smallcard then cType = "small" 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, (cType=="event" and "120" or "100")}) iLink = CHEST({name, "L"}) elseif name:match("^EC%-") then iFile = EC({iName, nil, nil, "C", (cType=="small" and 60 or 120)}) 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, (cType=="small" and 55 or 120)})			iLink = TOK({name, "S"})			if cType == "small" then				iFile = ' ' .. iFile .. ' ' .. TOK({name, "C"}) .. '  '				if event and not event:match("^ts") then iEvent = iEvent .. "token" end			end		end	end

if requirements then for rName in mw.text.gsplit(requirements, "%s*$%s*") do			local tRequ = {space, "", rName, "", "", ""}

if rName:match("-" .. iEvent:upper) then tRequ[2] = ""				tRequ[5] = mw.ustring.gsub(rName, "-" .. iEvent:upper, "")				tRequ[6] = ""

if tRequ[5]:match("^.+%-%d+$") then tRequ[5] = qLink:match("(.+)%-%d+$") end end

iRequ = iRequ .. table.concat(tRequ) space = " " end elseif rewards then iReward = ' ' end

if cost then iCost = costTable(cost, sale) end

if duration then local bDur1, bDur2 = mw.ustring.match(duration, "^([^,]-)%s*#%s*(%d+)$") if not bDur1 then bDur1 = "2016/01/01" end

if bDur2 then local today = os.date("%Y/%m/%d %H:%M:%S") local UnlockDate = bDur1 .. util.dayStart local LockDate = date(bDur1):adddays(tonumber(bDur2)):fmt("%Y/%m/%d")

if today <= UnlockDate then iCost = ": " .. util.countdown(UnlockDate, " in ", " on ", true) iCost = "" duration = util.countdown(UnlockDate, " in ", " on ", true) elseif today <= LockDate then duration = util.countdown(LockDate, " for ", " until ", true) elseif today > LockDate then duration = util.strDate(bDur1, tonumber(bDur2)) end end

iDur = ' ' end

if cType == "small" then return table.concat({'{| class="card ', iEvent, '" style="text-align: center; line-height: normal; border-spacing: 0px; display: inline-table; margin: 0 3px 10px 0; color: white;"', 			'\n| style="width: 210px; height: 65px; background-size: cover; background-position: top; padding: 0 9px 0 4px; vertical-align: bottom;"|', iFile, 			'\n|-\n| style="width: 210px; height: 17px; background-size: cover; background-position: 0 -65px; padding: 0 9px 0 4px; text-shadow: 0px 0px 5px #0000007a;"|', (iRequ~="" and (" " .. iRequ .. " ") or RARITY({TOK({name, "R"}), "S", 15})), 			'\n|-\n| style="width: 210px; height: 40px; background-size: cover; background-position: 0 -82px; padding: 0 9px 0 4px; text-shadow: 2px 2px 1px #030562;"|', (" '''" .. iLink .. "''' "), 			'\n|-\n| style="width: 210px; height: 54px; background-size: cover; background-position: 0 -126px; padding: 0 9px 0 4px; vertical-align: top;"|', (iReward or iCost), 			'\n|-\n| style="background-size: cover;background-position: 0 -180px; background-repeat: space;"|', iDur, 			'\n|}'		}) elseif cType == "event" then return table.concat({'{| class="card ', iEvent, '" style="text-align: center; line-height: normal; border-spacing: 0px; display: inline-table; margin: 0 3px 10px 0; color: white;"', 			'\n| style="width: 210px; height: 35px; background-size: cover; background-position: top; padding: 0 6px 0 4px; text-shadow: 2px 2px 1px #030562; font-size: 15px;"|', ("'''" .. iLink .. "'''"), 			'\n|-\n| style="width: 210px; height: 150px; background-size: cover; background-position: 0 -35px; padding: 5px 0 0 0;"|', (' ' .. iFile .. ' '), 			'\n|-\n| style="width: 210px; height: 60px; background-size: cover; background-position: 0 -185px; padding: 0 9px 0 4px; text-shadow: 0px 0px 5px #0000007a;"|', iRequ, 			'\n|-\n| style="width: 210px; height: 60px; background-size: cover; background-position: 0 -245px; background-repeat: space; vertical-align: top; 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|}'		}) else return table.concat({'{| class="card ', iEvent, '" style="text-align: center; line-height: normal; border-spacing: 0px; display: inline-table; margin: 0 3px 10px 0; color: white;"', 			'\n| style="width: 210px; height: 140px; background-size: cover; background-position: top; 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; text-shadow: 2px 2px 1px #030562;"|', (" '''" .. iLink .. "''' "), 			'\n|-\n| style="width: 210px; height: 60px; background-size: cover; background-position: 0 -185px; padding: 0 9px 0 4px; vertical-align: top; text-shadow: 0px 0px 5px #0000007a;"|', (iReward or iRequ), 			'\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|}'		}) end 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, ("EC-Elixirs #" .. TOK({token, "E"})), nil, nil, ("ts" .. TOK({token, "R"})), true)) 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["reward"], tArgs["requirement"], tArgs["cost"], tArgs["sale"], tArgs["duration"], tArgs["event"], tArgs["small"]) end end

return p