• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Module:DropTable

From Kancolle Wiki
Revision as of 23:03, 28 August 2016 by IbarakiIbuki (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:DropTable/doc

local p = {}
local remiLib = require("Module:RemiLib")

function p.dropTable(frame)
	-- entries are in the form of <Node>_<Ship Type> = <List of Ships>
	local drops = {}
	for param, list in pairs(frame.args) do
		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
		if drops[label] == nil then
			drops[label] = {}
		end
		drops[label][shipCode] = list
	end

	local headerList = {}
	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 shipTypes = {"DD", "CL", "CA", "BB", "CV", "CVL", "AV", "SS", "AUX"}

	for i, ship in pairs(shipTypes) do
		headerList[ship] = false
	end
	for x, node in pairs(validLabels) do
		if drops[node] ~= nil then
			for y, ship in pairs(shipTypes) do
				if drops[node][ship] ~= nil then
					headerList[ship] = true
				end
			end
		end
	end

	local tablehtml = {}
	tablehtml = tablehtml .. '<table class="mw-collapsible mw-collapsed wikitable" style="width:100%">'

-- Creating header --
	local numCols = 0
	for i, ship in pairs(shipTypes) do
		if headerList[ship] == true then
			numCols = numCols + 1
		end
	end

	local headertext = {}
	headertext["DD"] = '[[EliteDD|Destroyers]]'
	headertext["CL"] = '[[EliteCL|Light Cruisers]]'
	headertext["CA"] = '[[EliteCA|Heavy Cruisers]]'
	headertext["BB"] = '[[EliteBB|Battleships]]'
	headertext["CV"] = '[[EliteDD|Aircraft Carriers]]'
	headertext["CVL"] = '[[EliteDD|Light Aircraft Carriers]]'
	headertext["AV"] = '[[EliteAV|Seaplane Tenders]]'
	headertext["SS"] = '[[EliteSS|Submarines]]'
	headertext["AUX"] = '[[Auxiliary Ship]]s'

	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
		if drops[node] ~= nil then
			tablehtml = tablehtml .. '<tr><td style="text-align:center; font-size:18px; font-weight:bold;">' .. node .. '</td>'
			for y, ship in pairs(shipTypes) do
				if headerList[ship] == true then
					tablehtml = tablehtml .. '<td>'
					if drops[node][ship] ~= nil then
						tablehtml = tablehtml .. drops[node][ship]
					end
					tablehtml = tablehtml .. '</td>'
				end
			end
			tablehtml = tablehtml .. '</tr>'
		end
	end
	
	tablehtml = tablehtml .. '</table>'
	return tablehtml
end

return p