Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Infobox card: Difference between revisions

From Sekaipedia
Content added Content deleted
No edit summary
(hide fields if they are empty)
Line 98: Line 98:
}
}
)
)
:addRow({
:addRow(
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
})
},
:addRow({
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ hideIfEmpty = { 'japanese' } }
)
{ tag = 'argtd', content = 'romaji', colspan = 18 }
:addRow(
})
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
},
{ hideIfEmpty = { 'romaji' } }
)
:addHeader({ tag = 'th', content = 'Card Information' }, { subheader = true })
:addHeader({ tag = 'th', content = 'Card Information' }, { subheader = true })
:addRow({
:addRow({
Line 123: Line 129:
{ tag = 'argtd', content = 'unit', colspan = 18 }
{ tag = 'argtd', content = 'unit', colspan = 18 }
})
})
:addRow({
:addRow(
{
{ tag = 'th', content = 'Support Unit', colspan = 12 },
{ tag = 'argtd', content = 'support unit', colspan = 18 }
{ tag = 'th', content = 'Support Unit', colspan = 12 },
{ tag = 'argtd', content = 'support unit', colspan = 18 }
})
},
{ hideIfEmpty = { 'support unit' } }
)
:addHeader({ tag = 'th', content = 'Obtainment Information' }, { subheader = true })
:addHeader({ tag = 'th', content = 'Obtainment Information' }, { subheader = true })
:addRow({
:addRow({
Line 140: Line 149:
{ tag = 'argtd', content = 'obtain', colspan = 18 }
{ tag = 'argtd', content = 'obtain', colspan = 18 }
})
})
:addRow({
:addRow(
{
{ tag = 'th', content = 'Associated Event', colspan = 12 },
{ tag = 'argtd', content = 'event', colspan = 18 }
{ tag = 'th', content = 'Associated Event', colspan = 12 },
{ tag = 'argtd', content = 'event', colspan = 18 }
})
},
:addRow({
{ tag = 'th', content = 'Debut Banner', colspan = 12 },
{ hideIfEmpty = { 'event' } }
)
{ tag = 'argtd', content = 'banner', colspan = 18 }
:addRow(
})
{
{ tag = 'th', content = 'Debut Banner', colspan = 12 },
{ tag = 'argtd', content = 'banner', colspan = 18 }
},
{ hideIfEmpty = { 'banner' } }
)
if mw.title.getCurrentTitle().namespace == 0 then
if mw.title.getCurrentTitle().namespace == 0 then

Revision as of 20:10, 8 October 2021

--------------------------
-- Module for [[Template:Infobox Card]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local builder   = require('Module:InfoboxBuilder')
local constants = require('Module:Constants')
local utils     = require('Module:Utilities')
local icons     = require('Module:Icons')._main


local p = {}
local categories = ""

local function formatImage(image_name)
	return string.format("[[File:%s|156px]]", image_name)
end

local function formatAttribute(attribute)
	if attribute and attribute ~= '' then
		return string.format(
			"%s %s",
			icons({ attribute, size = '20px' }),
			utils.capitalize(attribute)
		)
	end
	
	return nil
end

local function formatRarity(rarity)
	if rarity and rarity ~= '' then
		if tonumber(rarity) and 
			tonumber(rarity) >= 1 and 
			tonumber(rarity) <= 4 then
			return icons({ rarity .. " star", size = '20px' })
		elseif rarity == 'birthday' then
			return icons({ rarity, size = '20px' })
		end
	end

	return nil
end

local function formatUnit(unit)
	if unit and unit ~= '' then
		return string.format(
			"%s [[%s]]",
			icons({ unit, size = '20px' }),
			constants.get_unit(unit)
		)
		end
	
	return nil
end

local function formatToLink(val)
	if val and val ~= '' then
		return '[[' .. val .. ']]'
	end
	
	return nil
end


function p.main(frame)
	local args = getArgs(frame)
	local infobox = builder.new()
	
	infobox:setName('Infobox Card')
		:setWidth("330px")
		:setParams{
			{ name = 'card id' },
			{ name = 'card name', default = mw.title.getCurrentTitle().text },
			{ name = 'thumbnail', func = formatImage },
			{ name = 'thumbnail trained', func = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'character', func = formatToLink },
			{ name = 'attribute', func = formatAttribute },
			{ name = 'rarity', func = formatRarity },
			{ name = 'unit', func = formatUnit },
			{ name = 'support unit' , func = formatUnit},
			{ name = 'status' },
			{ name = 'date' },
			{ name = 'obtain' },
			{ name = 'event', func = formatToLink },
			{ name = 'banner', func = formatToLink }
		}
		:setArgs(args)
		:setHeaderColorsByParam('attribute', constants.get_attribute_colors)

	infobox
		:addHeader({ tag = 'argth', content = 'card name' })
		:addImage(
			{
				{ tag = 'argtd', content = 'thumbnail', title = 'Untrained' },
				{ tag = 'argtd', content = 'thumbnail trained', title = 'Trained' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Japanese', colspan = 12 },
				{ tag = 'argtd', content = 'japanese', colspan = 18 }
			},
			{ hideIfEmpty = { 'japanese' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Romaji', colspan = 12 },
				{ tag = 'argtd', content = 'romaji', colspan = 18 }
			},
			{ hideIfEmpty = { 'romaji' } }
		)
		:addHeader({ tag = 'th', content = 'Card Information' }, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Character', colspan = 12 },
			{ tag = 'argtd', content = 'character', colspan = 18 }
		})
		:addRow({
			{ tag = 'th', content = 'Attribute', colspan = 12 },
			{ tag = 'argtd', content = 'attribute', colspan = 18 }
		})
		:addRow({
			{ tag = 'th', content = 'Rarity', colspan = 12 },
			{ tag = 'argtd', content = 'rarity', colspan = 18 }
		})
		:addRow({
			{ tag = 'th', content = 'Unit', colspan = 12 },
			{ tag = 'argtd', content = 'unit', colspan = 18 }
		})
		:addRow(
			{
				{ tag = 'th', content = 'Support Unit', colspan = 12 },
				{ tag = 'argtd', content = 'support unit', colspan = 18 }
			},
			{ hideIfEmpty = { 'support unit' } }
		)
		:addHeader({ tag = 'th', content = 'Obtainment Information' }, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Status', colspan = 12 },
			{ tag = 'argtd', content = 'status', colspan = 18 }
		})
		:addRow({
			{ tag = 'th', content = 'Release Date', colspan = 12 },
			{ tag = 'argtd', content = 'date', colspan = 18 }
		})
		:addRow({
			{ tag = 'th', content = 'Obtainment Method', colspan = 12 },
			{ tag = 'argtd', content = 'obtain', colspan = 18 }
		})
		:addRow(
			{
				{ tag = 'th', content = 'Associated Event', colspan = 12 },
				{ tag = 'argtd', content = 'event', colspan = 18 }
			},
			{ hideIfEmpty = { 'event' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Debut Banner', colspan = 12 },
				{ tag = 'argtd', content = 'banner', colspan = 18 }
			},
			{ hideIfEmpty = { 'banner' } }
		)
	
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Cards]]" .. categories
	end

	return infobox:tostring() .. categories
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.