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

Module:RequirementBox: Difference between revisions

From Piñata Journal
Created page with "local p = {} function p.render(frame) local title = frame.args.title or "Game" local game = frame.args.game or "" local state = frame.args.state or "" -- Grab content for each category local appear = frame.args.appear or "" local visit = frame.args.visit or "" local resident = frame.args.resident or "" local romance = frame.args.romance or "" local tricks = frame.args.tricks or "" -- Helper to render a category..."
 
No edit summary
 
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


function p.render(frame)
local function renderCategory(title, list)
     local title = frame.args.title or "Game"
    if list == "" then return "" end
    local game  = frame.args.game or ""
 
     local state = frame.args.state or ""
    local blocks = {}
   
     local current = nil
     -- Grab content for each category
 
    local appear  = frame.args.appear or ""
    -- Split into lines and group into bullet blocks
    local visit    = frame.args.visit or ""
    for line in list:gmatch("[^\r\n]+") do
    local resident = frame.args.resident or ""
        line = mw.text.trim(line)
    local romance  = frame.args.romance or ""
 
    local tricks  = frame.args.tricks or ""
        if line:sub(1,1) == "*" then
   
            -- start new requirement block
    -- Helper to render a category
            if current then
     local function renderCategory(title, list)
                table.insert(blocks, current)
         if list == "" then return "" end
            end
        return string.format([[
            current = mw.text.trim(line:sub(2))
        elseif current then
            -- continuation of previous requirement
            current = current .. "\n" .. line
        end
    end
 
    if current then
        table.insert(blocks, current)
    end
 
     local out = ""
for _, block in ipairs(blocks) do
     if block:find("%-%-%-AND%-%-%-") then
        local parts = mw.text.split(block, "%-%-%-AND%-%-%-")
        out = out .. '<li class="vp-requirement-and-or">'
        for i, part in ipairs(parts) do
            out = out .. '<div class="vp-requirement-and-or-option">' ..
                mw.text.trim(part) .. '</div>'
            if i < #parts then
                out = out .. '<div class="vp-requirement-and-or-divider">AND</div>'
            end
        end
        out = out .. '</li>'
 
    elseif block:find("%-%-%-OR%-%-%-") then
        local parts = mw.text.split(block, "%-%-%-OR%-%-%-")
        out = out .. '<li class="vp-requirement-and-or">'
        for i, part in ipairs(parts) do
            out = out .. '<div class="vp-requirement-and-or-option">' ..
                mw.text.trim(part) .. '</div>'
            if i < #parts then
                out = out .. '<div class="vp-requirement-and-or-divider">OR</div>'
            end
        end
        out = out .. '</li>'
 
     else
         out = out .. '<li>' .. block .. '</li>'
    end
end
 
    if out == "" then return "" end
 
    return string.format([[
<div class="vp-requirements-category">
<div class="vp-requirements-category">
   <div class="requirements-header">%s</div>
   <div class="requirements-header">%s</div>
   <ul class="vp-requirements-list">
   <ul class="vp-requirements-list">
    %s
%s
   </ul>
   </ul>
</div>
</div>]], title, out)
]], title, list)
end
 
 
 
