Module:Sandbox/ChaoticShadow/SongDataLine: Difference between revisions

From TestWiki
Content added Content deleted
No edit summary
No edit summary
Line 44: Line 44:
addCell(args.duration, '', {})
addCell(args.duration, '', {})
local diffs = mw.text.split(args.difficulties, ',')
local diffs = mw.text.split(args.difficulties or '', ',')
for i=1,5,1 do
for i=1,5,1 do
addCell(diffs[i], '', {})
addCell(diffs[i], '', {})
end
end
local notes = mw.text.split(args.notes, ',')
local notes = mw.text.split(args.notes or '', ',')
for i=1,5,1 do
for i=1,5,1 do
addCell(notes[i], '', {})
addCell(notes[i], '', {})

Revision as of 21:36, 14 May 2021

Documentation for this module may be created at Module:Sandbox/ChaoticShadow/SongDataLine/doc

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

local p = {}
local args = {}

local root

local colors = {
	vs       = { bg = '#00CDBA', text = '#FFFFFF' },
	ln       = { bg = '#4455DD', text = '#FFFFFF' },
	mmj      = { bg = '#6CCB20', text = '#FFFFFF' },
	vbs      = { bg = '#EE1166', text = '#FFFFFF' },
	wxs      = { bg = '#FF9900', text = '#FFFFFF' },
	['25ji'] = { bg = '#884499', text = '#FFFFFF' },
	mix      = { bg = '#81ebee', text = '#000000' }
}
local palette = { bg = '#FFFFFF', text = '#000000' }

local function addCell(value, default, css)
	local content = value or default
	
	root:tag('td')
		:css(css)
		:wikitext(content)
end

function p.main(frame)
	args = getArgs(frame)
	
	if args.unit and colors[args.unit] then
		palette = colors[args.unit]
	end
	
	root = mw.html.create('tr')
	
	addCell(args.id, '-1', {})
	addCell(args.song, '', {})
	addCell(args.producer, '', {})
	addCell(args.unit, '', {
		['background-color']= palette.bg,
		['color']= palette.text
	})
	addCell(args.mv, '✕', {})
	addCell(args.duration, '', {})
	
	local diffs = mw.text.split(args.difficulties or '', ',')
	for i=1,5,1 do
		addCell(diffs[i], '', {})
	end
	
	local notes = mw.text.split(args.notes or '', ',')
	for i=1,5,1 do
		addCell(notes[i], '', {})
	end
	
	return tostring(root)
end

return p