Content added Content deleted
No edit summary |
m (Testing (will undo)) |
||
Line 1: | Line 1: | ||
-------------------------- |
|||
local ib = require('Module:Infobox character') |
|||
-- Module for [[Template:Infobox character new]] |
|||
------------------------ |
|||
local getArgs = require('Module:Arguments').getArgs |
|||
local InfoboxBuilder = require('Module:InfoboxBuilder') |
|||
local DisplayFns = require('Module:DisplayFunctions') |
|||
local ProcessingFns = require('Module:ProcessingFunctions') |
|||
local constants = require('Module:Constants') |
|||
local p = {} |
local p = {} |
||
local function formatUnit(unit) |
|||
if unit and unit ~= nil then |
|||
return string.format("[[File:%s|150px|link=%s]]", |
|||
constants.get_unit_image(unit), |
|||
constants.get_unit(unit)) |
|||
end |
|||
return nil |
|||
end |
|||
local function formatColor(color) |
|||
if color and color ~= nil then |
|||
return string.format( |
|||
"%s <span style=\"height: 10px; width: 10px; background: %s; display: inline-block;margin-left: 5px; border:1px solid;\"></span>", |
|||
color, |
|||
color |
|||
); |
|||
end |
|||
end |
|||
local function formatSchool(list) |
|||
if list == nil then return nil end |
|||
return table.concat(list, '<br>') |
|||
end |
|||
function p.main(frame) |
function p.main(frame) |
||
local |
local args = getArgs(frame) |
||
local infobox = InfoboxBuilder.new(); |
|||
local test |
|||
infobox:setName('Infobox character new') |
|||
if lang == 'en' then |
|||
:setParams{ |
|||
test = 'Test!' |
|||
{ name = 'character name', default = mw.title.getCurrentTitle().text }, |
|||
else |
|||
{ name = 'character image' }, |
|||
{ name = 'character image 3rd anni'}, |
|||
{ name = 'japanese' }, |
|||
{ name = 'romaji' }, |
|||
{ name = 'english' }, |
|||
{ name = 'unit' }, |
|||
{ name = 'position' }, |
|||
{ name = 'gender' }, |
|||
{ name = 'birthday' }, |
|||
{ name = 'height' }, |
|||
{ name = 'height 3rd anni' }, |
|||
{ name = 'school', fn = ProcessingFns.stringToArray('\n') }, |
|||
{ name = 'school 3rd anni', fn = ProcessingFns.stringToArray('\n') }, |
|||
{ name = 'hobbies', fn = ProcessingFns.stringToArray('\n') }, |
|||
{ name = 'talents', fn = ProcessingFns.stringToArray('\n') }, |
|||
{ name = 'dislikes', fn = ProcessingFns.stringToArray('\n') }, |
|||
{ name = 'bad at', fn = ProcessingFns.stringToArray('\n') }, |
|||
{ name = 'color' }, |
|||
{ name = 'seiyuu', fn = ProcessingFns.stringToArray('\n') } |
|||
} |
|||
:setArgs(args) |
|||
:processArgs() |
|||
if args['color'] and args['color'] ~= '' then |
|||
infobox:setHeaderBackgroundColor(args['color']) |
|||
end |
end |
||
infobox |
|||
:addHeader({ tag = 'argth', content = 'character name' }) |
|||
:addImage({ |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'character image', |
|||
fn = DisplayFns.image('315px'), |
|||
tabName = 'Original' |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'character image 3rd anni', |
|||
fn = DisplayFns.image('315px'), |
|||
tabName = '3rd Anniversary' |
|||
}, |
|||
}) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Japanese' }, |
|||
{ tag = 'argtd', content = 'japanese' } |
|||
} |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Romaji' }, |
|||
{ tag = 'argtd', content = 'romaji' } |
|||
} |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'English' }, |
|||
{ tag = 'argtd', content = 'english' } |
|||
} |
|||
) |
|||
:addHeader({ tag = 'th', content = 'Unit'}, { subheader = true }) |
|||
:addImage{{ |
|||
tag = 'argtd', |
|||
content = 'unit', |
|||
fn = formatUnit |
|||
}} |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Position' }, |
|||
{ tag = 'argtd', content = 'position' } |
|||
}, |
|||
{ hideIfEmpty = { 'position' } } |
|||
) |
|||
:addHeader({ tag = 'th', content = 'Profile' }, { subheader = true }) |
|||
:addPanel({tag = 'th', content = 'Original'} |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Gender' }, |
|||
{ tag = 'argtd', content = 'gender' } |
|||
} |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Birthday' }, |
|||
{ tag = 'argtd', content = 'birthday' } |
|||
} |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Height' }, |
|||
{ tag = 'argtd', content = 'height' } |
|||
} |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'School' }, |
|||
{ tag = 'argtd', content = 'school', fn = formatSchool } |
|||
}, |
|||
{ hideIfEmpty = { 'school' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Hobbies' }, |
|||
{ tag = 'argtd', content = 'hobbies', fn = DisplayFns.list('unbulleted') } |
|||
}, |
|||
{ hideIfEmpty = { 'hobbies' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Talents' }, |
|||
{ tag = 'argtd', content = 'talents', fn = DisplayFns.list('unbulleted') } |
|||
}, |
|||
{ hideIfEmpty = { 'talents' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Dislikes' }, |
|||
{ tag = 'argtd', content = 'dislikes', fn = DisplayFns.list('unbulleted') } |
|||
}, |
|||
{ hideIfEmpty = { 'dislikes' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Bad at' }, |
|||
{ tag = 'argtd', content = 'bad at', fn = DisplayFns.list('unbulleted') } |
|||
}, |
|||
{ hideIfEmpty = { 'bad at' } } |
|||
) |
|||
:addPanel({tag = 'th', content = '3rd Anniversary'} |
|||
):addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Gender' }, |
|||
{ tag = 'argtd', content = 'gender' } |
|||
} |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Birthday' }, |
|||
{ tag = 'argtd', content = 'birthday' } |
|||
} |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Height' }, |
|||
{ tag = 'argtd', content = 'height 3rd anni' } |
|||
}, |
|||
{hideIfEmpty = {'height 3rd anni'}} |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'School' }, |
|||
{ tag = 'argtd', content = 'school 3rd anni', fn = formatSchool } |
|||
}, |
|||
{ hideIfEmpty = { 'school 3rd anni' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Hobbies' }, |
|||
{ tag = 'argtd', content = 'hobbies', fn = DisplayFns.list('unbulleted') } |
|||
}, |
|||
{ hideIfEmpty = { 'hobbies' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Talents' }, |
|||
{ tag = 'argtd', content = 'talents', fn = DisplayFns.list('unbulleted') } |
|||
}, |
|||
{ hideIfEmpty = { 'talents' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Dislikes' }, |
|||
{ tag = 'argtd', content = 'dislikes', fn = DisplayFns.list('unbulleted') } |
|||
}, |
|||
{ hideIfEmpty = { 'dislikes' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Bad at' }, |
|||
{ tag = 'argtd', content = 'bad at', fn = DisplayFns.list('unbulleted') } |
|||
}, |
|||
{ hideIfEmpty = { 'bad at' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Image color' }, |
|||
{ tag = 'argtd', content = 'color', fn = formatColor } |
|||
} |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Seiyuu' }, |
|||
{ tag = 'argtd', content = 'seiyuu', fn = DisplayFns.list('unbulleted') } |
|||
} |
|||
) |
|||
local categories = "" |
|||
if mw.title.getCurrentTitle().namespace == 0 then |
|||
return ib.main(frame) .. test |
|||
categories = "[[Category:Characters]]" .. categories |
|||
end |
|||
return infobox:tostring() .. categories |
|||
end |
end |
||
Revision as of 18:40, 11 October 2023
Documentation for this module may be created at Module:Infobox character/sandbox/doc
--------------------------
-- Module for [[Template:Infobox character new]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')
local constants = require('Module:Constants')
local p = {}
local function formatUnit(unit)
if unit and unit ~= nil then
return string.format("[[File:%s|150px|link=%s]]",
constants.get_unit_image(unit),
constants.get_unit(unit))
end
return nil
end
local function formatColor(color)
if color and color ~= nil then
return string.format(
"%s <span style=\"height: 10px; width: 10px; background: %s; display: inline-block;margin-left: 5px; border:1px solid;\"></span>",
color,
color
);
end
end
local function formatSchool(list)
if list == nil then return nil end
return table.concat(list, '<br>')
end
function p.main(frame)
local args = getArgs(frame)
local infobox = InfoboxBuilder.new();
infobox:setName('Infobox character new')
:setParams{
{ name = 'character name', default = mw.title.getCurrentTitle().text },
{ name = 'character image' },
{ name = 'character image 3rd anni'},
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'english' },
{ name = 'unit' },
{ name = 'position' },
{ name = 'gender' },
{ name = 'birthday' },
{ name = 'height' },
{ name = 'height 3rd anni' },
{ name = 'school', fn = ProcessingFns.stringToArray('\n') },
{ name = 'school 3rd anni', fn = ProcessingFns.stringToArray('\n') },
{ name = 'hobbies', fn = ProcessingFns.stringToArray('\n') },
{ name = 'talents', fn = ProcessingFns.stringToArray('\n') },
{ name = 'dislikes', fn = ProcessingFns.stringToArray('\n') },
{ name = 'bad at', fn = ProcessingFns.stringToArray('\n') },
{ name = 'color' },
{ name = 'seiyuu', fn = ProcessingFns.stringToArray('\n') }
}
:setArgs(args)
:processArgs()
if args['color'] and args['color'] ~= '' then
infobox:setHeaderBackgroundColor(args['color'])
end
infobox
:addHeader({ tag = 'argth', content = 'character name' })
:addImage({
{
tag = 'argtd',
content = 'character image',
fn = DisplayFns.image('315px'),
tabName = 'Original'
},
{
tag = 'argtd',
content = 'character image 3rd anni',
fn = DisplayFns.image('315px'),
tabName = '3rd Anniversary'
},
})
:addRow(
{
{ tag = 'th', content = 'Japanese' },
{ tag = 'argtd', content = 'japanese' }
}
)
:addRow(
{
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji' }
}
)
:addRow(
{
{ tag = 'th', content = 'English' },
{ tag = 'argtd', content = 'english' }
}
)
:addHeader({ tag = 'th', content = 'Unit'}, { subheader = true })
:addImage{{
tag = 'argtd',
content = 'unit',
fn = formatUnit
}}
:addRow(
{
{ tag = 'th', content = 'Position' },
{ tag = 'argtd', content = 'position' }
},
{ hideIfEmpty = { 'position' } }
)
:addHeader({ tag = 'th', content = 'Profile' }, { subheader = true })
:addPanel({tag = 'th', content = 'Original'}
)
:addRow(
{
{ tag = 'th', content = 'Gender' },
{ tag = 'argtd', content = 'gender' }
}
)
:addRow(
{
{ tag = 'th', content = 'Birthday' },
{ tag = 'argtd', content = 'birthday' }
}
)
:addRow(
{
{ tag = 'th', content = 'Height' },
{ tag = 'argtd', content = 'height' }
}
)
:addRow(
{
{ tag = 'th', content = 'School' },
{ tag = 'argtd', content = 'school', fn = formatSchool }
},
{ hideIfEmpty = { 'school' } }
)
:addRow(
{
{ tag = 'th', content = 'Hobbies' },
{ tag = 'argtd', content = 'hobbies', fn = DisplayFns.list('unbulleted') }
},
{ hideIfEmpty = { 'hobbies' } }
)
:addRow(
{
{ tag = 'th', content = 'Talents' },
{ tag = 'argtd', content = 'talents', fn = DisplayFns.list('unbulleted') }
},
{ hideIfEmpty = { 'talents' } }
)
:addRow(
{
{ tag = 'th', content = 'Dislikes' },
{ tag = 'argtd', content = 'dislikes', fn = DisplayFns.list('unbulleted') }
},
{ hideIfEmpty = { 'dislikes' } }
)
:addRow(
{
{ tag = 'th', content = 'Bad at' },
{ tag = 'argtd', content = 'bad at', fn = DisplayFns.list('unbulleted') }
},
{ hideIfEmpty = { 'bad at' } }
)
:addPanel({tag = 'th', content = '3rd Anniversary'}
):addRow(
{
{ tag = 'th', content = 'Gender' },
{ tag = 'argtd', content = 'gender' }
}
)
:addRow(
{
{ tag = 'th', content = 'Birthday' },
{ tag = 'argtd', content = 'birthday' }
}
)
:addRow(
{
{ tag = 'th', content = 'Height' },
{ tag = 'argtd', content = 'height 3rd anni' }
},
{hideIfEmpty = {'height 3rd anni'}}
)
:addRow(
{
{ tag = 'th', content = 'School' },
{ tag = 'argtd', content = 'school 3rd anni', fn = formatSchool }
},
{ hideIfEmpty = { 'school 3rd anni' } }
)
:addRow(
{
{ tag = 'th', content = 'Hobbies' },
{ tag = 'argtd', content = 'hobbies', fn = DisplayFns.list('unbulleted') }
},
{ hideIfEmpty = { 'hobbies' } }
)
:addRow(
{
{ tag = 'th', content = 'Talents' },
{ tag = 'argtd', content = 'talents', fn = DisplayFns.list('unbulleted') }
},
{ hideIfEmpty = { 'talents' } }
)
:addRow(
{
{ tag = 'th', content = 'Dislikes' },
{ tag = 'argtd', content = 'dislikes', fn = DisplayFns.list('unbulleted') }
},
{ hideIfEmpty = { 'dislikes' } }
)
:addRow(
{
{ tag = 'th', content = 'Bad at' },
{ tag = 'argtd', content = 'bad at', fn = DisplayFns.list('unbulleted') }
},
{ hideIfEmpty = { 'bad at' } }
)
:addRow(
{
{ tag = 'th', content = 'Image color' },
{ tag = 'argtd', content = 'color', fn = formatColor }
}
)
:addRow(
{
{ tag = 'th', content = 'Seiyuu' },
{ tag = 'argtd', content = 'seiyuu', fn = DisplayFns.list('unbulleted') }
}
)
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Characters]]" .. categories
end
return infobox:tostring() .. categories
end
return p