Changes

no edit summary
Line 2: Line 2:  
local remiLib = require("Module:RemiLib")
 
local remiLib = require("Module:RemiLib")
   −
function p.dropTable(frame)
+
function p.createDropTable(frame)
 
-- entries are in the form of <Node>_<Ship Type> = <List of Ships>
 
-- entries are in the form of <Node>_<Ship Type> = <List of Ships>
 
local drops = {}
 
local drops = {}
 
for param, list in pairs(frame.args) do
 
for param, list in pairs(frame.args) do
 
local label = string.upper(mw.text.split(param, "_")[1]) -- Should be single letter in uppercase
 
local label = string.upper(mw.text.split(param, "_")[1]) -- Should be single letter in uppercase
local shipCode = mw.text.split(param, "_")[2] -- One of DD, CL, CA, BB, CV, CVL, AV, SS, AUX
+
local shipCode = mw.text.split(param, "_")[2] -- One of DE, DD, CL, CA, BB, CV, CVL, AV, SS, AUX
 +
if drops[label] == nil then
 +
drops[label] = {}
 +
end
 
drops[label][shipCode] = list
 
drops[label][shipCode] = list
 
end
 
end
   −
local headerList = {}
+
local numTypes = {}
local validLabels = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
+
local validLabels = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","Z1", "Z2", "Z3", "Z4", "Z5", "Z6", "Z7", "Z8", "Z9", "ZZ1", "ZZ2", "ZZ3"}
local shipTypes = {"DD", "CL", "CA", "BB", "CV", "CVL", "AV", "SS", "AUX"}
+
local shipTypes = {"DE", "DD", "CL", "CA", "BB", "CV", "CVL", "AV", "SS", "AUX"}
   −
for i, ship in pairs(shipTypes) do
+
for i, letter in pairs(validLabels) do
headerList[ship] = false
+
numTypes[letter] = 0
 
end
 
end
 
for x, node in pairs(validLabels) do
 
for x, node in pairs(validLabels) do
for y, ship in pairs(shipTypes) do
+
if drops[node] ~= nil then
if drops[node][ship] ~= nil then
+
for y, ship in pairs(shipTypes) do
headerList[ship] = true
+
if drops[node][ship] ~= nil then
 +
numTypes[node] = numTypes[node] + 1
 +
end
 
end
 
end
 
end
 
end
 
end
 
end
   −
local tablehtml = {}
+
local tablehtml = '<table class="mw-collapsible mw-collapsed wikitable" style="width:100%">'
tablehtml = tablehtml .. '<table class="mw-collapsible mw-collapsed wikitable" style="width:100%">'
+
tablehtml = tablehtml .. '<tr><th style="width:50px;">Node</th><th colspan="2">Ship List</th></tr>'
 
  −
-- Creating header --
  −
local numCols = 0
  −
for i, ship in pairs(shipTypes) do
  −
if headerList[ship] == true then
  −
numCols = numCols + 1
  −
end
  −
end
     −
local headertext = {}
+
local classLink = {}
headertext["DD"] = '[[EliteDD|Destroyers]]'
+
classLink["DE"] = '[[Destroyer Escorts]]'
headertext["CL"] = '[[EliteCL|Light Cruisers]]'
+
classLink["DD"] = '[[EliteDD|Destroyers]]'
headertext["CA"] = '[[EliteCA|Heavy Cruisers]]'
+
classLink["CL"] = '[[EliteCL|Light Cruisers]]'
headertext["BB"] = '[[EliteBB|Battleships]]'
+
classLink["CA"] = '[[EliteCA|Heavy Cruisers]]'
headertext["CV"] = '[[EliteDD|Aircraft Carriers]]'
+
classLink["BB"] = '[[EliteBB|Battleships]]'
headertext["CVL"] = '[[EliteDD|Light Aircraft Carriers]]'
+
classLink["CV"] = '[[EliteDD|Aircraft Carriers]]'
headertext["AV"] = '[[EliteAV|Seaplane Tenders]]'
+
classLink["CVL"] = '[[EliteDD|Light Aircraft Carriers]]'
headertext["SS"] = '[[EliteSS|Submarines]]'
+
classLink["AV"] = '[[EliteAV|Seaplane Tenders]]'
headertext["AUX"] = '[[Auxiliary Ship]]s'
+
classLink["SS"] = '[[EliteSS|Submarines]]'
 +
classLink["AUX"] = '[[Auxiliary Ships]]'
   −
if numCols == 0 then -- no valid entries
  −
tablehtml = tablehtml .. '<tr><th style="width:50px;">Node</th><th>Ship List</th></tr>'
  −
else
  −
tablehtml = tablehtml .. '<tr><th style="width:50px;" rowspan="2">Node</th><th colspan="' .. numCols .. '">Ship List</th></tr>'
  −
tablehtml = tablehtml .. '<tr>'
  −
for i, ship in pairs(shipTypes) do
  −
if headerList[ship] == true then
  −
tablehtml = tablehtml .. '<th>' .. headertext[ship] .. '</th>'
  −
end
  −
end
  −
tablehtml = tablehtml .. '</tr>'
  −
end
  −
   
for x, node in pairs(validLabels) do
 
for x, node in pairs(validLabels) do
if drops[node] ~= nil then
+
if numTypes[node] > 0 then
tablehtml = tablehtml .. '<tr><td style="text-align:center; font-size:18px; font-weight:bold;">' .. node .. '</td>'
+
tablehtml = tablehtml .. '<tr><td style="text-align:center; font-size:18px; font-weight:bold;" '
 +
tablehtml = tablehtml .. 'rowspan="' .. numTypes[node] .. '">' .. node .. '</td>'
 +
 +
remTypes = numTypes[node]
 
for y, ship in pairs(shipTypes) do
 
for y, ship in pairs(shipTypes) do
if headerList[ship] == true then
+
if drops[node][ship] ~= nil then
tablehtml = tablehtml .. '<td>'
+
tablehtml = tablehtml .. '<td style="text-align:center; width:70px;">' .. classLink[ship] .. '</td>'
if drops[node][ship] ~= nil then
+
tablehtml = tablehtml .. '<td>' .. drops[node][ship] .. '</td>'
tablehtml = tablehtml .. drops[node][ship]
+
remTypes = remTypes - 1
 +
if remTypes > 0 then
 +
tablehtml = tablehtml .. '</tr><tr>'
 +
else
 +
tablehtml = tablehtml .. '</tr>'
 +
break
 
end
 
end
tablehtml = tablehtml .. '</td>'
   
end
 
end
 
end
 
end
tablehtml = tablehtml .. '</tr>'
   
end
 
end
 
end
 
end
+
 
 +
tablehtml = tablehtml .. '</table>'
 
return tablehtml
 
return tablehtml
 
end
 
end
    
return p
 
return p
5,421

edits