Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Song video: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
No edit summary
 
(11 intermediate revisions by 2 users not shown)
Line 12: Line 12:
['expert preview'] = constants.get_difficulty_color('expert'),
['expert preview'] = constants.get_difficulty_color('expert'),
['master preview'] = constants.get_difficulty_color('master'),
['master preview'] = constants.get_difficulty_color('master'),
['append preview'] = nil,
['original mv'] = '#66dd11',
['original mv'] = '#66dd11',
['game 2d mv'] = '#66dd11',
['game 2d mv'] = '#66dd11',
['full 2d mv'] = nil,
['full 2d mv'] = nil,
['3d mv'] = '#66dd11'
['3d mv'] = '#66dd11',
['april fools\' mv'] = nil
}
}


local function makeHeader(video_type)
local function makeHeader(videoType)
local headers = {
local headers = {
['easy preview'] = 'Easy Preview',
['easy preview'] = 'Easy Preview',
Line 25: Line 27:
['expert preview'] = 'Expert Preview',
['expert preview'] = 'Expert Preview',
['master preview'] = 'Master Preview',
['master preview'] = 'Master Preview',
['append preview'] = 'Append Preview',
['original mv'] = 'Original MV',
['original mv'] = 'Original MV',
['game 2d mv'] = '2D MV (game version)',
['game 2d mv'] = '2D MV (game version)',
['full 2d mv'] = '2D MV (full version)',
['full 2d mv'] = '2D MV (full version)',
['3d mv'] = '3D MV'
['3d mv'] = '3D MV',
['april fools\' mv'] = 'April Fools\' MV'
}
}
Line 37: Line 41:
})
})
:wikitext(utils.editIfNil(
:wikitext(utils.editIfNil(
video_type,
videoType,
function()
function()
return utils.editIfNil(headers[video_type:lower()])
return utils.editIfNil(headers[videoType:lower()])
end
end
))
))
Line 45: Line 49:
return header
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
end


Line 52: Line 103:
if link then
if link then
local is_yt = string.find(link, '^' .. ('[a-zA-Z0-9_-]'):rep(11) .. '$') ~= nil
local isYt = string.find(link, '^' .. ('[a-zA-Z0-9_-]'):rep(11) .. '$') ~= nil
local is_file = string.find(link, '.+\.mp4') ~= nil
local isFile = string.find(link, '.+\.mp4') ~= nil
if is_yt then
if isYt then
video:wikitext(frame:extensionTag{
video:wikitext(frame:extensionTag{
name = 'youtube',
name = 'youtube',
Line 61: Line 112:
content = link
content = link
})
})
elseif is_file then
elseif isFile then
video:wikitext('[[File:' .. link .. '|320px]]')
video:wikitext('[[File:' .. link .. '|320px]]')
else
else
Line 73: Line 124:
end
end


local function makeInfo(release_date, illustration, animation, video)
local infoHeaderCss = {
['background-color'] = color
}
local info = mw.html.create('div')
:addClass('info')

info:tag('div')
:css(infoHeaderCss)
:addClass('ih')
:wikitext('Release date')
:done()
:tag('div')
:addClass('id')
:wikitext(utils.editIfNil(release_date))
:done()
if illustration and illustration ~= '' then
info:tag('div')
:css(infoHeaderCss)
:addClass('ih')
:wikitext('Illustration')
:done()
:tag('div')
:addClass('id')
:wikitext(illustration)
:done()
end
if animation and animation ~= '' then
info:tag('div')
:css(infoHeaderCss)
:addClass('ih')
:wikitext('Animation')
:done()
:tag('div')
:addClass('id')
:wikitext(animation)
:done()
end
if video and video ~= '' then
info:tag('div')
:css(infoHeaderCss)
:addClass('ih')
:wikitext('Video')
:done()
:tag('div')
:addClass('id')
:wikitext(video)
:done()
end
return info
end


function p.main(frame)
function p.main(frame)
Line 135: Line 130:
local video_type = args['type']
local video_type = args['type']
local link = args['link']
local link = args['link']
local release_date = args['date']
local releaseDate = args['date']
local illustration = args['illustration']
local illustration = args['illustration'] or args['illustrator']
local animation = args['animation']
local animation = args['animation'] or args['animator']
local video = args['video']
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')
Line 148: Line 145:
root:node(header)
root:node(header)
root:node(makeVideo(frame, link))
local body = root:tag('div')
root:node(makeInformationSection(
:addClass('content')
releaseDate,
:node(makeVideo(frame, link))
:node(makeInfo(release_date, illustration, animation, video))
illustration,
animation,
video,
director,
bgArtist
))
return mw.getCurrentFrame():extensionTag{
return mw.getCurrentFrame():extensionTag{

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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.