Jump to content

Module:DigimonTab: Difference between revisions

From Untitled Monster Game
imported>Ziebster
No edit summary
imported>Ziebster
No edit summary
Line 24: Line 24:
     table.sort(unsummonable, function(a,b) return mw.text.unstripNoWiki(a.name) < mw.text.unstripNoWiki(b.name) end)
     table.sort(unsummonable, function(a,b) return mw.text.unstripNoWiki(a.name) < mw.text.unstripNoWiki(b.name) end)


     local out = (#summonable > 0 and "='''Summonable Digimon=\n{| class=\"sortable fandom-table\"\n! '''IMG !! '''Digimon\n" .. table.concat((function() local rows = {} for _, e in ipairs(summonable) do table.insert(rows, "|-\n| " .. e.image .. "\n| " .. e.name .. "\n") end return rows end)(), "") .. "|}\n" or "") ..
     local function buildGrid(entries)
                (#unsummonable > 0 and "='''Unsummonable Digimon=\n{| class=\"sortable fandom-table\"\n! '''IMG !! '''Digimon\n" .. table.concat((function() local rows = {} for _, e in ipairs(unsummonable) do table.insert(rows, "|-\n| " .. e.image .. "\n| " .. e.name .. "\n") end return rows end)(), "") .. "|}\n" or (#summonable == 0 and "''No Digimon in this version.''\n" or ""))
        local rows = ""
        for i = 1, #entries, 2 do
            rows = rows .. "|-\n"
            rows = rows .. "| " .. entries[i].image .. " || " .. entries[i].name .. " || "
            rows = rows .. (entries[i+1] and entries[i+1].image or "") .. " || " .. (entries[i+1] and entries[i+1].name or "") .. "\n"
        end
        return rows
    end
 
    local out = (#summonable > 0 and "===Summonable Digimon===\n{| class=\"fandom-table\"\n! '''IMG''' !! '''Digimon''' !! '''IMG''' !! '''Digimon'''\n" .. buildGrid(summonable) .. "|}\n" or "") ..
                (#unsummonable > 0 and "===Unsummonable Digimon===\n{| class=\"fandom-table\"\n! '''IMG''' !! '''Digimon''' !! '''IMG''' !! '''Digimon'''\n" .. buildGrid(unsummonable) .. "|}\n" or (#summonable == 0 and "''No Digimon in this version.''\n" or ""))


     return frame:preprocess(out)
     return frame:preprocess(out)

Revision as of 07:19, 5 January 2026

Example Usage:

<tabber>
|-|Example=<div class="mobileonly"><h3>Example</h3></div>
{{#invoke:DigimonTab|show|Exam|Ex}}
</tabber>
  • Example = Version tabber label
  • Exam = Master List device tag
  • Ex = Footnote tag (if applicable)

local p = {}

function p.show(frame)
    local versionTag = frame.args[1] or (frame:getParent() and frame:getParent().args[1]) or "Error: No version tag"
    local data = mw.loadData("Module:MasterList")
    local summonable, unsummonable = {}, {}

    for _, digimon in ipairs(data) do
        for i, v in ipairs(digimon.versions or {}) do
            if v == versionTag then
                local status = digimon.summonable[i] or "Yes"
                local entry = {
                    image = digimon.image and digimon.image ~= "" and "[[File:" .. digimon.image .. "|50px]]" or "",
                    name = digimon.name
                }
                if status == "''Yes''" then entry.name = entry.name .. "<ref>You need another device with a similar Battle Type in order to battle with this Digimon.</ref>" end
                table.insert(status == "No" and unsummonable or summonable, entry)
                break
            end
        end
    end

    table.sort(summonable, function(a,b) return mw.text.unstripNoWiki(a.name) < mw.text.unstripNoWiki(b.name) end)
    table.sort(unsummonable, function(a,b) return mw.text.unstripNoWiki(a.name) < mw.text.unstripNoWiki(b.name) end)

    local function buildGrid(entries)
        local rows = ""
        for i = 1, #entries, 2 do
            rows = rows .. "|-\n"
            rows = rows .. "| " .. entries[i].image .. " || " .. entries[i].name .. " || "
            rows = rows .. (entries[i+1] and entries[i+1].image or "") .. " || " .. (entries[i+1] and entries[i+1].name or "") .. "\n"
        end
        return rows
    end

    local out = (#summonable > 0 and "===Summonable Digimon===\n{| class=\"fandom-table\"\n! '''IMG''' !! '''Digimon''' !! '''IMG''' !! '''Digimon'''\n" .. buildGrid(summonable) .. "|}\n" or "") ..
                (#unsummonable > 0 and "===Unsummonable Digimon===\n{| class=\"fandom-table\"\n! '''IMG''' !! '''Digimon''' !! '''IMG''' !! '''Digimon'''\n" .. buildGrid(unsummonable) .. "|}\n" or (#summonable == 0 and "''No Digimon in this version.''\n" or ""))

    return frame:preprocess(out)
end

return p