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
m (separate out types of 2d mv)
Line 14: Line 14:
['master preview'] = 'Master Preview',
['master preview'] = 'Master Preview',
['original mv'] = 'Original MV',
['original mv'] = 'Original MV',
['2d mv'] = '2D MV',
['short 2d mv'] = '2D MV (short ver.)',
['full 2d mv'] = '2D MV (full ver.)',
['3d mv'] = '3D MV'
['3d mv'] = '3D MV'
}
}

Revision as of 05:06, 30 October 2021

Documentation for this module may be created at Module:Song video/doc

local getArgs   = require('Module:Arguments').getArgs
local utils     = require('Module:Utilities')

local p = {}

local color = '#00cdba'

local function makeHeader(video_type)
	local headers = {
		['easy preview'] = 'Easy Preview',
		['normal preview'] = 'Normal Preview',
		['hard preview'] = 'Hard Preview',
		['expert preview'] = 'Expert Preview',
		['master preview'] = 'Master Preview',
		['original mv'] = 'Original MV',
		['short 2d mv'] = '2D MV (short ver.)',
		['full 2d mv'] = '2D MV (full ver.)',
		['3d mv'] = '3D MV'
	}
	
	local header = mw.html.create('div')
		:css({
			['border-radius'] = '6px',
			['background-color'] = color,
			['font-weight'] = 'bold',
			['text-align'] = 'center',
			['margin-bottom'] = '5px',
			['padding'] = '5px'
		})
		:wikitext(utils.editIfNil(
			video_type,
			function()
				return utils.editIfNil(headers[video_type:lower()])
			end
		))
		:done()
		
	return header
end

local function makeVideo(frame, link)
	local video = mw.html.create('div')
		:css({
			['flex'] = '1 1 320px',
			['text-align'] = 'center',
			['min-width'] = '320px',
			['height'] = '180px'
		})
	
	if link then
		local is_yt = string.find(link, '^' .. ('[a-zA-Z0-9_-]'):rep(11) .. '$') ~= nil
		local is_file = string.find(link, '.+\.mp4') ~= nil
		
		if is_yt then
			video:wikitext(frame:extensionTag{ 
				name = 'youtube',
				args = { width = "320", height= "180" },
				content = link
			})
		elseif is_file then
			video:wikitext('[[File:' .. link .. '|320px]]')
		else
			video:wikitext(utils.editIfNil(nil))
		end
	else
		video:wikitext(utils.editIfNil(nil))
	end
	
	return video
end

local function makeInfo(release_date, illustrator, animator)
	local infoHeaderCss = {
		['border-radius'] = '6px',
		['background-color'] = color,
		['padding'] = '5px 10px'
	}
	local infoCellCss = {
		['padding'] = '5px'
	}
	
	local info = mw.html.create('div')
		:css({
			['display'] = 'grid',
			['grid-template-columns'] = '1fr 1fr',
			['grid-auto-rows'] = 'min-content',
			['gap'] = '5px'
		})

	info:tag('div')
			:css(infoHeaderCss)
			:wikitext('Release Date')
			:done()
		:tag('div')
			:css(infoCellCss)
			:wikitext(utils.editIfNil(release_date))
			:done()
	
	if illustrator and illustrator ~= '' then
		info:tag('div')
				:css(infoHeaderCss)
				:wikitext('Illustrator')
				:done()
			:tag('div')
				:css(infoCellCss)
				:wikitext(illustrator)
				:done()
	end
	
	if animator and animator ~= '' then
		info:tag('div')
				:css(infoHeaderCss)
				:wikitext('Movie')
				:done()
			:tag('div')
				:css(infoCellCss)
				:wikitext('Lye')
				:done()
	end
			
	return info
end

function p.main(frame)
	local args = getArgs(frame)
	
	local video_type = args['type']
	local link = args['link']
	local release_date = args['date']
	local illustrator = args['illustrator']
	local animator = args['animator']
	
	local root = mw.html.create('div')
		:css({
			['display'] = 'inline-grid',
			['margin-right'] = '10px',
			['margin-bottom'] = '10px'
		})
	
	local header = makeHeader(video_type)
	root:node(header)
	
	local body = root:tag('div')
		:css({
			['display'] = 'flex',
			['flex-wrap'] = 'wrap',
			['gap'] = '5px'
		})
		:node(makeVideo(frame, link))
		:node(makeInfo(release_date, illustrator, animator))
	
	return tostring(root)
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.