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

Module:VariantGrid

From Piñata Journal
Revision as of 11:03, 4 March 2026 by Admin Jeremy (talk | contribs)

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

local p = {}

local function notEmpty(val)
	return val and val ~= ""
end

local function gameRow(label, class, content)
	if not notEmpty(content) then
		return ""
	end
	
	return string.format(
		'<div class="vpvg-req %s"><span class="vpvg-game">%s:</span> %s</div>',
		class,
		label,
		content
	)
end

local function renderVariant(args, index)
	local title = args["variant" .. index .. "_title"]
	if not notEmpty(title) then
		return ""
	end
	
	local image = args["variant" .. index .. "_image"] or ""
	local vp1 = args["variant" .. index .. "_vp1"]
	local tip = args["variant" .. index .. "_tip"]
	local pp  = args["variant" .. index .. "_pp"]
	
	local html = {}
	
	table.insert(html, '<div class="vpvg-col">')
	table.insert(html, '<div class="vpvg-title">' .. title .. '</div>')
	
	if notEmpty(image) then
		table.insert(html,
			'<div class="vpvg-image">[[File:' .. image .. '|160px]]</div>'
		)
	end
	
	table.insert(html, gameRow("VP1", "vp1", vp1))
	table.insert(html, gameRow("TIP", "tip", tip))
	table.insert(html, gameRow("PP",  "pp",  pp))
	
	table.insert(html, '</div>')
	
	return table.concat(html)
end

function p.main(frame)
	local args = frame:getParent().args
	
	local output = {}
	
	table.insert(output, '<div class="vpvg-grid">')
	
	-- Support up to 4 variants
	for i = 1, 4 do
		table.insert(output, renderVariant(args, i))
	end
	
	table.insert(output, '</div>')
	
	return table.concat(output)
end

return p