function p.render(frame)
    local args = frame.args
    local title    = "Invalid Game"
    local game    = args.game or ""
    local isAllGames = (game == "all")
    if game == "vp1" then
        title = "Viva Piñata"
    elseif game == "tip" or game == "vp2" then
        title = "Viva Piñata: Trouble in Paradise"
    elseif game == "pp" then
        title = "Viva Piñata: Pocket Paradise"   
    elseif game == "all" then
        title = "All games"   
     end
     end
      
 
     -- Build the requirements HTML
     local state    = args.state or ""
     local requirementsHTML = '<div class="vp-requirements">\n'
    local evolve_first = args.evolve_first or ""
     requirementsHTML = requirementsHTML .. renderCategory("Appear", appear)
 
     requirementsHTML = requirementsHTML .. renderCategory("Visit", visit)
     -- preprocess each category to allow raw wikitext
     requirementsHTML = requirementsHTML .. renderCategory("Resident", resident)
    local appear  = frame:preprocess(args.appear or "")
     requirementsHTML = requirementsHTML .. renderCategory("Romance", romance)
    local visit    = frame:preprocess(args.visit or "")
     requirementsHTML = requirementsHTML .. renderCategory("Tricks", tricks)
    local resident = frame:preprocess(args.resident or "")
     requirementsHTML = requirementsHTML .. '\n</div>'
    local romance  = frame:preprocess(args.romance or "")
   
    local tricks  = frame:preprocess(args.tricks or "")
     -- Build the top-level <details>
    local unblock = frame:preprocess(args.unblock or "")
    local evolve = frame:preprocess(args.evolve or "")
    local bait = frame:preprocess(args.bait or "")
    local mature = frame:preprocess(args.mature or "")
    local catalyst = frame:preprocess(args.catalyst or "")
    local surface  = frame:preprocess(args.surface or "")
 
 
    -- build requirements HTML
     local html = ""
    if evolve_first == "true" then
        html = html .. renderCategory("Evolve", evolve)
    end
     html = html .. renderCategory("Appear", appear)
     html = html .. renderCategory("Unblock", unblock)
    html = html .. renderCategory("Bait", bait)
    html = html .. renderCategory("Visit", visit)
     html = html .. renderCategory("Resident", resident)
     if evolve_first ~= "true" then
        html = html .. renderCategory("Evolve", evolve)
    end
    html = html .. renderCategory("Romance", romance)
     html = html .. renderCategory("Tricks", tricks)
     html = html .. renderCategory("Growth", mature)
    html = html .. renderCategory("Surface", surface)
    html = html .. renderCategory("Catalyst", catalyst)
 
 
local box
 
if isAllGames then
    -- STATIC (non-collapsible) version
    box = string.format([[
<div class="vp-gamebox vp-gamebox-static" data-game="%s">
  <div class="vp-gamebox-header">%s</div>
  <div class="vp-gamebox-content">
%s
  </div>
</div>]], game, title, html)
 
else
     -- COLLAPSIBLE version
     local openAttr = ""
     local openAttr = ""
     if state ~= "mw-collapsed" and state ~= "" then
     if state ~= "mw-collapsed" then
         openAttr = ' open="open"'
         openAttr = ' open="open"'
    elseif state == "" then
        openAttr = ' open="open"'  -- default open
     end
     end
   
 
     local html = string.format([[
     box = string.format([[
<details class="vp-gamebox"%s>
<details class="vp-gamebox"%s data-game="%s">
   <summary class="vp-gamebox-header">%s</summary>
   <summary class="vp-gamebox-header">%s</summary>
   <div class="vp-gamebox-content">
   <div class="vp-gamebox-content">
    %s
%s
   </div>
   </div>
</details>
</details>]], openAttr, game, title, html)
]], openAttr, title, requirementsHTML)
end
   
 
    return html
return frame:preprocess(box)
end
end


return p
return p

Latest revision as of 12:43, 26 February 2026

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

local p = {}

local function renderCategory(title, list)
    if list == "" then return "" end

    local blocks = {}
    local current = nil

    -- Split into lines and group into bullet blocks
    for line in list:gmatch("[^\r\n]+") do
        line = mw.text.trim(line)

        if line:sub(1,1) == "*" then
            -- start new requirement block
            if current then
                table.insert(blocks, current)
            end
            current = mw.text.trim(line:sub(2))
        elseif current then
            -- continuation of previous requirement
            current = current .. "\n" .. line
        end
    end

    if current then
        table.insert(blocks, current)
    end

    local out = ""
