dev
Documentation icon Module documentation
[create]

The documentation for this module is missing. Click here to create it.

--<nowiki>
local p = {}

local data = require("Module:Sandbox/Ballmanac/Data")
local all_data = data.name

-- Utility
local function HaveValue(tab, val)
	if tab == nil then
		return false
	end
    for OrdinalIndex, value in ipairs(tab) do
        if value == val then
            return true
        end
    end

    return false
end

------------------------------------- Count
function p.CategoryCount(frame)
	local category = frame.args[1]
	local c = 0
	for i, index in pairs(all_data) do
		if ( category == index.Category and index.Hidden == false ) then
			c = c + 1
		end
	end
	return c
end

function p.PackCount(frame)
	local pack = frame.args[1]
	local c = 0
	for i, index in pairs(all_data) do
		if HaveValue(index.Pack, pack) then
			c = c + 1
		end
	end
	return c
end

function p.PackTierCount(frame)
	local pack = frame.args[1]
	local tier = frame.args[2]
	local c = 0
	for i, index in pairs(all_data) do
		if ( HaveValue(index.Pack, pack) and index.Tier == tier ) then
			c = c + 1
		end
	end
	return c
end

------------------------------------- Pack()

function Pack(list)
	local packs = {}
	for i, index in ipairs(list) do
		table.insert(packs, "[[:Category:" .. index .. "|" .. index .. "]][[Category:" .. index .. "]]")
	end
	return table.concat(packs, ", ")
end

------------------------------------- ID()

function ID(list)
	local ids = {}
	for i, index in ipairs(list) do
		table.insert(ids, index)
	end
	return table.concat(ids, ", ")
end

------------------------------------- Infobox

