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
Created page with "local p = {} local function notEmpty(val) return val and mw.text.trim(val) ~= "" end local function renderImage(label, file) if not notEmpty(file) then return "" end local fileLink = '200px' return '<div class="vp-variant-image">' .. '<div class="vp-variant-image-label">' .. label .. '</div>' .. fileLink .. '</div>' end local function renderGameRequirement(frame, game, content) if not notEm..."
 
No edit summary
 
(8 intermediate revisions by the same user not shown)
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 renderItem(token)
    if not notEmpty(file) then return "" end
token = mw.text.trim(token)


    local fileLink = '[[File:' .. file .. '|200px]]'
local name, qty = token:match("^(.-)%s*x(%d+)$")
if not name then
name = token
end


    return '<div class="vp-variant-image">' ..
local icon = string.format(
          '<div class="vp-variant-image-label">' .. label .. '</div>' ..
'<span class="vpvg-icon">[[File:%s icon.png|28px|link=%s]]</span>',
          fileLink ..
name,
          '</div>'
name
)
 
local text = string.format('[[%s]]', name)
 
local result = icon .. '<span class="vpvg-mini-box">' .. text
 
if qty then
result = result .. ' ×' .. qty
end
 
result = result .. '</span>'
 
return result
end
 
 
local function renderRequirement(content)
if not notEmpty(content) then
return ""
end
 
local parts = mw.text.split(content, "%+")
local rendered = {}
 
for _, part in ipairs(parts) do
table.insert(rendered, renderItem(part))
end
 
return table.concat(rendered, '<span class="vpvg-plus">+</span>')
end
end


local function renderGameRequirement(frame, game, content)
local function requirementRow(label, class, content)
    if not notEmpty(content) then return "" end
if not notEmpty(content) then
return ""
end


    return frame:expandTemplate{
return string.format(
        title = "RequirementBox",
'<tr class="vpvg-row %s">' ..
        args = {
'<td class="vpvg-gamecell">%s</td>' ..
            game = game,
'<td class="vpvg-reqcell">%s</td>' ..
            evolve = content,
'</tr>',
            evolve_first = "true"
class,
        }
label,
    }
renderRequirement(content)
)
end
end


local function renderVariant(frame, args)
local function renderVariant(args, index)
    local name = args.name or "Unnamed Variant"
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>')


    local html = '<div class="vp-variant-block">'
if notEmpty(image) then
    html = html .. '<h3 class="vp-variant-title">' .. name .. '</h3>'
table.insert(html,
'<div class="vpvg-image">[[File:' .. image .. '|160px]]</div>'
)
end


    -- Images
table.insert(html, '<table class="vpvg-reqtable">')
    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
table.insert(html, requirementRow("VP1", "vp1", vp1))
    html = html .. '<div class="vp-variant-requirements">'
table.insert(html, requirementRow("TIP", "tip", tip))
    html = html .. renderGameRequirement(frame, "vp1", args.vp1)
table.insert(html, requirementRow("PP", "pp", pp))
    html = html .. renderGameRequirement(frame, "tip", args.tip)
    html = html .. renderGameRequirement(frame, "pp", args.pp)
    html = html .. '</div>'


    html = html .. '</div>'
table.insert(html, '</table>')
table.insert(html, '</div>')


    return html
return table.concat(html)
end
end


function p.render(frame)
function p.main(frame)
    local args = frame:getParent().args
local args = frame:getParent().args
    local output = '<div class="vp-variants-container">'
local output = {}


    local i = 1
table.insert(output, '<div class="vpvg-grid">')
    while args["variant" .. i] do
        local variantFrame = frame:newChild{
            title = "PinataVariant",
            args = {}
        }


        -- Parse subtemplate manually
for i = 1, 4 do
        local variantArgs = frame:preprocess(args["variant" .. i])
table.insert(output, renderVariant(args, i))
        output = output .. variantArgs
end


        i = i + 1
table.insert(output, '</div>')
    end


    output = output .. '</div>'
return table.concat(output)
    return output
end
end


return p
return p

Latest revision as of 13:34, 5 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 renderItem(token)
	token = mw.text.trim(token)

	local name, qty = token:match("^(.-)%s*x(%d+)$")
	if not name then
		name = token
	end

	local icon = string.format(
		'<span class="vpvg-icon">[[File:%s icon.png|28px|link=%s]]</span>',
		name,
		name
	)

	local text = string.format('[[%s]]', name)

	local result = icon .. '<span class="vpvg-mini-box">' .. text

	if qty then
		result = result .. ' ×' .. qty
	end

	result = result .. '</span>'

	return result
end


local function renderRequirement(content)
	if not notEmpty(content) then
		return ""
	end

	local parts = mw.text.split(content, "%+")
	local rendered = {}

	for _, part in ipairs(parts) do
		table.insert(rendered, renderItem(part))
	end

	return table.concat(rendered, '<span class="vpvg-plus">+</span>')
end

local function requirementRow(label, class, content)
	if not notEmpty(content) then
		return ""
	end

	return string.format(
		'<tr class="vpvg-row %s">' ..
			'<td class="vpvg-gamecell">%s</td>' ..
			'<td class="vpvg-reqcell">%s</td>' ..
		'</tr>',
		class,
		label,
		renderRequirement(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, '<table class="vpvg-reqtable">')

	table.insert(html, requirementRow("VP1", "vp1", vp1))
	table.insert(html, requirementRow("TIP", "tip", tip))
	table.insert(html, requirementRow("PP",  "pp",  pp))

	table.insert(html, '</table>')
	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">')

	for i = 1, 4 do
		table.insert(output, renderVariant(args, i))
	end

	table.insert(output, '</div>')

	return table.concat(output)
end

return p