Module:Infobox gacha

From Sekaipedia
Revision as of 21:23, 9 March 2022 by ChaoticShadow (talk | contribs) (added gacha idrow)

To generate {{Infobox gacha}}, invoke using the main function.


--------------------------
-- Module for [[Template:Infobox gacha]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local builder   = require('Module:InfoboxBuilder new')

local p = {}
local categories = ""

local function formatImage(imageName)
	return string.format("[[File:%s|x100px]]", imageName)
end

local function splitList(str)
	if str == nil then
		return nil
	end
	
	local list = mw.text.split(str, ',')
	for i=1,#list do
		list[i] = mw.text.trim(list[i])
	end
	
	return list
end

local function displayList(list)
	if #list < 2 then
		return list[1]
	end
	
	local ul = mw.html.create('ul')
	
	for i=1,#list do
		ul:tag('li')
			:wikitext(list[i])
	end
	
	return tostring(ul)
end


function p.main(frame)
	local args = getArgs(frame)
	local infobox = builder.new()
	
	infobox:setName('Infobox gacha')
		:setParams{
			{ name = 'gacha id' },
			{ name = 'gacha name', default = mw.title.getCurrentTitle().text },
			{ name = 'logo', dFunc = formatImage },
			{ name = 'banner', dFunc = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'start' },
			{ name = 'end' },
			{ name = 'type' },
			{ name = 'festival' },
			{ name = 'pity' },
			{ name = 'currency', pFunc = splitList, dFunc = displayList }
		}
		:setArgs(args)
		:processArgs()
		:setCategoryMap({
			['pity'] = {
				['Yes'] = 'Gachas with pity'
			}
		})

	infobox
		:addHeader({ tag = 'argth', content = 'gacha name' })
		:addImage({
			{ tag = 'argtd', content = 'logo', tabName = 'Logo' },
			{ tag = 'argtd', content = 'banner', tabName = 'Banner' }
		})
		:addRow({
			{ tag = 'th', content = 'Japanese' },
			{ tag = 'argtd', content = 'japanese' }
		})
		:addRow({
			{ tag = 'th', content = 'Romaji' },
			{ tag = 'argtd', content = 'romaji' }
		})
		:addHeader({ tag = 'th', content = 'Gacha Information' }, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Gacha ID' },
			{ tag = 'argtd', content = 'gacha id' }
		})
		:addRow({
			{ tag = 'th', content = 'Start date' },
			{ tag = 'argtd', content = 'start' }
		})
		:addRow({
			{ tag = 'th', content = 'End date' },
			{ tag = 'argtd', content = 'end' }
		})
		:addRow({
			{ tag = 'th', content = 'Gacha type' },
			{ tag = 'argtd', content = 'type' }
		})
		:addRow({
			{ tag = 'th', content = 'Has pity?' },
			{ tag = 'argtd', content = 'pity' }
		})
		:addRow({
			{ tag = 'th', content = 'Currency' },
			{ tag = 'argtd', content = 'currency' }
		})

	
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Gachas]]" .. infobox:getCategories()
	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.