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: Difference between revisions

From Piñata Journal
No edit summary
No edit summary
Line 2: Line 2:


local function notEmpty(val)
local function notEmpty(val)
    return val and mw.text.trim(val) ~= ""
return val and val ~= ""
end
end


local function renderImage(label, file)
local function gameRow(label, class, content)
    if not notEmpty(file) then return "" end
if not notEmpty(content) then
 
return ""
    local fileLink = '[[File:' .. file .. '|200px]]'
end
 
    return '<div class="vp-variant-image">' ..
return string.format(
          '<div class="vp-variant-image-label">' .. label .. '</div>' ..
'<div class="vpvg-req %s"><span class="vpvg-game">%s:</span> %s</div>',
          fileLink ..
class,
          '</div>'
label,
end
content
 
)
local function renderGameRequirement(frame, game, content)
    if not notEmpty(content) then return "" end
 
    return frame:expandTemplate{
        title = "RequirementBox",
        args = {
            game = game,
            evolve = content,
            evolve_first = "true"
        }
    }
end
 
local function renderVariant(frame, args)
    local name = args.name or "Unnamed Variant"
 
    local html = '<div class="vp-variant-block">'
    html = html .. '<h3 class="vp-variant-title">' .. name .. '</h3>'
 
    -- Images
    html = html .. '<div class="vp-variant-images">'
    html = html .. renderImage("Console (VP1/TIP)", args.img_console)
    html = html .. renderImage("Pocket Paradise", args.img_pp)
    html = html .. renderImage("Pinarctic (TIP)", args.img_pinarctic)
    html = html .. renderImage("Dessert Desert (TIP)", args.img_dessert)
    html = html .. '</div>'
 
    -- Requirements
    html = html .. '<div class="vp-variant-requirements">'
    html = html .. renderGameRequirement(frame, "vp1", args.vp1)
    html = html .. renderGameRequirement(frame, "tip", args.tip)
    html = html .. renderGameRequirement(frame, "pp", args.pp)
    html = html .. '</div>'
 
    html = html .. '</div>'
 
    return html
end
end


function p.render(frame)
local function renderVariant(args, index)
    local args = frame:getParent().args
local title = args["variant" .. index .. "_title"]
    local output = '<div class="vp-variants-container">'
if not notEmpty(title) then
 
return ""
    local i = 1
end
    while args["variant" .. i] do
        local variantFrame = frame:newChild{
local image = args["variant" .. index .. "_image"] or ""
            title = "PinataVariant",
local vp1 = args["variant" .. index .. "_vp1"]
            args = {}
local tip = args["variant" .. index .. "_tip"]
        }
local pp  = args["variant" .. index .. "_pp"]
 
        -- Parse subtemplate manually
local html = {}
        local variantArgs = frame:preprocess(args["variant" .. i])
        output = output .. variantArgs
table.insert(html, '<div class="vpvg-col">')
 
table.insert(html, '<div class="vpvg-title">' .. title .. '</div>')
        i = i + 1
    end
if notEmpty(image) then
 
table.insert(html,
    output = output .. '</div>'
'<div class="vpvg-image">[[File:' .. image .. '|160px]]</div>'
    return output
)
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
end


 
function p.main(frame)
function p.renderVariant(frame)
local args = frame:getParent().args
    return renderVariant(frame, frame.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
end


return p
return p

Revision as of 11:03, 4 March 2026

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