This module depends on the following other modules: |
To generate {{Infobox gacha}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox gacha]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')
local sicon = require('Module:Seal icon')._main
local VariablesLua = mw.ext.VariablesLua
local p = {}
local function getYear(str)
if str == nil then return nil end
local function formatSeal(seal)
if seal == nil then return nil end
return string.format(
"%s %s",
sicon({seal, size = '30px'}) or '',
seal
)
end
local pattern = '(%d+)/(%d+)/(%d+), (%d+):(%d+)'
local year, month, day, hour, minute = str:match(pattern)
return year
end
function p.main(frame)
local args = getArgs(frame)
local infobox = InfoboxBuilder.new()
infobox:setName('Infobox gacha')
:setParams{
{ name = 'gacha id' },
{ name = 'gacha name', default = mw.title.getCurrentTitle().text },
{ name = 'logo' },
{ name = 'banner' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'start' },
{ name = 'end' },
{ name = 'type' },
{ name = 'seal' },
{ name = 'pity' },
{ name = 'currency', fn = ProcessingFns.stringToArray(',') }
}
:setArgs(args)
:processArgs()
:setCategoryMap({
['pity'] = {
['Yes'] = 'Gachas with pity'
}
})
infobox
:addHeader({ tag = 'argth', content = 'gacha name' })
:addImage({
{
tag = 'argtd',
content = 'logo',
fn = DisplayFns.image('x100px'),
tabName = 'Logo',
required = true
},
{
tag = 'argtd',
content = 'banner',
fn = DisplayFns.image('x100px'),
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 = 'Seal' },
{ tag = 'argtd', content = 'seal', fn = formatSeal }
})
:addRow({
{ tag = 'th', content = 'Has pity?' },
{ tag = 'argtd', content = 'pity' }
})
:addRow({
{ tag = 'th', content = 'Currency' },
{ tag = 'argtd', content = 'currency', fn = DisplayFns.list('unbulleted') }
})
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Gachas]]" .. infobox:getCategories()
local rawArgs = infobox:getRawArgs()
local year = getYear(rawArgs['start'])
if year then
categories = categories .. string.format('[[Category:Gachas in %s]]', year)
end
end
return infobox:tostring() .. categories
end
return p