Content added Content deleted
mNo edit summary |
(updated to infobox builder) |
||
Line 2: | Line 2: | ||
-- Module for [[Template:Infobox Card]] |
-- Module for [[Template:Infobox Card]] |
||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
|||
local builder = require('Module:InfoboxBuilder') |
|||
local constants = require('Module:Constants') |
|||
local utils = require('Module:Utilities') |
|||
local icons = require('Module:Icons')._main |
|||
local getArgs = require('Module:Arguments').getArgs |
|||
local p = {} |
local p = {} |
||
local |
local categories = "" |
||
local width = '330px' |
|||
local function formatImage(image_name) |
|||
local root |
|||
return string.format("[[File:%s|220px]]", image_name) |
|||
local colors = { |
|||
cute = { bg = '#ff70a8', text = '#ffffff' }, |
|||
cool = { bg = '#435cff', text = '#ffffff'}, |
|||
pure = { bg = '#00bf51', text = '#ffffff'}, |
|||
happy = { bg = '#ff9821', text = '#ffffff'}, |
|||
mysterious = { bg = '#8651bc', text = '#ffffff' } |
|||
} |
|||
local palette = { bg = '#000000', text = '#FFFFFF' } |
|||
local units = { |
|||
vs = { image = 'Virtualsingerlogo.png', link = 'VIRTUAL SINGER' }, |
|||
ln = { image = 'Leoneedlogo.png', link = 'Leo/need' }, |
|||
mmj = { image = 'MMJ_logo.png', link = 'MORE MORE JUMP!'}, |
|||
vbs = { image = 'Vivid_logo.png', link = 'Vivid BAD SQUAD'}, |
|||
wxs = { image = 'Wonderlandsxswowtimelogo.png', link = 'Wonderlands×Showtime' }, |
|||
['25ji'] = { image = '25ji-logo.png', link = '25-ji, Night Code de.' } |
|||
} |
|||
local function addHeader(label) |
|||
root:tag('tr') |
|||
:tag('th') |
|||
:attr('colspan', 30) |
|||
:css({ |
|||
['text-align'] = 'center', |
|||
['background-color'] = palette.bg, |
|||
color = palette.text |
|||
}) |
|||
:wikitext(label) |
|||
end |
end |
||
local function |
local function formatAttribute(attribute) |
||
if |
if attribute and attribute ~= '' then |
||
return string.format( |
|||
root:tag('tr') |
|||
"%s %s", |
|||
:attr('id', label) |
|||
icons({ attribute, size = '20px' }), |
|||
:tag('th') |
|||
utils.capitalize(attribute) |
|||
:attr('colspan', 12) |
|||
) |
|||
:css('text-align', 'left') |
|||
:wikitext(label) |
|||
:done() |
|||
:tag('td') |
|||
:attr('colspan', 18) |
|||
:wikitext(data) |
|||
:done() |
|||
end |
end |
||
return nil |
|||
end |
end |
||
local function |
local function formatRarity(rarity) |
||
if rarity and |
|||
local image_size = 300 |
|||
rarity ~= '' and |
|||
tonumber(rarity) >= 1 and |
|||
if untrained and rarity then |
|||
tonumber(rarity) <= 4 then |
|||
local images = |
|||
return icons({ value .. " star", size = '20px' }) |
|||
string.format( |
|||
'Untrained=[[File:%s|%dpx]]', |
|||
untrained, |
|||
image_size) |
|||
if tonumber(rarity) > 2 then |
|||
images = |
|||
images |
|||
.. |
|||
string.format( |
|||
'|-|Trained=[[File:%s|%dpx]]', |
|||
trained, |
|||
image_size) |
|||
end |
|||
root:tag('tr') |
|||
:tag('td') |
|||
:attr('colspan', 30) |
|||
:css('text-align', 'center') |
|||
:wikitext(_frame:callParserFunction({ |
|||
name = '#tag', |
|||
args = { 'tabber', images } |
|||
})) |
|||
end |
end |
||
end |
|||
return nil |
|||
local function addUnit(unit, subunit) |
|||
if unit and units[unit] then |
|||
local unit_info = units[unit] |
|||
root:tag('tr') |
|||
:tag('td') |
|||
:attr('colspan', 30) |
|||
:css('text-align', 'center') |
|||
:wikitext( |
|||
string.format( |
|||
"[[File:%s|150px|link=%s]]", |
|||
unit_info.image, |
|||
unit_info.link |
|||
)) |
|||
end |
|||
if unit == 'vs' and subunit and units[subunit] then |
|||
local subunit_info = units[subunit] |
|||
root:tag('tr') |
|||
:tag('td') |
|||
:attr('colspan', 30) |
|||
:css('text-align', 'center') |
|||
:wikitext( |
|||
string.format( |
|||
"[[File:%s|100px|link=%s]]", |
|||
subunit_info.image, |
|||
subunit_info.link |
|||
)) |
|||
end |
|||
end |
end |
||
local function |
local function formatUnit(unit) |
||
if |
if unit and unit ~= '' then |
||
return string.format( |
|||
addRow( |
|||
"%s [[%s]]", |
|||
icons({ unit, size = '20px' }), |
|||
_frame:expandTemplate({ |
|||
constants.get_unit(unit) |
|||
title = 'Icons', |
|||
args = { attr, size='20px' } |
|||
}) .. ' ' .. attr:sub(1, 1):upper() .. attr:sub(2, -1) |
|||
) |
) |
||
end |
|||
return nil |
|||
end |
end |
||
local function |
local function formatToLink(val) |
||
if |
if val and val ~= '' then |
||
return '[[' .. val .. ']]' |
|||
addRow( |
|||
'Rarity', |
|||
_frame:expandTemplate({ |
|||
title = 'Icons', |
|||
args = { string.format("%sstar", rarity), size = '20px'} |
|||
}) |
|||
) |
|||
end |
end |
||
return nil |
|||
end |
end |
||
local function addStatsRow(label, data1, data2) |
|||
root:tag('tr') |
|||
:attr('id', label) |
|||
:tag('th') |
|||
:attr('colspan', 12) |
|||
:css('text-align', 'left') |
|||
:wikitext(label) |
|||
:done() |
|||
:tag('td') |
|||
:attr('colspan', 9) |
|||
:wikitext(data1) |
|||
:done() |
|||
:tag('td') |
|||
:attr('colspan', 9) |
|||
:wikitext(data2) |
|||
:done() |
|||
end |
|||
local function addStats( |
|||
rarity, |
|||
min_performance, max_performance, |
|||
min_technique, max_technique, |
|||
min_stamina, max_stamina) |
|||
local levels = { |
|||
['1'] = 20, |
|||
['2'] = 30, |
|||
['3'] = 50, |
|||
['4'] = 60 |
|||
} |
|||
local stats = { |
|||
performance = { |
|||
['min'] = tonumber(min_performance) or 0, |
|||
['max'] = tonumber(max_performance) or 0 |
|||
}, |
|||
technique = { |
|||
['min'] = tonumber(min_technique) or 0, |
|||
['max'] = tonumber(max_technique) or 0 |
|||
}, |
|||
stamina = { |
|||
['min'] = tonumber(min_stamina) or 0, |
|||
['max'] = tonumber(max_stamina) or 0 |
|||
}, |
|||
} |
|||
stats['power'] = { |
|||
['min'] = stats['performance']['min'] + stats['technique']['min'] + stats['stamina']['min'], |
|||
['max'] = stats['performance']['max'] + stats['technique']['max'] + stats['stamina']['max'] |
|||
} |
|||
addHeader('Card Stats') |
|||
addStatsRow('', 'Lvl. 1', 'Lvl. ' .. levels[rarity]) |
|||
addStatsRow('Performance', stats['performance']['min'], stats['performance']['max']) |
|||
addStatsRow('Technique', stats['technique']['min'], stats['technique']['max']) |
|||
addStatsRow('Stamina', stats['stamina']['min'], stats['stamina']['max']) |
|||
addStatsRow('Power', stats['power']['min'], stats['power']['max']) |
|||
end |
|||
local function addSideStories(story1, story2) |
|||
root:tag('tr') |
|||
:tag('td') |
|||
:attr('colspan', 15) |
|||
:tag('div') |
|||
:css({ |
|||
['background-color'] = palette.bg, |
|||
['text-align'] = 'center', |
|||
padding = '5px', |
|||
['border-radius'] = '5px', |
|||
margin = '2px' |
|||
}) |
|||
:wikitext(string.format( |
|||
'[[%s|<span style="color:%s">Side Story 1</span>]]', |
|||
story1 or '/Side Story 1', |
|||
palette.text)) |
|||
:done() |
|||
:done() |
|||
:tag('td') |
|||
:attr('colspan', 15) |
|||
:tag('div') |
|||
:css({ |
|||
['background-color'] = palette.bg, |
|||
['text-align'] = 'center', |
|||
padding = '5px', |
|||
['border-radius'] = '5px', |
|||
margin = '2px' |
|||
}) |
|||
:wikitext(string.format( |
|||
'[[%s|<span style="color:%s">Side Story 2</span>]]', |
|||
story2 or '/Side Story 2', |
|||
palette.text)) |
|||
:done() |
|||
:done() |
|||
end |
|||
function p.main(frame) |
function p.main(frame) |
||
local args = getArgs(frame) |
|||
local infobox = builder.new() |
|||
args = getArgs(frame) |
|||
infobox:setName('Infobox Card') |
|||
if args['bg color'] or args['text color'] then |
|||
:setWidth("330px") |
|||
if args['bg color'] then |
|||
:setParams{ |
|||
palette.bg = args['bg color'] |
|||
{ name = 'card id' }, |
|||
end |
|||
{ name = 'card name', default = mw.title.getCurrentTitle().text }, |
|||
if args['text color'] then |
|||
{ name = 'thumbnail', func = formatImage }, |
|||
palette.text = args['text color'] |
|||
{ name = 'thumbnail trained', func = formatImage }, |
|||
end |
|||
{ name = 'japanese' }, |
|||
elseif args['attribute'] and colors[args['attribute']] then |
|||
{ name = 'romaji' }, |
|||
palette = colors[args['attribute']] |
|||
{ name = 'character' }, |
|||
end |
|||
{ name = 'attribute', func = formatAttribute }, |
|||
{ name = 'rarity', func = formatRarity }, |
|||
{ name = 'unit', func = formatUnit }, |
|||
{ name = 'support unit' , func = formatUnit}, |
|||
{ name = 'status' }, |
|||
{ name = 'date' }, |
|||
{ name = 'obtain' }, |
|||
{ name = 'event', func = formatToLink }, |
|||
{ name = 'banner', func = formatToLink } |
|||
} |
|||
:setArgs(args) |
|||
:setHeaderColorsByParam('attribute', constants.get_attribute_colors) |
|||
infobox |
|||
:addHeader({ tag = 'argth', content = 'card name' }) |
|||
:addImage( |
|||
{ |
|||
{ tag = 'argtd', content = 'thumbnail', title = 'Untrained' }, |
|||
{ tag = 'argtd', content = 'thumbnail trained', title = 'Trained' } |
|||
} |
|||
) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Japanese', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'japanese', colspan = 18 } |
|||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Romaji', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'romaji', colspan = 18 } |
|||
}) |
|||
:addHeader({ tag = 'th', content = 'Card Information' }, { subheader = true }) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Character', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'character', colspan = 18 } |
|||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Attribute', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'attribute', colspan = 18 } |
|||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Unit', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'unit', colspan = 18 } |
|||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Support Unit', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'support unit', colspan = 18 } |
|||
}) |
|||
:addHeader({ tag = 'th', content = 'Obtainment Information' }, { subheader = true }) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Status', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'status', colspan = 18 } |
|||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Release Date', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'date', colspan = 18 } |
|||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Obtainment Method', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'obtain', colspan = 18 } |
|||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Associated Event', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'event', colspan = 18 } |
|||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Debut Banner', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'banner', colspan = 18 } |
|||
}) |
|||
if mw.title.getCurrentTitle().namespace == 0 then |
|||
root = mw.html.create('table') |
|||
categories = "[[Category:Cards]]" .. categories |
|||
root |
|||
:addClass('infobox') |
|||
:css('width', width) |
|||
addHeader(args['title']) |
|||
addCardArt(args['rarity'], args['untrained'], args['trained']) |
|||
addRow('Japanese', args['japanese']) |
|||
addRow('Romaji', args['romaji']) |
|||
addHeader('Unit') |
|||
addUnit(args['unit'], args['subunit']) |
|||
addHeader('Card Information') |
|||
addRow('Character', args['character']) |
|||
addAttribute(args['attribute']) |
|||
addRarity(args['rarity']) |
|||
addRow('Status', args['status']) |
|||
addRow('Card Debut', args['debut']) |
|||
addRow('Release Date', args['date']) |
|||
addStats( |
|||
args['rarity'], |
|||
args['min performance'], args['max performance'], |
|||
args['min technique'], args['max technique'], |
|||
args['min stamina'], args['max stamina'] |
|||
) |
|||
addHeader('Side Stories') |
|||
addSideStories(args['story 1'], args['story 2']) |
|||
local spacer = root:tag('tr') |
|||
for i=1,30,1 do |
|||
spacer:tag('td') |
|||
:attr('colspan', 1) |
|||
:css('width', 'calc(100% / 30)') |
|||
end |
end |
||
return tostring( |
return infobox:tostring() .. categories |
||
end |
end |
||
Revision as of 05:46, 12 August 2021
This module depends on the following other modules: |
To generate {{Infobox card}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox Card]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local builder = require('Module:InfoboxBuilder')
local constants = require('Module:Constants')
local utils = require('Module:Utilities')
local icons = require('Module:Icons')._main
local p = {}
local categories = ""
local function formatImage(image_name)
return string.format("[[File:%s|220px]]", image_name)
end
local function formatAttribute(attribute)
if attribute and attribute ~= '' then
return string.format(
"%s %s",
icons({ attribute, size = '20px' }),
utils.capitalize(attribute)
)
end
return nil
end
local function formatRarity(rarity)
if rarity and
rarity ~= '' and
tonumber(rarity) >= 1 and
tonumber(rarity) <= 4 then
return icons({ value .. " star", size = '20px' })
end
return nil
end
local function formatUnit(unit)
if unit and unit ~= '' then
return string.format(
"%s [[%s]]",
icons({ unit, size = '20px' }),
constants.get_unit(unit)
)
end
return nil
end
local function formatToLink(val)
if val and val ~= '' then
return '[[' .. val .. ']]'
end
return nil
end
function p.main(frame)
local args = getArgs(frame)
local infobox = builder.new()
infobox:setName('Infobox Card')
:setWidth("330px")
:setParams{
{ name = 'card id' },
{ name = 'card name', default = mw.title.getCurrentTitle().text },
{ name = 'thumbnail', func = formatImage },
{ name = 'thumbnail trained', func = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'character' },
{ name = 'attribute', func = formatAttribute },
{ name = 'rarity', func = formatRarity },
{ name = 'unit', func = formatUnit },
{ name = 'support unit' , func = formatUnit},
{ name = 'status' },
{ name = 'date' },
{ name = 'obtain' },
{ name = 'event', func = formatToLink },
{ name = 'banner', func = formatToLink }
}
:setArgs(args)
:setHeaderColorsByParam('attribute', constants.get_attribute_colors)
infobox
:addHeader({ tag = 'argth', content = 'card name' })
:addImage(
{
{ tag = 'argtd', content = 'thumbnail', title = 'Untrained' },
{ tag = 'argtd', content = 'thumbnail trained', title = 'Trained' }
}
)
:addRow({
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
})
:addHeader({ tag = 'th', content = 'Card Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Character', colspan = 12 },
{ tag = 'argtd', content = 'character', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Attribute', colspan = 12 },
{ tag = 'argtd', content = 'attribute', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Unit', colspan = 12 },
{ tag = 'argtd', content = 'unit', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Support Unit', colspan = 12 },
{ tag = 'argtd', content = 'support unit', colspan = 18 }
})
:addHeader({ tag = 'th', content = 'Obtainment Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Status', colspan = 12 },
{ tag = 'argtd', content = 'status', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Release Date', colspan = 12 },
{ tag = 'argtd', content = 'date', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Obtainment Method', colspan = 12 },
{ tag = 'argtd', content = 'obtain', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Associated Event', colspan = 12 },
{ tag = 'argtd', content = 'event', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Debut Banner', colspan = 12 },
{ tag = 'argtd', content = 'banner', colspan = 18 }
})
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Cards]]" .. categories
end
return infobox:tostring() .. categories
end
return p