Content added Content deleted
mNo edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local |
local InfoboxBuilder = require('Module:InfoboxBuilder new') |
||
local |
local DisplayFns = require('Module:InfoboxBuilderDisplayFunctions') |
||
local ProcessingFns = require('Module:InfoboxBuilderProcessingFunctions') |
|||
local constants = require('Module:Constants') |
local constants = require('Module:Constants') |
||
local utils = require('Module:Utilities') |
|||
local VariablesLua = mw.ext.VariablesLua |
local VariablesLua = mw.ext.VariablesLua |
||
local p = {} |
local p = {} |
||
local function convertToBoolOrNil(val) |
|||
return yesno(val, nil) |
|||
end |
|||
local function formatJacket(jacket) |
|||
return string.format("[[File:%s|220px]]", jacket) |
|||
end |
|||
local function formatList(list) |
|||
if #list < 2 then |
|||
return list[1] |
|||
end |
|||
local ul = mw.html.create('ul') |
|||
for i=1,#list do |
|||
ul:tag('li') |
|||
:wikitext(list[i]) |
|||
end |
|||
return tostring(ul) |
|||
end |
|||
local function formatCommissioned(comm) |
|||
-- probably should not use == with bool, but this is more explicit |
|||
if comm == true then |
|||
return 'Yes' |
|||
elseif comm == false then |
|||
return 'No' |
|||
end |
|||
return nil |
|||
end |
|||
local function formatMv(mv) |
|||
-- probably should not use == with bool, but this is more explicit |
|||
if mv == true then |
|||
return '✓' |
|||
elseif mv == false then |
|||
return '✗' |
|||
end |
|||
return nil |
|||
end |
|||
local function getMvClass(mv) |
local function getMvClass(mv) |
||
Line 89: | Line 43: | ||
function p.main(frame) |
function p.main(frame) |
||
local args = getArgs(frame) |
local args = getArgs(frame) |
||
local infobox = |
local infobox = InfoboxBuilder.new(); |
||
infobox:setName('Infobox song') |
infobox:setName('Infobox song new') |
||
:setParams{ |
:setParams{ |
||
{ name = 'song id' }, |
{ name = 'song id' }, |
||
{ name = 'song name', default = mw.title.getCurrentTitle().text }, |
{ name = 'song name', default = mw.title.getCurrentTitle().text }, |
||
{ name = 'jacket' |
{ name = 'jacket', default = 'Dummyalbumart.png' }, |
||
{ name = 'jacket alt' |
{ name = 'jacket alt' }, |
||
{ name = 'jacket alt 2' }, |
|||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'english' }, |
{ name = 'english' }, |
||
{ name = 'singers', |
{ name = 'singers', fn = ProcessingFns.stringToArray(',') }, |
||
{ name = 'producers', |
{ name = 'producers', fn = ProcessingFns.stringToArray(',') }, |
||
{ name = 'duration' }, |
{ name = 'duration' }, |
||
{ name = 'units', |
{ name = 'units', fn = ProcessingFns.stringToArray(';') }, |
||
{ name = 'unlock' }, |
{ name = 'unlock' }, |
||
{ name = 'arrangers', |
{ name = 'arrangers', fn = ProcessingFns.stringToArray(',') }, |
||
{ name = 'composers', |
{ name = 'composers', fn = ProcessingFns.stringToArray(',') }, |
||
{ name = 'lyricists', |
{ name = 'lyricists', fn = ProcessingFns.stringToArray(',') }, |
||
{ name = 'commissioned', |
{ name = 'commissioned', fn = ProcessingFns.stringToBoolOrNil }, |
||
{ name = 'contest winner', |
{ name = 'contest winner', fn = ProcessingFns.stringToBoolOrNil, default = false }, |
||
{ name = 'bpm' }, |
{ name = 'bpm' }, |
||
{ name = 'game duration' }, |
{ name = 'game duration' }, |
||
{ name = 'date' }, |
{ name = 'date' }, |
||
{ name = '3d mv', |
{ name = '3d mv', fn = ProcessingFns.stringToBoolOrNil }, |
||
{ name = '2d mv', |
{ name = '2d mv', fn = ProcessingFns.stringToBoolOrNil }, |
||
{ name = 'original mv', |
{ name = 'original mv', fn = ProcessingFns.stringToBoolOrNil }, |
||
{ name = 'easy difficulty' }, |
{ name = 'easy difficulty' }, |
||
{ name = 'normal difficulty' }, |
{ name = 'normal difficulty' }, |
||
Line 163: | Line 118: | ||
infobox |
infobox |
||
:addHeader({ tag = 'argth', content = 'song name' }) |
:addHeader({ tag = 'argth', content = 'song name' }) |
||
:addImage( |
:addImage({ |
||
{ |
|||
tag = 'argtd', |
|||
content = 'jacket', |
|||
fn = DisplayFns.image('220px'), |
|||
tabName = 'Original' |
|||
}, |
|||
{ |
{ |
||
tag = 'argtd', |
|||
content = 'jacket alt', |
|||
fn = DisplayFns.image('220px'), |
|||
} |
|||
tabName = 'Alternate' |
|||
) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'jacket alt 2', |
|||
fn = DisplayFns.image('220px'), |
|||
tabName = 'Alternate #2' |
|||
}, |
|||
}) |
|||
:addRow( |
:addRow( |
||
{ |
{ |
||
Line 193: | Line 162: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ |
|||
{ tag = 'th', content = 'Original singer(s)' }, |
|||
tag = 'argth', |
|||
content = 'singers', |
|||
fn = DisplayFns.pluralHeader({ 'Original singer', 'Original singers' }) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'singers', |
|||
fn = DisplayFns.list('unbulleted') |
|||
} |
|||
}, |
}, |
||
{ hideIfEmpty = { 'singers' } } |
{ hideIfEmpty = { 'singers' } } |
||
Line 200: | Line 177: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ |
|||
{ tag = 'th', content = 'Producer(s)' }, |
|||
tag = 'argth', |
|||
content = 'producers', |
|||
fn = DisplayFns.pluralHeader({ 'Producer', 'Producers' }) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'producers', |
|||
fn = DisplayFns.list('unbulleted') |
|||
} |
|||
} |
} |
||
) |
) |
||
Line 220: | Line 205: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ |
|||
{ tag = 'th', content = 'Unit(s)' }, |
|||
tag = 'argth', |
|||
content = 'units', |
|||
fn = DisplayFns.pluralHeader({ 'Unit', 'Units' }) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'units', |
|||
fn = DisplayFns.list('unbulleted') |
|||
} |
|||
} |
} |
||
) |
) |
||
Line 232: | Line 225: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ |
|||
{ tag = 'th', content = 'Arranger(s)' }, |
|||
tag = 'argth', |
|||
content = 'arrangers', |
|||
fn = DisplayFns.pluralHeader({ 'Arranger', 'Arranger(s)' }) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'arrangers', |
|||
fn = DisplayFns.list('unbulleted') |
|||
} |
|||
}, |
}, |
||
{ hideIfEmpty = { 'arrangers' } } |
{ hideIfEmpty = { 'arrangers' } } |
||
Line 239: | Line 240: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ |
|||
{ tag = 'th', content = 'Composer(s)' }, |
|||
tag = 'argth', |
|||
content = 'composers', |
|||
fn = DisplayFns.pluralHeader({ 'Composer', 'Composer(s)' }) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'composers', |
|||
fn = DisplayFns.list('unbulleted') |
|||
} |
|||
}, |
}, |
||
{ hideIfEmpty = { 'composers' } } |
{ hideIfEmpty = { 'composers' } } |
||
Line 246: | Line 255: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ |
|||
{ tag = 'th', content = 'Lyricist(s)' }, |
|||
tag = 'argth', |
|||
content = 'lyricists', |
|||
fn = DisplayFns.pluralHeader({ 'Lyricist', 'Lyricists' }) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'lyricists', |
|||
fn = DisplayFns.list('unbulleted') |
|||
} |
|||
}, |
}, |
||
{ hideIfEmpty = { 'lyricists' } } |
{ hideIfEmpty = { 'lyricists' } } |
||
Line 254: | Line 271: | ||
{ |
{ |
||
{ tag = 'th', content = 'Commissioned?' }, |
{ tag = 'th', content = 'Commissioned?' }, |
||
{ tag = 'argtd', content = 'commissioned' } |
{ tag = 'argtd', content = 'commissioned', fn = DisplayFns.yesAndNo } |
||
} |
} |
||
) |
) |
||
Line 286: | Line 303: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ |
|||
{ tag = 'argtd', content = '3d mv', classFuncs = { getMvClass } }, |
|||
tag = 'argtd', |
|||
content = '3d mv', |
|||
fn = DisplayFns.checkAndX, |
|||
classFns = { getMvClass } |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = '2d mv', |
|||
fn = DisplayFns.checkAndX, |
|||
classFns = { getMvClass } |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'original mv', |
|||
fn = DisplayFns.checkAndX, |
|||
classFns = { getMvClass } |
|||
}, |
|||
}, |
}, |
||
{ defaultCss = { ['text-align'] = 'center' } } |
{ defaultCss = { ['text-align'] = 'center' } } |
Revision as of 02:27, 18 October 2022
This module depends on the following other modules: |
To generate {{Infobox song}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox song]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder new')
local DisplayFns = require('Module:InfoboxBuilderDisplayFunctions')
local ProcessingFns = require('Module:InfoboxBuilderProcessingFunctions')
local constants = require('Module:Constants')
local VariablesLua = mw.ext.VariablesLua
local p = {}
local function getMvClass(mv)
-- probably should not use == with bool, but this is more explicit
if mv == true then
return 'true-cell'
elseif mv == false then
return 'false-cell'
end
return nil
end
local function difficultiesRow()
local difficulties = { 'Easy', 'Normal', 'Hard', 'Expert', 'Master' }
local row = {}
for _,v in ipairs(difficulties) do
table.insert(row,
{
content = v,
tag = 'th',
css = { ['border-bottom-color'] = constants.get_difficulty_color(v) }
}
)
end
return row
end
function p.main(frame)
local args = getArgs(frame)
local infobox = InfoboxBuilder.new();
infobox:setName('Infobox song new')
:setParams{
{ name = 'song id' },
{ name = 'song name', default = mw.title.getCurrentTitle().text },
{ name = 'jacket', default = 'Dummyalbumart.png' },
{ name = 'jacket alt' },
{ name = 'jacket alt 2' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'english' },
{ name = 'singers', fn = ProcessingFns.stringToArray(',') },
{ name = 'producers', fn = ProcessingFns.stringToArray(',') },
{ name = 'duration' },
{ name = 'units', fn = ProcessingFns.stringToArray(';') },
{ name = 'unlock' },
{ name = 'arrangers', fn = ProcessingFns.stringToArray(',') },
{ name = 'composers', fn = ProcessingFns.stringToArray(',') },
{ name = 'lyricists', fn = ProcessingFns.stringToArray(',') },
{ name = 'commissioned', fn = ProcessingFns.stringToBoolOrNil },
{ name = 'contest winner', fn = ProcessingFns.stringToBoolOrNil, default = false },
{ name = 'bpm' },
{ name = 'game duration' },
{ name = 'date' },
{ name = '3d mv', fn = ProcessingFns.stringToBoolOrNil },
{ name = '2d mv', fn = ProcessingFns.stringToBoolOrNil },
{ name = 'original mv', fn = ProcessingFns.stringToBoolOrNil },
{ name = 'easy difficulty' },
{ name = 'normal difficulty' },
{ name = 'hard difficulty' },
{ name = 'expert difficulty' },
{ name = 'master difficulty' },
{ name = 'easy notes' },
{ name = 'normal notes' },
{ name = 'hard notes' },
{ name = 'expert notes' },
{ name = 'master notes' },
}
:setArgs(args)
:processArgs()
:setCategoryMap({
['units'] = {
['VIRTUAL SINGER'] = 'VIRTUAL SINGER songs',
['Leo/need'] = 'Leo/need songs',
['MORE MORE JUMP!'] = 'MORE MORE JUMP! songs',
['Vivid BAD SQUAD'] = 'Vivid BAD SQUAD songs',
['Wonderlands×Showtime'] = 'Wonderlands×Showtime songs',
['25-ji, Nightcord de.'] = '25-ji, Nightcord de. songs',
['Other'] = 'Other songs'
},
['unlock'] = {
['Automatic'] = 'Songs unlocked automatically',
['Music Shop'] = 'Songs unlocked from the Music Shop',
['Present Box'] = 'Songs unlocked from the Present Box',
},
['commissioned'] = {
[true] = 'Commissioned songs',
},
['contest winner'] = {
[true] = 'Contest winning songs'
},
['3d mv'] = {
[true] = 'Songs with 3D MV'
},
['2d mv'] = {
[true] = 'Songs with 2D MV'
},
['original mv'] = {
[true] = 'Songs with Original MV'
},
})
infobox
:addHeader({ tag = 'argth', content = 'song name' })
:addImage({
{
tag = 'argtd',
content = 'jacket',
fn = DisplayFns.image('220px'),
tabName = 'Original'
},
{
tag = 'argtd',
content = 'jacket alt',
fn = DisplayFns.image('220px'),
tabName = 'Alternate'
},
{
tag = 'argtd',
content = 'jacket alt 2',
fn = DisplayFns.image('220px'),
tabName = 'Alternate #2'
},
})
:addRow(
{
{ tag = 'th', content = 'Japanese' },
{ tag = 'argtd', content = 'japanese' }
},
{ hideIfEmpty = { 'japanese' } }
)
:addRow(
{
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji' }
},
{ hideIfEmpty = { 'romaji' } }
)
:addRow(
{
{ tag = 'th', content = 'English' },
{ tag = 'argtd', content = 'english' }
},
{ hideIfEmpty = { 'english' } }
)
:addHeader({ tag = 'th', content = 'Song Information' }, { subheader = true })
:addRow(
{
{
tag = 'argth',
content = 'singers',
fn = DisplayFns.pluralHeader({ 'Original singer', 'Original singers' })
},
{
tag = 'argtd',
content = 'singers',
fn = DisplayFns.list('unbulleted')
}
},
{ hideIfEmpty = { 'singers' } }
)
:addRow(
{
{
tag = 'argth',
content = 'producers',
fn = DisplayFns.pluralHeader({ 'Producer', 'Producers' })
},
{
tag = 'argtd',
content = 'producers',
fn = DisplayFns.list('unbulleted')
}
}
)
:addRow(
{
{ tag = 'th', content = 'Duration' },
{ tag = 'argtd', content = 'duration' }
},
{ hideIfEmpty = { 'duration' } }
)
:addHeader({ tag = 'th', content = 'In-game Information' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Song ID' },
{ tag = 'argtd', content = 'song id' }
}
)
:addRow(
{
{
tag = 'argth',
content = 'units',
fn = DisplayFns.pluralHeader({ 'Unit', 'Units' })
},
{
tag = 'argtd',
content = 'units',
fn = DisplayFns.list('unbulleted')
}
}
)
:addRow(
{
{ tag = 'th', content = 'How to unlock' },
{ tag = 'argtd', content = 'unlock' }
}
)
:addRow(
{
{
tag = 'argth',
content = 'arrangers',
fn = DisplayFns.pluralHeader({ 'Arranger', 'Arranger(s)' })
},
{
tag = 'argtd',
content = 'arrangers',
fn = DisplayFns.list('unbulleted')
}
},
{ hideIfEmpty = { 'arrangers' } }
)
:addRow(
{
{
tag = 'argth',
content = 'composers',
fn = DisplayFns.pluralHeader({ 'Composer', 'Composer(s)' })
},
{
tag = 'argtd',
content = 'composers',
fn = DisplayFns.list('unbulleted')
}
},
{ hideIfEmpty = { 'composers' } }
)
:addRow(
{
{
tag = 'argth',
content = 'lyricists',
fn = DisplayFns.pluralHeader({ 'Lyricist', 'Lyricists' })
},
{
tag = 'argtd',
content = 'lyricists',
fn = DisplayFns.list('unbulleted')
}
},
{ hideIfEmpty = { 'lyricists' } }
)
:addRow(
{
{ tag = 'th', content = 'Commissioned?' },
{ tag = 'argtd', content = 'commissioned', fn = DisplayFns.yesAndNo }
}
)
:addRow(
{
{ tag = 'th', content = 'BPM' },
{ tag = 'argtd', content = 'bpm' }
}
)
:addRow(
{
{ tag = 'th', content = 'Duration (game)' },
{ tag = 'argtd', content = 'game duration' }
}
)
:addRow(
{
{ tag = 'th', content = 'Release date' },
{ tag = 'argtd', content = 'date' }
}
)
:addHeader({ tag = 'th', content = 'Music Video' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = '3D' },
{ tag = 'th', content = '2D' },
{ tag = 'th', content = 'Original' }
},
{ defaultCss = { ['text-align'] = 'center' } }
)
:addRow(
{
{
tag = 'argtd',
content = '3d mv',
fn = DisplayFns.checkAndX,
classFns = { getMvClass }
},
{
tag = 'argtd',
content = '2d mv',
fn = DisplayFns.checkAndX,
classFns = { getMvClass }
},
{
tag = 'argtd',
content = 'original mv',
fn = DisplayFns.checkAndX,
classFns = { getMvClass }
},
},
{ defaultCss = { ['text-align'] = 'center' } }
)
:addHeader({ tag = 'th', content = 'Difficulties' }, { subheader = true })
:addRow(
difficultiesRow(),
{
defaultCss = {
['text-align'] = 'center',
['border-bottom-style'] = 'solid'
}
}
)
:addRow(
{
{ tag = 'argtd', content = 'easy difficulty' },
{ tag = 'argtd', content = 'normal difficulty' },
{ tag = 'argtd', content = 'hard difficulty' },
{ tag = 'argtd', content = 'expert difficulty' },
{ tag = 'argtd', content = 'master difficulty' }
},
{ defaultCss = { ['text-align'] = 'center' } }
)
:addHeader({ tag = 'th', content = 'Notes' }, { subheader = true })
:addRow(
difficultiesRow(),
{
defaultCss = {
['text-align'] = 'center',
['border-bottom-style'] = 'solid'
}
}
)
:addRow(
{
{ tag = 'argtd', content = 'easy notes' },
{ tag = 'argtd', content = 'normal notes' },
{ tag = 'argtd', content = 'hard notes' },
{ tag = 'argtd', content = 'expert notes' },
{ tag = 'argtd', content = 'master notes' }
},
{ defaultCss = { ['text-align'] = 'center' } }
)
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Songs]]" .. infobox:getCategories()
local rawArgs = infobox:getRawArgs()
VariablesLua.vardefine( 'song id', rawArgs['song id'] )
end
return infobox:tostring() .. categories
end
return p