Content added Content deleted
m (add mission pass row) |
(using new builder) |
||
Line 4: | Line 4: | ||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local yesno = require('Module:Yesno') |
local yesno = require('Module:Yesno') |
||
local builder = require('Module:InfoboxBuilder') |
local builder = require('Module:InfoboxBuilder new') |
||
local p = {} |
local p = {} |
||
⚫ | |||
local function formatImage(image_name) |
local function formatImage(image_name) |
||
Line 13: | Line 12: | ||
end |
end |
||
local function formatLink( |
local function formatLink(link) |
||
return '[[' .. |
return '[[' .. link .. ']]' |
||
end |
end |
||
local function formatAccessory(accessory) |
local function formatAccessory(accessory) |
||
⚫ | |||
-- probably should not use == with bool, but this is more explicit |
-- probably should not use == with bool, but this is more explicit |
||
if |
if accessory == true then |
||
return '✓' |
return '✓' |
||
elseif |
elseif accessory == false then |
||
return '✗' |
return '✗' |
||
end |
end |
||
Line 29: | Line 27: | ||
end |
end |
||
local function |
local function getAccessoryClass(accessory) |
||
local val = yesno(accessory, nil) |
|||
-- probably should not use == with bool, but this is more explicit |
-- probably should not use == with bool, but this is more explicit |
||
if |
if accessory == true then |
||
return |
return 'true-cell' |
||
⚫ | |||
['background-color'] = 'lightgreen', |
|||
⚫ | |||
['font-weight'] = 'bold' |
|||
⚫ | |||
⚫ | |||
⚫ | |||
['background-color'] = 'pink', |
|||
['font-weight'] = 'bold' |
|||
⚫ | |||
end |
end |
||
Line 47: | Line 38: | ||
end |
end |
||
local function convertToBoolOrNil(val) |
|||
⚫ | |||
⚫ | |||
function p.main(frame) |
function p.main(frame) |
||
local args = getArgs(frame) |
local args = getArgs(frame, { wrappers = { 'Template:Infobox costume' } }) |
||
local infobox = builder.new() |
local infobox = builder.new() |
||
infobox:setName('Infobox costume') |
infobox:setName('Infobox costume') |
||
:setWidth("330px") |
|||
:setParams{ |
:setParams{ |
||
{ name = 'costume id' }, |
{ name = 'costume id' }, |
||
{ name = 'costume name', default = mw.title.getCurrentTitle().text }, |
{ name = 'costume name', default = mw.title.getCurrentTitle().text }, |
||
{ name = 'thumbnail', |
{ name = 'thumbnail', dFunc = formatImage }, |
||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
Line 64: | Line 57: | ||
{ name = 'designer' }, |
{ name = 'designer' }, |
||
{ name = 'date' }, |
{ name = 'date' }, |
||
{ name = 'unlock' }, |
|||
{ name = 'acquire' }, |
{ name = 'acquire' }, |
||
{ name = 'price' }, |
{ name = 'price' }, |
||
{ name = 'card', |
{ name = 'card', dFunc = formatLink }, |
||
{ name = 'pass' }, |
{ name = 'pass' }, |
||
{ name = 'accessory', |
{ name = 'accessory', pFunc = convertToBoolOrNil, dFunc = formatAccessory }, |
||
{ name = 'unique accessory', |
{ name = 'unique accessory', pFunc = convertToBoolOrNil, dFunc = formatAccessory }, |
||
{ name = 'unique hair', |
{ name = 'unique hair', pFunc = convertToBoolOrNil, dFunc = formatAccessory }, |
||
} |
} |
||
:setArgs(args) |
:setArgs(args) |
||
:processArgs() |
|||
:setCategoryMap({ |
|||
['gender'] = { |
|||
['Ladies'] = 'Ladies\' costumes', |
|||
['Men'] = 'Men\'s costumes' |
|||
}, |
|||
⚫ | |||
⚫ | |||
}, |
|||
⚫ | |||
⚫ | |||
}, |
|||
⚫ | |||
⚫ | |||
}, |
|||
⚫ | |||
infobox |
infobox |
||
Line 81: | Line 92: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Japanese' |
{ tag = 'th', content = 'Japanese' }, |
||
{ tag = 'argtd', content = 'japanese' |
{ tag = 'argtd', content = 'japanese' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'japanese' } } |
{ hideIfEmpty = { 'japanese' } } |
||
Line 88: | Line 99: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Romaji' |
{ tag = 'th', content = 'Romaji' }, |
||
{ tag = 'argtd', content = 'romaji' |
{ tag = 'argtd', content = 'romaji' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'romaji' } } |
{ hideIfEmpty = { 'romaji' } } |
||
Line 95: | Line 106: | ||
:addHeader({ tag = 'th', content = 'Costume Information' }, { subheader = true }) |
:addHeader({ tag = 'th', content = 'Costume Information' }, { subheader = true }) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Gender' |
{ tag = 'th', content = 'Gender' }, |
||
{ tag = 'argtd', content = 'gender' |
{ tag = 'argtd', content = 'gender' } |
||
}) |
}) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Designer' |
{ tag = 'th', content = 'Designer' }, |
||
{ tag = 'argtd', content = 'designer' |
{ tag = 'argtd', content = 'designer' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'designer' } } |
{ hideIfEmpty = { 'designer' } } |
||
Line 107: | Line 118: | ||
:addHeader({ tag = 'th', content = 'Acquisition Information'}, { subheader = true }) |
:addHeader({ tag = 'th', content = 'Acquisition Information'}, { subheader = true }) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Release date' |
{ tag = 'th', content = 'Release date' }, |
||
{ tag = 'argtd', content = 'date' |
{ tag = 'argtd', content = 'date' }, |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = ' |
{ tag = 'th', content = 'Unlock method(s)' }, |
||
{ tag = 'argtd', content = ' |
{ tag = 'argtd', content = 'unlock' } |
||
⚫ | |||
:addRow({ |
|||
{ tag = 'th', content = 'Acquition method(s)' }, |
|||
{ tag = 'argtd', content = 'acquire' }, |
|||
}) |
}) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Price' |
{ tag = 'th', content = 'Price' }, |
||
{ tag = 'argtd', content = 'price' |
{ tag = 'argtd', content = 'price' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'price' } } |
{ hideIfEmpty = { 'price' } } |
||
Line 123: | Line 138: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Associated card' |
{ tag = 'th', content = 'Associated card' }, |
||
{ tag = 'argtd', content = 'card' |
{ tag = 'argtd', content = 'card' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'card' } } |
{ hideIfEmpty = { 'card' } } |
||
Line 130: | Line 145: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Mission Pass' |
{ tag = 'th', content = 'Mission Pass' }, |
||
{ tag = 'argtd', content = 'pass' |
{ tag = 'argtd', content = 'pass' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'pass' } } |
{ hideIfEmpty = { 'pass' } } |
||
Line 142: | Line 157: | ||
{ tag = 'th', content = 'Unique Hair' }, |
{ tag = 'th', content = 'Unique Hair' }, |
||
}, |
}, |
||
{ |
{ defaultCss = { ['text-align'] = 'center' } } |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'argtd', content = 'accessory', |
{ tag = 'argtd', content = 'accessory', classFunc = { getAccessoryClass } }, |
||
{ tag = 'argtd', content = 'unique accessory', |
{ tag = 'argtd', content = 'unique accessory', classFunc = { getAccessoryClass } }, |
||
{ tag = 'argtd', content = 'unique hair', |
{ tag = 'argtd', content = 'unique hair', classFunc = { getAccessoryClass } } |
||
}, |
}, |
||
{ |
{ defaultCss = { ['text-align'] = 'center' } } |
||
) |
) |
||
⚫ | |||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Costumes]]" .. categories |
categories = "[[Category:Costumes]]" .. categories |
||
local procArgs = infobox:getArgs('processed') |
|||
local rawArgs = infobox:getArgs('raw') |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
end |
|||
if rawArgs['gender'] == 'Ladies' then |
|||
categories = categories .. "[[Category:Ladies' costumes]]" |
|||
elseif rawArgs['gender'] == 'Men' then |
|||
categories = categories .. "[[Category:Men's costumes]]" |
|||
end |
|||
end |
end |
||
Revision as of 08:02, 22 January 2022
This module depends on the following other modules: |
To generate {{Infobox costume}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox costume]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local builder = require('Module:InfoboxBuilder new')
local p = {}
local function formatImage(image_name)
return string.format("[[File:%s|128px]]", image_name)
end
local function formatLink(link)
return '[[' .. link .. ']]'
end
local function formatAccessory(accessory)
-- probably should not use == with bool, but this is more explicit
if accessory == true then
return '✓'
elseif accessory == false then
return '✗'
end
return nil
end
local function getAccessoryClass(accessory)
-- probably should not use == with bool, but this is more explicit
if accessory == true then
return 'true-cell'
elseif accessory == false then
return 'false-cell'
end
return nil
end
local function convertToBoolOrNil(val)
return yesno(val, nil)
end
function p.main(frame)
local args = getArgs(frame, { wrappers = { 'Template:Infobox costume' } })
local infobox = builder.new()
infobox:setName('Infobox costume')
:setParams{
{ name = 'costume id' },
{ name = 'costume name', default = mw.title.getCurrentTitle().text },
{ name = 'thumbnail', dFunc = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'gender' },
{ name = 'designer' },
{ name = 'date' },
{ name = 'unlock' },
{ name = 'acquire' },
{ name = 'price' },
{ name = 'card', dFunc = formatLink },
{ name = 'pass' },
{ name = 'accessory', pFunc = convertToBoolOrNil, dFunc = formatAccessory },
{ name = 'unique accessory', pFunc = convertToBoolOrNil, dFunc = formatAccessory },
{ name = 'unique hair', pFunc = convertToBoolOrNil, dFunc = formatAccessory },
}
:setArgs(args)
:processArgs()
:setCategoryMap({
['gender'] = {
['Ladies'] = 'Ladies\' costumes',
['Men'] = 'Men\'s costumes'
},
['accessory'] = {
[true] = 'Costumes with accessories',
},
['unique accessory'] = {
[true] = 'Costumes with unique accessories'
},
['unique hair'] = {
[true] = 'Costumes with unique hair'
},
})
infobox
:addHeader({ tag = 'argth', content = 'costume name' })
:addImage({
{ tag = 'argtd', content = 'thumbnail' },
})
:addRow(
{
{ tag = 'th', content = 'Japanese' },
{ tag = 'argtd', content = 'japanese' }
},
{ hideIfEmpty = { 'japanese' } }
)
:addRow(
{
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji' }
},
{ hideIfEmpty = { 'romaji' } }
)
:addHeader({ tag = 'th', content = 'Costume Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Gender' },
{ tag = 'argtd', content = 'gender' }
})
:addRow(
{
{ tag = 'th', content = 'Designer' },
{ tag = 'argtd', content = 'designer' }
},
{ hideIfEmpty = { 'designer' } }
)
:addHeader({ tag = 'th', content = 'Acquisition Information'}, { subheader = true })
:addRow({
{ tag = 'th', content = 'Release date' },
{ tag = 'argtd', content = 'date' },
})
:addRow({
{ tag = 'th', content = 'Unlock method(s)' },
{ tag = 'argtd', content = 'unlock' }
})
:addRow({
{ tag = 'th', content = 'Acquition method(s)' },
{ tag = 'argtd', content = 'acquire' },
})
:addRow(
{
{ tag = 'th', content = 'Price' },
{ tag = 'argtd', content = 'price' }
},
{ hideIfEmpty = { 'price' } }
)
:addRow(
{
{ tag = 'th', content = 'Associated card' },
{ tag = 'argtd', content = 'card' }
},
{ hideIfEmpty = { 'card' } }
)
:addRow(
{
{ tag = 'th', content = 'Mission Pass' },
{ tag = 'argtd', content = 'pass' }
},
{ hideIfEmpty = { 'pass' } }
)
:addHeader({ tag = 'th', content = 'Accessory & Hair Information' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Accessory' },
{ tag = 'th', content = 'Unique Accessory' },
{ tag = 'th', content = 'Unique Hair' },
},
{ defaultCss = { ['text-align'] = 'center' } }
)
:addRow(
{
{ tag = 'argtd', content = 'accessory', classFunc = { getAccessoryClass } },
{ tag = 'argtd', content = 'unique accessory', classFunc = { getAccessoryClass } },
{ tag = 'argtd', content = 'unique hair', classFunc = { getAccessoryClass } }
},
{ defaultCss = { ['text-align'] = 'center' } }
)
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Costumes]]" .. categories
end
return infobox:tostring() .. categories
end
return p