Content added Content deleted
mNo edit summary |
mNo edit summary |
||
(16 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local InfoboxBuilder = require('Module:InfoboxBuilder') |
local InfoboxBuilder = require('Module:InfoboxBuilder') |
||
local DisplayFns = require('Module: |
local DisplayFns = require('Module:DisplayFunctions') |
||
local ProcessingFns = require('Module: |
local ProcessingFns = require('Module:ProcessingFunctions') |
||
local sicon = require('Module:Seal icon')._main |
|||
local VariablesLua = mw.ext.VariablesLua |
|||
local p = {} |
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) |
function p.main(frame) |
||
Line 25: | Line 46: | ||
{ name = 'end' }, |
{ name = 'end' }, |
||
{ name = 'type' }, |
{ name = 'type' }, |
||
{ name = 'seal' }, |
|||
{ name = 'pity' }, |
{ name = 'pity' }, |
||
{ name = 'currency', fn = ProcessingFns.stringToArray(',') } |
{ name = 'currency', fn = ProcessingFns.stringToArray(',') } |
||
Line 33: | Line 55: | ||
['pity'] = { |
['pity'] = { |
||
['Yes'] = 'Gachas with pity' |
['Yes'] = 'Gachas with pity' |
||
} |
}, |
||
['type'] = { |
|||
['Permanent'] = 'Permanent Gachas', |
|||
['Limited'] = 'Limited Gachas', |
|||
['Unit-Limited'] = 'Unit-Limited Gachas', |
|||
['Colorful Festival'] = 'Colorful Festival Gachas', |
|||
['Birthday'] = 'Birthday Gachas', |
|||
['Anniversary'] = 'Anniversary Gachas', |
|||
['Select List'] = 'Select List Gachas', |
|||
['Hapiness Package'] = 'Hapiness Package Gachas', |
|||
['Free 10-Pull'] = 'Free 10-pull Gachas', |
|||
['Premium Present'] = 'Premium Present Gachas', |
|||
['World Link Support'] = 'World Link Support Gachas' |
|||
} |
|||
}) |
}) |
||
Line 50: | Line 85: | ||
content = 'banner', |
content = 'banner', |
||
fn = DisplayFns.image('x100px'), |
fn = DisplayFns.image('x100px'), |
||
tabName = 'Banner' |
tabName = 'Banner' |
||
required = true |
|||
} |
} |
||
}) |
}) |
||
Line 78: | Line 112: | ||
{ tag = 'th', content = 'Gacha type' }, |
{ tag = 'th', content = 'Gacha type' }, |
||
{ tag = 'argtd', content = 'type' } |
{ tag = 'argtd', content = 'type' } |
||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Seal' }, |
|||
{ tag = 'argtd', content = 'seal', fn = formatSeal } |
|||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
Line 91: | Line 129: | ||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Gachas]]" .. infobox:getCategories() |
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 |
end |
||
Latest revision as of 14:06, 3 May 2024
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'
},
['type'] = {
['Permanent'] = 'Permanent Gachas',
['Limited'] = 'Limited Gachas',
['Unit-Limited'] = 'Unit-Limited Gachas',
['Colorful Festival'] = 'Colorful Festival Gachas',
['Birthday'] = 'Birthday Gachas',
['Anniversary'] = 'Anniversary Gachas',
['Select List'] = 'Select List Gachas',
['Hapiness Package'] = 'Hapiness Package Gachas',
['Free 10-Pull'] = 'Free 10-pull Gachas',
['Premium Present'] = 'Premium Present Gachas',
['World Link Support'] = 'World Link Support Gachas'
}
})
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