for _, block in ipairs(blocks) do
    if block:find("%-%-%-AND%-%-%-") then
        local parts = mw.text.split(block, "%-%-%-AND%-%-%-")
        out = out .. '<li class="vp-requirement-and-or">'
        for i, part in ipairs(parts) do
            out = out .. '<div class="vp-requirement-and-or-option">' ..
                mw.text.trim(part) .. '</div>'
            if i < #parts then
                out = out .. '<div class="vp-requirement-and-or-divider">AND</div>'
            end
        end
        out = out .. '</li>'

    elseif block:find("%-%-%-OR%-%-%-") then
        local parts = mw.text.split(block, "%-%-%-OR%-%-%-")
        out = out .. '<li class="vp-requirement-and-or">'
        for i, part in ipairs(parts) do
            out = out .. '<div class="vp-requirement-and-or-option">' ..
                mw.text.trim(part) .. '</div>'
            if i < #parts then
                out = out .. '<div class="vp-requirement-and-or-divider">OR</div>'
            end
        end
        out = out .. '</li>'

    else
        out = out .. '<li>' .. block .. '</li>'
    end
end

    if out == "" then return "" end

    return string.format([[
<div class="vp-requirements-category">
  <div class="requirements-header">%s</div>
  <ul class="vp-requirements-list">
%s
  </ul>
</div>]], title, out)
end



function p.render(frame)
    local args = frame.args
    local title    = "Invalid Game"
    local game     = args.game or ""
    local isAllGames = (game == "all")
    if game == "vp1" then
        title = "Viva Piñata"
    elseif game == "tip" or game == "vp2" then
        title = "Viva Piñata: Trouble in Paradise"
    elseif game == "pp" then
        title = "Viva Piñata: Pocket Paradise"    
    elseif game == "all" then
        title = "All games"    
    end

    local state    = args.state or ""
    local evolve_first = args.evolve_first or ""

    -- preprocess each category to allow raw wikitext
    local appear   = frame:preprocess(args.appear or "")
    local visit    = frame:preprocess(args.visit or "")
    local resident = frame:preprocess(args.resident or "")
    local romance  = frame:preprocess(args.romance or "")
    local tricks   = frame:preprocess(args.tricks or "")
    local unblock = frame:preprocess(args.unblock or "")
    local evolve = frame:preprocess(args.evolve or "")
    local bait = frame:preprocess(args.bait or "")
    local mature = frame:preprocess(args.mature or "")
    local catalyst = frame:preprocess(args.catalyst or "")
    local surface  = frame:preprocess(args.surface or "")


    -- build requirements HTML
    local html = ""
    if evolve_first == "true" then
        html = html .. renderCategory("Evolve", evolve)
    end
    html = html .. renderCategory("Appear", appear)
    html = html .. renderCategory("Unblock", unblock)
    html = html .. renderCategory("Bait", bait)
    html = html .. renderCategory("Visit", visit)
    html = html .. renderCategory("Resident", resident)
    if evolve_first ~= "true" then
        html = html .. renderCategory("Evolve", evolve)
    end
    html = html .. renderCategory("Romance", romance)
    html = html .. renderCategory("Tricks", tricks)
    html = html .. renderCategory("Growth", mature)
    html = html .. renderCategory("Surface", surface)
    html = html .. renderCategory("Catalyst", catalyst)


local box

if isAllGames then
    -- STATIC (non-collapsible) version
    box = string.format([[
<div class="vp-gamebox vp-gamebox-static" data-game="%s">
  <div class="vp-gamebox-header">%s</div>
  <div class="vp-gamebox-content">
%s
  </div>
</div>]], game, title, html)

else
    -- COLLAPSIBLE version
    local openAttr = ""
    if state ~= "mw-collapsed" then
        openAttr = ' open="open"'
    end

    box = string.format([[
<details class="vp-gamebox"%s data-game="%s">
  <summary class="vp-gamebox-header">%s</summary>
  <div class="vp-gamebox-content">
%s
  </div>
</details>]], openAttr, game, title, html)
end

return frame:preprocess(box)
end

return p