Content added Content deleted
mNo edit summary |
MathTurtle (talk | contribs) No edit summary |
||
(40 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local utils = require('Module:Utilities') |
local utils = require('Module:Utilities') |
||
local constants = require('Module:Constants') |
|||
local p = {} |
local p = {} |
||
local color = nil |
|||
local function makeVideo(frame, type, link) |
|||
local colors = { |
|||
['easy preview'] = constants.get_difficulty_color('easy'), |
|||
['normal preview'] = constants.get_difficulty_color('normal'), |
|||
['hard preview'] = constants.get_difficulty_color('hard'), |
|||
['expert preview'] = constants.get_difficulty_color('expert'), |
|||
['master preview'] = constants.get_difficulty_color('master'), |
|||
['append preview'] = nil, |
|||
['original mv'] = '#66dd11', |
|||
['game 2d mv'] = '#66dd11', |
|||
['full 2d mv'] = nil, |
|||
['3d mv'] = '#66dd11', |
|||
['april fools\' mv'] = nil |
|||
} |
|||
local function makeHeader(videoType) |
|||
local headers = { |
|||
['easy preview'] = 'Easy Preview', |
|||
['normal preview'] = 'Normal Preview', |
|||
['hard preview'] = 'Hard Preview', |
|||
['expert preview'] = 'Expert Preview', |
|||
['master preview'] = 'Master Preview', |
|||
['append preview'] = 'Append Preview', |
|||
['original mv'] = 'Original MV', |
|||
['game 2d mv'] = '2D MV (game version)', |
|||
['full 2d mv'] = '2D MV (full version)', |
|||
['3d mv'] = '3D MV', |
|||
['april fools\' mv'] = 'April Fools\' MV' |
|||
} |
|||
local header = mw.html.create('div') |
|||
:addClass('header') |
|||
:css({ |
:css({ |
||
[' |
['background-color'] = color, |
||
['text-align'] = 'center', |
|||
['min-width'] = '320px' |
|||
}) |
}) |
||
:wikitext(utils.editIfNil( |
|||
videoType, |
|||
function() |
|||
return utils.editIfNil(headers[videoType:lower()]) |
|||
end |
|||
)) |
|||
:done() |
|||
return header |
|||
end |
|||
local function makeInfoRow(header, data) |
|||
local row = mw.html.create() |
|||
local header = row:tag('div') |
|||
if type and (type == 'youtube' or type == 'file') and link then |
|||
:css({ |
|||
if type == 'file' then |
|||
['background-color'] = color |
|||
video:wikitext('[[File:' .. link .. '|320px]]') |
|||
}) |
|||
:addClass('ih') |
|||
:wikitext(header) |
|||
row:tag('div') |
|||
:addClass('id') |
|||
:wikitext(utils.editIfNil(data)) |
|||
return row |
|||
end |
|||
local function makeInformationSection(releaseDate, illustrator, animator, video, director, bgArtist) |
|||
local infoHeaderCss = { |
|||
['background-color'] = color |
|||
} |
|||
local info = mw.html.create('div') |
|||
:addClass('info') |
|||
info:node(makeInfoRow('Release date', releaseDate)) |
|||
local rows = { |
|||
{ header = 'Illustrator', data = illustrator }, |
|||
{ header = 'Animator', data = animator }, |
|||
{ header = 'Video', data = video }, |
|||
{ header = 'Director', data = director }, |
|||
{ header = 'Background artist', data = bgArtist } |
|||
} |
|||
for _, row in pairs(rows) do |
|||
local header = row.header |
|||
local data = row.data |
|||
if data and data ~= '' then |
|||
info:node(makeInfoRow(header, data)) |
|||
end |
|||
end |
|||
return info |
|||
end |
|||
local function makeVideo(frame, link) |
|||
local video = mw.html.create('div') |
|||
:addClass('video') |
|||
if link then |
|||
local isYt = string.find(link, '^' .. ('[a-zA-Z0-9_-]'):rep(11) .. '$') ~= nil |
|||
local isFile = string.find(link, '.+\.mp4') ~= nil |
|||
if isYt then |
|||
video:wikitext(frame:extensionTag{ |
video:wikitext(frame:extensionTag{ |
||
name = 'youtube', |
name = 'youtube', |
||
Line 21: | Line 112: | ||
content = link |
content = link |
||
}) |
}) |
||
elseif isFile then |
|||
video:wikitext('[[File:' .. link .. '|320px]]') |
|||
else |
|||
video:wikitext(utils.editIfNil(nil)) |
|||
end |
end |
||
else |
else |
||
Line 28: | Line 123: | ||
return video |
return video |
||
end |
end |
||
function p.main(frame) |
function p.main(frame) |
||
local args = getArgs(frame) |
local args = getArgs(frame) |
||
local video_type = args['type'] |
|||
local link = args['link'] |
|||
local releaseDate = args['date'] |
|||
local illustration = args['illustration'] or args['illustrator'] |
|||
local animation = args['animation'] or args['animator'] |
|||
local video = args['video'] |
|||
local director = args['director'] |
|||
local bgArtist = args['background artist'] |
|||
local root = mw.html.create('div') |
local root = mw.html.create('div') |
||
:addClass('song-video') |
|||
:css({ |
|||
['display'] = 'inline-grid', |
|||
['margin-right'] = '10px', |
|||
['margin-bottom'] = '10px' |
|||
}) |
|||
color = colors[video_type] or color |
|||
local header = root:tag('div') |
|||
:css({ |
|||
['border-radius'] = '6px', |
|||
['background-color'] = '#FFA900', |
|||
['font-weight'] = 'bold', |
|||
['text-align'] = 'center', |
|||
['margin-bottom'] = '5px', |
|||
['padding'] = '5px' |
|||
}) |
|||
:wikitext('Hard Preview') |
|||
:done() |
|||
local |
local header = makeHeader(video_type) |
||
root:node(header) |
|||
:css({ |
|||
['display'] = 'flex', |
|||
['flex-wrap'] = 'wrap', |
|||
['gap'] = '5px' |
|||
}) |
|||
local video = makeVideo(frame, args['type'], args['link']) |
|||
root:node(makeVideo(frame, link)) |
|||
local infoHeaderCss = { |
|||
root:node(makeInformationSection( |
|||
['border-radius'] = '6px', |
|||
releaseDate, |
|||
['background-color'] = '#a7ee75', |
|||
illustration, |
|||
['padding'] = '5px 10px' |
|||
animation, |
|||
} |
|||
video, |
|||
local infoCellCss = { |
|||
director, |
|||
['padding'] = '5px' |
|||
bgArtist |
|||
} |
|||
)) |
|||
local info = mw.html.create('div') |
|||
:css({ |
|||
['display'] = 'grid', |
|||
['grid-template-columns'] = '1fr 1fr', |
|||
['grid-auto-rows'] = 'min-content', |
|||
['gap'] = '5px' |
|||
}) |
|||
:tag('div') |
|||
:css(infoHeaderCss) |
|||
:wikitext('Release Date') |
|||
:done() |
|||
:tag('div') |
|||
:css(infoCellCss) |
|||
:wikitext('2021/08/18') |
|||
:done() |
|||
:tag('div') |
|||
:css(infoHeaderCss) |
|||
:wikitext('Illust') |
|||
:done() |
|||
:tag('div') |
|||
:css(infoCellCss) |
|||
:wikitext('Sidu') |
|||
:done() |
|||
:tag('div') |
|||
:css(infoHeaderCss) |
|||
:wikitext('Movie') |
|||
:done() |
|||
:tag('div') |
|||
:css(infoCellCss) |
|||
:wikitext('Lye') |
|||
:done() |
|||
body:node(video) |
|||
body:node(info) |
|||
return |
return mw.getCurrentFrame():extensionTag{ |
||
name = 'templatestyles', |
|||
args = { src = 'Template:Song video/styles.css' } |
|||
} .. tostring(root) |
|||
end |
end |
||
Latest revision as of 09:10, 4 October 2023
Documentation for this module may be created at Module:Song video/doc
local getArgs = require('Module:Arguments').getArgs
local utils = require('Module:Utilities')
local constants = require('Module:Constants')
local p = {}
local color = nil
local colors = {
['easy preview'] = constants.get_difficulty_color('easy'),
['normal preview'] = constants.get_difficulty_color('normal'),
['hard preview'] = constants.get_difficulty_color('hard'),
['expert preview'] = constants.get_difficulty_color('expert'),
['master preview'] = constants.get_difficulty_color('master'),
['append preview'] = nil,
['original mv'] = '#66dd11',
['game 2d mv'] = '#66dd11',
['full 2d mv'] = nil,
['3d mv'] = '#66dd11',
['april fools\' mv'] = nil
}
local function makeHeader(videoType)
local headers = {
['easy preview'] = 'Easy Preview',
['normal preview'] = 'Normal Preview',
['hard preview'] = 'Hard Preview',
['expert preview'] = 'Expert Preview',
['master preview'] = 'Master Preview',
['append preview'] = 'Append Preview',
['original mv'] = 'Original MV',
['game 2d mv'] = '2D MV (game version)',
['full 2d mv'] = '2D MV (full version)',
['3d mv'] = '3D MV',
['april fools\' mv'] = 'April Fools\' MV'
}
local header = mw.html.create('div')
:addClass('header')
:css({
['background-color'] = color,
})
:wikitext(utils.editIfNil(
videoType,
function()
return utils.editIfNil(headers[videoType:lower()])
end
))
:done()
return header
end
local function makeInfoRow(header, data)
local row = mw.html.create()
local header = row:tag('div')
:css({
['background-color'] = color
})
:addClass('ih')
:wikitext(header)
row:tag('div')
:addClass('id')
:wikitext(utils.editIfNil(data))
return row
end
local function makeInformationSection(releaseDate, illustrator, animator, video, director, bgArtist)
local infoHeaderCss = {
['background-color'] = color
}
local info = mw.html.create('div')
:addClass('info')
info:node(makeInfoRow('Release date', releaseDate))
local rows = {
{ header = 'Illustrator', data = illustrator },
{ header = 'Animator', data = animator },
{ header = 'Video', data = video },
{ header = 'Director', data = director },
{ header = 'Background artist', data = bgArtist }
}
for _, row in pairs(rows) do
local header = row.header
local data = row.data
if data and data ~= '' then
info:node(makeInfoRow(header, data))
end
end
return info
end
local function makeVideo(frame, link)
local video = mw.html.create('div')
:addClass('video')
if link then
local isYt = string.find(link, '^' .. ('[a-zA-Z0-9_-]'):rep(11) .. '$') ~= nil
local isFile = string.find(link, '.+\.mp4') ~= nil
if isYt then
video:wikitext(frame:extensionTag{
name = 'youtube',
args = { width = "320", height= "180" },
content = link
})
elseif isFile then
video:wikitext('[[File:' .. link .. '|320px]]')
else
video:wikitext(utils.editIfNil(nil))
end
else
video:wikitext(utils.editIfNil(nil))
end
return video
end
function p.main(frame)
local args = getArgs(frame)
local video_type = args['type']
local link = args['link']
local releaseDate = args['date']
local illustration = args['illustration'] or args['illustrator']
local animation = args['animation'] or args['animator']
local video = args['video']
local director = args['director']
local bgArtist = args['background artist']
local root = mw.html.create('div')
:addClass('song-video')
color = colors[video_type] or color
local header = makeHeader(video_type)
root:node(header)
root:node(makeVideo(frame, link))
root:node(makeInformationSection(
releaseDate,
illustration,
animation,
video,
director,
bgArtist
))
return mw.getCurrentFrame():extensionTag{
name = 'templatestyles',
args = { src = 'Template:Song video/styles.css' }
} .. tostring(root)
end
return p