local infobox_template = [=[{{ABInfobox/Archetype
  |title = %s
  |image = %s.PNG
  |damage = {{#if:%s|{{Symbol|d|%s}}|}}
  |health = {{#if:%s|{{Symbol|h|%s}}|}}
  |description = %s
  |upgrading = %s
  |pack = %s
  |tier = %s
  |note = %s
  |unlock_by = %s
  |concept_by = %s
  |added_in = [[Patch_Notes#v%s|%s]]
  |ID = %s
}}]=]

function p.Infobox(frame)
	local infoname = frame.args[1] ~= "" and frame.args[1] or mw.title.getCurrentTitle().text
	local info = all_data[infoname]
	return frame:preprocess(infobox_template:format(
		infoname,
        infoname,
        info.Damage or "",
        info.Damage or "",
        info.Health or "",
        info.Health or "",
        info.Description,
        info.Upgrading or "",
        info.Pack and Pack(info.Pack) or "",
        info.Tier,
        info.Note or "",
        info.Unlock or "",
        info.ConceptBy or "",
        info.Version, 
        info.Version,
        info.ID and ID(info.ID) or ""
        ))
end

------------------------------------- Sort

function Sort(list)
	local info = {}
	for i, index in pairs(list) do
		index.Name = i
		table.insert(info, index)
		end
		table.sort(info, function(a, b) return a.Name < b.Name end)
		return info
end

------------------------------------- Ball Table

local table_head_ball = [=[
{| class="fandom-table sortable firstcolumn-center-nowrap floatheader" style="width:100%; max-width:1350px"
 ! rowspan="2" style="width:20%" | Ball
 ! rowspan="2" style="max-width:6%; text-align: center;" | {{Symbol|d|}}
 ! rowspan="2" style="max-width:6%; text-align: center;" | {{Symbol|h|}}
 ! class="unsortable" colspan="2" | Ability
 ! rowspan="2" class="unsortable" style="width:15%" | Note
 ! rowspan="2" style="max-width:6%" text-align: center;" | Added In
|-
 ! class="unsortable floatheader" | Description
 ! class="unsortable floatheader" | Upgrading
]=]

local table_row_ball = [=[
 |-
 | data-sort-value="%s" style="text-align: center" | [[File:%s.PNG|center|link=%s]]<br />[[%s]]
 | style="text-align: center" | {{Symbol|d|%s}}
 | style="text-align: center" | {{Symbol|h|%s}}
 | style="font-size: small" | %s
 | style="font-size: small" | %s
 | style="font-size: small" | %s
 | style="text-align: center" | [[Patch_Notes#v%s|%s]]
]=]

function p.BallTable(frame)
	local pack = frame.args[1]
	local tier = frame.args[2]
	local thetable = table_head_ball
	for i, index in ipairs(Sort(all_data)) do
		if ( index.Category == "Ball" and ( HaveValue(index.Pack, pack) or pack == "ALL" ) and ( index.Tier == tier or tier == "ALL" ) ) then
			thetable = thetable .. table_row_ball:format(
				index.Name, 
				index.Name, 
				index.Name, 
				index.Name,
				index.Damage,
				index.Health,
				index.Description,
				index.Upgrading,
				index.Note or "",
				index.Version,
				index.Version
			)
		end
	end
	return frame:preprocess(thetable .. "|}")
end

------------------------------------- Item/Equipment Table

local table_head_item = [=[
{| class="fandom-table sortable firstcolumn-center-nowrap floatheader" style="width:100%; max-width:1350px"
 ! rowspan="2" style="width:20%" | Item
 ! class="unsortable" | Description
 ! rowspan="2" class="unsortable" style="width:25%" | Note
 ! rowspan="2" style="width:6%" text-align: center;" | Added In
]=]

local table_row_item = [=[
 |-
 | data-sort-value="%s" style="text-align: center" | [[File:%s.PNG|center|link=%s]]<br />[[%s]]
 | style="font-size: small" | %s
 | style="font-size: small" | %s
 | style="text-align: center" | [[Patch_Notes#v%s|%s]]
]=]

function p.ItemTable(frame)
	local category = frame.args[1]
	local tier = frame.args[2]
	local thetable = table_head_item
	for i, index in ipairs(Sort(all_data)) do
		if ( ( index.Category == category or category == "ALL" ) and HaveValue(index.Pack, "Items") and (index.Tier == tier or tier == "ALL" ) ) then
			thetable = thetable .. table_row_item:format(
				index.Name, 
				index.Name, 
				index.Name, 
				index.Name,
				index.Description,
				index.Note or "",
				index.Version,
				index.Version
			)
		end
	end
	return frame:preprocess(thetable .. "|}")
end

------------------------------------- Nav Items

local nav_title = [=[
{| class="mw-collapsible mw-collapsed" style="width: 100%; border: solid white 4px; border-radius: 0.45em;"
 ! colspan="3" style="background: #484dff; border: solid #484dff 1px; color: white;" | Navbox
 |-
]=]

local nav_group = [=[
 ! rowspan="%s" width="10%%" style="background: #484dff; color: white;" | %s
]=]

local nav_subgroup = [=[
 ! width="7.5%%" style="background: #24267f; font-size: small; color: white;" | Tier %s <br /> (%s)
 | style="background: #000000; font-size: small; color: white;" | %s
 |-
]=]

function p.Navbox(frame)
	local TheNavbox = nav_title
	local pack_datas = { 
		Classic_Pack = { I = {}, II = {}, III = {}, IIIp = {} }, 
		Community_Pack = { I = {}, II = {}, III = {}, IIIp = {} },
		Items = { I = {}, II = {}, III = {}, IIIp = {} }, 
		Hidden = { I = {}, II = {}, III = {}, IIIp = {} } 
	}
	for name, index in pairs(all_data) do
		tie = string.gsub( index.Tier, "III%+", "IIIp" )
		if index.Hidden == false then
			for pack in pairs(pack_datas) do
				if HaveValue(index.Pack, string.gsub(pack, "_", " ")) then
					table.insert( pack_datas[pack][tie], "{{ABLink|" .. name .. "}}" )
				end
			end
		elseif index.Hidden == true then
			table.insert( pack_datas["Hidden"][tie], "{{ABLink|" .. name .. "}}" )
		end
	end
	--sorting pack_datas info
	for pack, tier in pairs(pack_datas) do
		if pack_datas[pack][tier] ~= nil then
			table.sort( pack_datas[pack][tier] )
		end
	end
	--creating the navbox
	for i, pack in ipairs({ "Classic_Pack", "Community_Pack", "Items", "Hidden" }) do
		nav = ""
		rowspan = 0
		for j, tier in ipairs({ "I", "II", "III", "IIIp" }) do
			if table.getn(pack_datas[pack][tier]) ~= 0 then
				rowspan = rowspan + 1
				nav = nav .. nav_subgroup:format(
					tier,
					table.getn(pack_datas[pack][tier]),
					table.concat(pack_datas[pack][tier], " · ") )
			end
		end
		TheNavbox = TheNavbox .. nav_group:format( rowspan, pack ) .. nav
	end
	TheNavbox = TheNavbox .. "|}"
	TheNavbox = string.gsub( TheNavbox, "IIIp", "III%+" )
	TheNavbox = string.gsub( TheNavbox, "_", " " )
	return(TheNavbox)
end

------------------------------------- 

return p
--</nowiki>