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
(using new icon modules)
Line 6: Line 6:
local constants = require('Module:Constants')
local constants = require('Module:Constants')
local utils = require('Module:Utilities')
local utils = require('Module:Utilities')
local aicon = require('Module:Attribute icon')._main
local cicon = require('Module:Character icon')._main
local ricon = require('Module:Rarity icon')._main
local icons = require('Module:Icons')._main
local icons = require('Module:Icons')._main


Line 20: Line 23:
return string.format(
return string.format(
"%s %s",
"%s %s",
icons({ attribute, size = '20px' }),
aicon({ attribute, size = '20px' }),
utils.capitalize(attribute)
utils.capitalize(attribute)
)
)
Line 30: Line 33:
local function formatCharacter(character)
local function formatCharacter(character)
if character and charater ~= '' then
if character and charater ~= '' then
local icon = icons({ character, size = '20px' })
local icon = cicon({ character, size = '20px' })
if icon then
if icon then
return string.format(
return string.format(
Line 48: Line 51:
tonumber(rarity) >= 1 and
tonumber(rarity) >= 1 and
tonumber(rarity) <= 4 then
tonumber(rarity) <= 4 then
return icons({ rarity .. " star", size = '20px' })
return ricon({ rarity, '20px' })
elseif rarity == 'birthday' then
elseif rarity == 'birthday' then
return icons({ rarity, size = '20px' })
return ricon({ rarity, '20px' })
end
end
end
end

Revision as of 04:09, 22 January 2022

--------------------------
-- 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 aicon     = require('Module:Attribute icon')._main
local cicon     = require('Module:Character icon')._main
local ricon     = require('Module:Rarity icon')._main
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",
			aicon({ attribute, size = '20px' }),
			utils.capitalize(attribute)
		)
	end
	
	return nil
end

local function formatCharacter(character)
	if character and charater ~= '' then
		local icon = cicon({ character, size = '20px' })
		if icon then
			return string.format(
				"%s [[%s]]",
				icon,
				character
			)
		end
		
		return '[[' .. character .. ']]'
	end
end

local function formatRarity(rarity)
	if rarity and rarity ~= '' then
		if tonumber(rarity) and 
			tonumber(rarity) >= 1 and 
			tonumber(rarity) <= 4 then
			return ricon({ rarity, '20px' })
		elseif rarity == 'birthday' then
			return ricon({ rarity, '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 formatBreakCommas(val)
	if val then
		local split_val = mw.text.split(val, ',')
		for i,v in ipairs(split_val) do
			split_val[i] = mw.text.trim(v)
		end
		
		return table.concat(split_val, "<br>") 
	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, { wrappers = 'Template:Infobox card' })
	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 = formatCharacter },
			{ name = 'attribute', func = formatAttribute },
			{ name = 'rarity', func = formatRarity },
			{ name = 'unit', func = formatUnit },
			{ name = 'support unit' , func = formatUnit},
			{ name = 'status' },
			{ name = 'date' },
			{ name = 'obtain', func = formatBreakCommas },
			{ 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 = 'Card ID', colspan = 12 },
			{ tag = 'argtd', content = 'card id', colspan = 18 }
		})
		: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 = 'Acquisition 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 = 'Acquisition method(s)', 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
		
		local rawArgs = infobox:getArgs('raw')
		
		if rawArgs['character'] then
			categories = categories .. string.format('[[Category:%s cards]]', rawArgs['character'])
		end
		
		if rawArgs['attribute'] then
			local attrs = {
				['cool'] = '[[Category:Cool cards]]',
				['cute'] = '[[Category:Cute cards]]',
				['happy'] = '[[Category:Happy cards]]',
				['mysterious'] = '[[Category:Mysterious cards]]',
				['pure'] = '[[Category:Pure cards]]'
			}
			if attrs[rawArgs['attribute']] then
				categories = categories .. attrs[rawArgs['attribute']]
			end
		end
		
		if rawArgs['rarity'] then
			local rarities = {
				['1'] = '[[Category:1☆ cards]]',
				['2'] = '[[Category:2☆ cards]]',
				['3'] = '[[Category:3☆ cards]]',
				['4'] = '[[Category:4☆ cards]]',
				['birthday'] = '[[Category:Birthday cards]]'
			}
			if rarities[rawArgs['rarity']] then
				categories = categories .. rarities[rawArgs['rarity']]
			end
		end

		if rawArgs['status'] then
			local statuses = {
				['Permanent'] = '[[Category:Permanent cards]]',
				['Limited']   = '[[Category:Limited cards]]',
				['Colorful Festival Limited'] = '[[Category:Colorful Festival limited cards]]',
				['Birthday Limited'] = '[[Category:Birthday limited cards]]',
			}
			if statuses[rawArgs['status']] then
				categories = categories .. statuses[rawArgs['status']]
			end
		end


	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.