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

Module:ListOfSortable

From Kancolle Wiki
Revision as of 22:07, 6 September 2022 by Memetails (talk | contribs)
Jump to navigation Jump to search

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

---
-- Automates generation of sortable table by designated class by looking at all ships within Module:Data/Ship
--
-- TODO: Get stats from Module:Data/Ship instead of relying on Module:ELiteShipsKai to retrieve from Module:Data/Ships/<ShipName>
-- TODO: Automate coloring without Module:EliteShipsKai

local ListOfSortable = {}
local U = require('Module:Core')

local template = {
	footer = "}}",
	header = [[{{EliteShipsKaiSortable]],
	item = [=[
|%s]=],
}

local function GenerateTable(shipClass, remodelSuffix, notes, coloring, ...)
	local shipClass = shipClass or frame.args[1] or "??"
	local success, data = U.loadData("Data/Ship")
	if not success then return "No data for ships: " .. shipClass end
	
	local result = string.format(template.header)
	
	local suffix = {}
	local index = 1
	for k, v in pairs(remodelSuffix) do
		suffix[index] = v
		index = index + 1
	end
	
	for k, v in pairs(data) do
		if v.type == shipClass and v.remodellv ~= '' then
			local name = v.name[3]
			local success = 0
			for k, v in pairs(remodelSuffix) do
				if success == 0 and v ~= nil and v ~= "" then
					name,success = name:gsub("." .. v, "/" .. v)
				end
			end
			result = result .. string.format(template.item, name)
		end
	end
	
	for k, v in pairs(notes) do
		result = result .. string.format(template.item, v)
	end
	
	for k, v in pairs(coloring) do
		result = result .. string.format(template.item, v)
	end

	result = result .. template.footer
	return result .. '\n'
end

function ListOfSortable.ParseAndGenerate(frame)
	local shipClass = {}
	if frame.args['shipClass']	   ~= nil then shipClass = frame.args['shipClass'] end
	local remodelSuffix = {}
	if frame.args['remodelSuffix'] ~= nil then remodelSuffix = U.split(frame.args['remodelSuffix'], ',') end
	local notes = {}
	if frame.args['notes']		   ~= nil then notes		 = U.split(frame.args['notes'], ',\n') end
	local coloring = {}
	if frame.args['coloring']	   ~= nil then coloring 	 = U.split(frame.args['coloring'], ',\n') end
	
	return GenerateTable(shipClass, remodelSuffix, notes, coloring)
end

local function test()
--	mw.log(generateTable("Destroyer", {"B Kai", "D Kai", "Mk.II", "Zwei"},
--		{"Mikazuki/Kai_notes = Can equip [[Daihatsu Landing Craft|Daihatsu]]",
--			"Mutsuki/Kai Ni_notes = 2nd remodel. Can equip [[Daihatsu Landing Craft|Daihatsu]]",
--			"Kisaragi/Kai Ni_notes = 2nd remodel. Can equip [[Daihatsu Landing Craft|Daihatsu]]",
--			"Satsuki/Kai Ni_notes = 2nd remodel. Can equip [[Daihatsu Landing Craft|Daihatsu]] & [[Special Type 2 Amphibious Landing Craft|Type 2 Landing Craft]]",
--			"Fumizuki/Kai Ni_notes = 2nd remodel. Can equip [[Daihatsu Landing Craft|Daihatsu]] & [[Special Type 2 Amphibious Landing Craft|Type 2 Landing Craft]]"},
--		{"remodel_level_good = 20",
--			"remodel_level_outstanding = 15",
--			"remodel_level_operator = <",
--			"firepower_good = 56",
--			"firepower_outstanding = 61",
--			"torpedo_good = 83",
--			"torpedo_outstanding = 89",
--			"night_battle = true",
--			"night_battle_good = 140",
--			"night_battle_outstanding = 150",
--			"aa_good = 64",
--			"aa_outstanding = 74",
--			"asw_good = 67",
--			"asw_outstanding = 73",
--			"los_good = 42",
--			"los_outstanding = 49",
--			"hp_good = 34",
--			"hp_outstanding = 36",
--			"armor_good = 50",
--			"armor_outstanding = 58",
--			"evasion_good = 92",
--			"evasion_outstanding = 98",
--			"aircraft_good = 1",
--			"aircraft_outstanding = 1",
--			"aircraft_slot_good = 1",
--			"luck_good = 19",
--			"luck_outstanding = 30",
--			"luck_max_good = 80",
--			"fuel_operator=<",
--			"ammo_good = 20",
--			"ammo_outstanding = 20",
--			"ammo_operator = <",
--			"reference_type = 2"}))
		
	local frame = {}
	frame.args = {}
	frame.args['shipClass'] = "Destroyer"
	frame.args['remodelSuffix'] = "B Kai,D Kai,Mk.II,Zwei,Kai"
	frame.args['notes'] = "Mikazuki/Kai_notes = Can equip [[Daihatsu Landing Craft|Daihatsu]],\nMutsuki/Kai Ni_notes = 2nd remodel. Can equip [[Daihatsu Landing Craft|Daihatsu]],\nKisaragi/Kai Ni_notes = 2nd remodel. Can equip [[Daihatsu Landing Craft|Daihatsu]],\nSatsuki/Kai Ni_notes = 2nd remodel. Can equip [[Daihatsu Landing Craft|Daihatsu]] & [[Special Type 2 Amphibious Landing Craft|Type 2 Landing Craft]],\nFumizuki/Kai Ni_notes = 2nd remodel. Can equip [[Daihatsu Landing Craft|Daihatsu]] & [[Special Type 2 Amphibious Landing Craft|Type 2 Landing Craft]]"
	frame.args['coloring'] = "remodel_level_good = 20,\nremodel_level_outstanding = 15,\nremodel_level_operator = <,\nfirepower_good = 56,\nfirepower_outstanding = 61,\ntorpedo_good = 83,\ntorpedo_outstanding = 89,\nnight_battle = true,\nnight_battle_good = 140,\nnight_battle_outstanding = 150,\nreference_type = 2"
	mw.log(ListOfSortable.ParseAndGenerate(frame))
end

--return { render = render, test = test } --swap comments to test
return ListOfSortable

-- TEST: p.test()