Module:Cards: Difference between revisions

627 bytes added ,  15:25, 16 December 2023
no edit summary
m (Undo revision 2785 by Lvlen-125 (talk))
Tag: Undo
No edit summary
Line 43: Line 43:
error("Argument Invalid:" .. stat)
error("Argument Invalid:" .. stat)
end
end
end
function p.test()
f = {}
f.args = {"Groff", "Image", "Name"}
return p.Table(f)
end
end


function p.Table(frame)
function p.Table(frame)
local headers = {}
local arr = {{}, {}}
local i = 2
local i = 1
while frame.args[i] ~= nil and i < 10 do
while frame.args[i] ~= nil do
  table.insert(headers, string.lower(frame.args[i] or ""))
  table.insert(arr[1], frame.args[i] or "")
  i = i + 1
  i = i + 1
end
end
local type = frame.args[1]
i = i + 1
return frame:preprocess(_table(type, headers))
while frame.args[i] ~= nil do
  table.insert(arr[2], string.lower(frame.args[i] or ""))
  i = i + 1
end
if #arr[2] == 0 then
for i=2,#arr[1] do
arr[2][i-1] = string.lower(arr[1][i])
end
arr[1] = {arr[1][1]}
end
--- return frame:preprocess(_table(arr[1], arr[2]))
mw.logObject(arr[1])
mw.logObject(arr[2])
return _table(arr[1], arr[2])
end
end


function _table(type, headers)
function _table(entries, headers)
   local out = '{| class="wikitable sortable" style="text-align:center;"\n'
   local out = '{| class="wikitable sortable" style="text-align:center;"\n'
   for i, header in ipairs(headers) do
   for i, header in ipairs(headers) do
Line 75: Line 94:
   end
   end
    
    
   for i, card in ipairs(sortedCards()) do
  local entryList = {}
    if card.Types and card.Types[type] then
   for i, entry in ipairs(entries) do
out = out.."|-\n"
  if all_cards[entry] then
for i, header in ipairs(headers) do
  all_cards[entry].UniqueName = entry
out = out.."|"
  table.insert(entryList, all_cards[entry])
if header == "image" then
  else
out = out.."{{CardArt|".. card.UniqueName.."}}"
  for i, card in ipairs(sortedCards()) do
elseif header == "name" then
  if card.Types and card.Types[entry] then
local link = card.Link or card.UniqueName
    table.insert(entryList, card)
out = out.."style=\"text-align:center;\"|[[".. link .. "|" .. card.Name .."]]"
    end
elseif header == "description" or header == "desc" or header == "summoncon" then
  end
out = out.."style=\"text-align:center;\"|".. (_getStat(card, header) or "")
end
elseif header == "health" and card.Health == nil and card.Scrap then
  end
out = out.. card.Scrap .." {{Stat|Scrap}}"
 
else
  for i, card in ipairs(entryList) do
out = out .. _getStat(card, header)  
out = out.."|-\n"
end
for i, header in ipairs(headers) do
out = out.."\n"
out = out.."|"
if header == "image" then
out = out.."{{CardArt|".. card.UniqueName.."}}"
elseif header == "name" then
local link = card.Link or card.UniqueName
out = out.."style=\"text-align:center;\"|[[".. link .. "|" .. card.Name .."]]"
elseif header == "description" or header == "desc" or header == "summoncon" then
out = out.."style=\"text-align:center;\"|".. (_getStat(card, header) or "")
elseif header == "health" and card.Health == nil and card.Scrap then
out = out.. card.Scrap .." {{Stat|Scrap}}"
else
out = out .. _getStat(card, header)  
end
end
out = out.."\n"
     end
     end
   end
   end
401

edits