Happy Early Access Launch! Please bear with us: We're doing our best to get the site updated. If we currently don't have what you're looking for, try checking our sister site, beastieball.info.

If you're looking to contribute to the site, we're happy to have you! Check out Beastiepedia:To Do List to see what needs done.

Find us in the Wishes Unlimited Discord in the "Beastiepedia: The Beastieball Wiki" thread in the Forums!

Module:Learners: Difference between revisions

From Beastiepedia: The Beastieball Wiki
No edit summary
No edit summary
Line 5: Line 5:
function p.Main( frame )
function p.Main( frame )
     local args = getArgs(frame)
     local args = getArgs(frame)
     local play = args[1] or mw.title.getCurrentTitle().text
     local play = (args[1] ~= ""  and args[1]) or mw.title.getCurrentTitle().text
     local levels = args["level"]
     local levels = args["level"]
     levels = levels and levels ~= ""
     levels = levels and levels ~= ""
Line 23: Line 23:
     for _, result in ipairs(results) do
     for _, result in ipairs(results) do
         local tr = tbl:tag("tr")
         local tr = tbl:tag("tr")
         tr:tag("td"):wikitext(result.Beastie)
         tr:tag("td"):wikitext("[[File:" .. result.Beastie .. "Idle.png]]" .. " " .. result.Beastie)
         if levels then
         if levels then
             for rplay in mw.text.gsplit(result.Plays, ", ", true) do
             for rplay in mw.text.gsplit(result.Plays, ", ", true) do

Revision as of 16:22, 19 November 2024

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

local p = {}
local cargo = mw.ext.cargo
local getArgs = require('Module:Arguments').getArgs

function p.Main( frame )
    local args = getArgs(frame)
    local play = (args[1] ~= ""  and args[1]) or mw.title.getCurrentTitle().text
    local levels = args["level"]
    levels = levels and levels ~= ""
    
    local tables = (levels and "BeastieLearnset") or "BeastieLearnFriend"
    local fields = (levels and "Beastie,Plays") or "Beastie"
    local where = tables .. ".Plays HOLDS LIKE '" .. ((levels and play .. "%") or play) .. "'"
    local results = cargo.query(tables, fields, {where=where})

    local tbl = mw.html.create('table'):addClass('wikitable')
    local header = tbl:tag("tr")
        :tag("th"):wikitext("Beastie"):done()
    if levels then
        header:tag("th"):wikitext("Level")
    end

    for _, result in ipairs(results) do
        local tr = tbl:tag("tr")
        tr:tag("td"):wikitext("[[File:" .. result.Beastie .. "Idle.png]]" .. " " .. result.Beastie)
        if levels then
            for rplay in mw.text.gsplit(result.Plays, ", ", true) do
                local rplaysplit = mw.text.split(rplay, ";", true)
                if rplaysplit[1] == play then
                    tr:tag("td"):wikitext(rplaysplit[2])
                    break
                end
            end
        end
    end
    return tbl
end

return p