Jump to content

Module:RequirementBox: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 4: Line 4:
     if list == "" then return "" end
     if list == "" then return "" end


     -- Split list into individual <li> blocks
    local blocks = {}
    local items = {}
    local current = nil
     for li in list:gmatch("<li>(.-)</li>") do
 
         table.insert(items, li)
     -- 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
     end


     local out = ""
     local out = ""


     for _, item in ipairs(items) do
     for _, block in ipairs(blocks) do
         if item:find("||OR||") then
         if block:find("%-%-%-OR%-%-%-") then
            -- OR requirement
             local parts = mw.text.split(block, "%-%-%-OR%-%-%-")
             local parts = mw.text.split(item, "%s*||OR||%s*")
             out = out .. '<li class="vp-requirement-or">'
             out = out .. '<li class="vp-requirement-or">'
             for i, part in ipairs(parts) do
             for i, part in ipairs(parts) do
                 out = out .. '<div class="vp-requirement-or-option">' .. part .. '</div>'
                 out = out .. '<div class="vp-requirement-or-option">' ..
                    mw.text.trim(part) .. '</div>'
                 if i < #parts then
                 if i < #parts then
                     out = out .. '<div class="vp-requirement-or-divider">OR</div>'
                     out = out .. '<div class="vp-requirement-or-divider">OR</div>'
Line 25: Line 42:
             out = out .. '</li>'
             out = out .. '</li>'
         else
         else
            -- Normal requirement
             out = out .. '<li>' .. block .. '</li>'
             out = out .. '<li>' .. item .. '</li>'
         end
         end
     end
     end
    if out == "" then return "" end


     return string.format([[
     return string.format([[
Line 38: Line 56:
</div>]], title, out)
</div>]], title, out)
end
end




function p.render(frame)
function p.render(frame)
     local args = frame.args
     local args = frame.args
     local title    = args.title or "Game"
     local title    = "Invalid Game"
     local game    = args.game or ""
     local game    = args.game or ""
    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 state    = args.state or ""
    local evolve_first = args.evolve_first or ""


     -- preprocess each category to allow raw wikitext
     -- preprocess each category to allow raw wikitext
Line 55: Line 85:
     local evolve = frame:preprocess(args.evolve or "")
     local evolve = frame:preprocess(args.evolve or "")
     local bait = frame:preprocess(args.bait or "")
     local bait = frame:preprocess(args.bait or "")
    local mature = frame:preprocess(args.mature or "")


     -- build requirements HTML
     -- build requirements HTML
     local html = renderCategory("Appear", appear)
     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("Visit", visit)
     html = html .. renderCategory("Resident", resident)
     html = html .. renderCategory("Resident", resident)
    if evolve_first ~= "true" then
        html = html .. renderCategory("Evolve", evolve)
    end
     html = html .. renderCategory("Romance", romance)
     html = html .. renderCategory("Romance", romance)
     html = html .. renderCategory("Tricks", tricks)
     html = html .. renderCategory("Tricks", tricks)
     html = html .. renderCategory("Unblock", unblock)
     html = html .. renderCategory("Growth", mature)
    html = html .. renderCategory("Evolve", evolve)
    html = html .. renderCategory("Bait", bait)