We're currently working on updating the Wiki content for the August 2024 Closed Playtest. All this information is subject to change in the final release.

Find us in the Wishes Unlimited Discord in the "Beastiepedia (Beastieball Wiki)" thread under #beastieball-spoilers!

Module:PlayList: Difference between revisions

From Beastiepedia: The Beastieball Wiki
No edit summary
No edit summary
 
(26 intermediate revisions by one other user not shown)
Line 4: Line 4:


local typeFormat = {
local typeFormat = {
     Body={value="[[File:Body.png|frameless|20x20px]][[Body]]", bg="#f3c18c"},
     Body={value="[[File:Body.png|frameless|20x20px|link=Body]][[Body]]", bg="#f3c18c"},
     Spirit={value="[[File:Spirit.png|frameless|20x20px]][[Spirit]]", bg="#f5abab"},
     Spirit={value="[[File:Spirit.png|frameless|20x20px|link=Spirit]][[Spirit]]", bg="#f5abab"},
     Mind={value="[[File:Mind.png|frameless|20x20px]][[Mind]]", bg="#60c0f3"},
     Mind={value="[[File:Mind.png|frameless|20x20px|link=Mind]][[Mind]]", bg="#60c0f3"},
     Volley={value="[[File:Volley.png|frameless|20x20px]][[Volley]]", bg="#ebcdff"},
     Volley={value="[[File:Volley.png|frameless|20x20px|link=Volley]][[Volley]]", bg="#ebcdff"},
     Support={value="[[File:Support.png|frameless|20x20px]][[Support]]", bg="#99ecaa"},
     Support={value="[[File:Support.png|frameless|20x20px|link=Support]][[Support]]", bg="#99ecaa"},
     Defence={value="[[File:Defence.png|frameless|20x20px]][[Defence]]", bg="#b3b3b3"},
     Defense={value="[[File:Defense.png|frameless|20x20px|link=Defense]][[Defense]]", bg="#b3b3b3"},
     Move={value="[[File:Move.png|frameless|20x20px]][[Move]]", bg=nil},
     Move={value="[[File:Move.png|frameless|20x20px|link=Move]][[Move]]", bg=nil},
}
}


Line 19: Line 19:
     Volley=false,
     Volley=false,
     Support=false,
     Support=false,
     Defence=false,
     Defense=false,
     Move=false,
     Move=false,
}
}
Line 71: Line 71:
     local tables = 'Plays'
     local tables = 'Plays'
     local args = {
     local args = {
         where = "Name IN ('" .. table.concat(names, "','") .. "')",
         where = "Plays.Name IN ('" .. table.concat(names, "','") .. "')",
        limit = 99999,
     }
     }
     if where then
     if where then
Line 79: Line 80:
     local results = cargo.query( tables, table.concat(fields, ","), args )
     local results = cargo.query( tables, table.concat(fields, ","), args )
     local tbl = mw.html.create('table'):addClass('wikitable')
     local tbl = mw.html.create('table'):addClass('wikitable')
    tbl:css( 'width', '100%' )
     if sortable then
     if sortable then
         tbl:addClass('sortable')
         tbl:addClass('sortable')
Line 98: Line 100:
     for _, name in ipairs(names) do
     for _, name in ipairs(names) do
         local row = namedResults[name]
         local row = namedResults[name]
         if row then
         local tr = tbl:tag('tr')
            local tr = tbl:tag('tr')
        for k = 1, #displayFields do
            for k = 1, #displayFields do
            local td = tr:tag('td')
                if displayFields[k] == "Type" then
            local field = displayFields[k]
                    local format = typeFormat[row[displayFields[k]]]
            local content = row and row[field]
                    local td = tr:tag('td'):wikitext(format.value)
            if field == "Level" then
                    if format.bg then
                td:wikitext(levels[name])
                        td:attr("bgcolor", format.bg)
            elseif field == "Type" then
                    end
                 local format = typeFormat[content]
                elseif displayFields[k] == "Level" then
                td:wikitext((format and format.value) or content)
                    tr:tag('td'):wikitext(levels[name])
                if format then
                 else
                     td:attr("bgcolor", format.bg)
                    local content = row[displayFields[k]]
                    if fieldTransform[displayFields[k]] then
                        content = fieldTransform[displayFields[k]](content)
                    end
                    if not content then
                        content = "--"
                     end
                    if displayFields[k] == "Pow" and not hasPow[row["Type"]] then
                        content = "--"
                    end
                    tr:tag('td'):wikitext(frame:preprocess(content))
                 end
                 end
            else
                content = content or (field == "Name" and name) or "--"
                if fieldTransform[field] then
                    content = fieldTransform[field](content)
                end
                if field == "Pow" and row and not hasPow[row["Type"]] then
                    content = "--"
                end
                td:wikitext(frame:preprocess(content))
             end
             end
         end
         end

Latest revision as of 00:08, 24 September 2024

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

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

local typeFormat = {
    Body={value="[[File:Body.png|frameless|20x20px|link=Body]][[Body]]", bg="#f3c18c"},
    Spirit={value="[[File:Spirit.png|frameless|20x20px|link=Spirit]][[Spirit]]", bg="#f5abab"},
    Mind={value="[[File:Mind.png|frameless|20x20px|link=Mind]][[Mind]]", bg="#60c0f3"},
    Volley={value="[[File:Volley.png|frameless|20x20px|link=Volley]][[Volley]]", bg="#ebcdff"},
    Support={value="[[File:Support.png|frameless|20x20px|link=Support]][[Support]]", bg="#99ecaa"},
    Defense={value="[[File:Defense.png|frameless|20x20px|link=Defense]][[Defense]]", bg="#b3b3b3"},
    Move={value="[[File:Move.png|frameless|20x20px|link=Move]][[Move]]", bg=nil},
}

local hasPow = {
    Body=true,
    Spirit=true,
    Mind=true,
    Volley=false,
    Support=false,
    Defense=false,
    Move=false,
}

local fieldTransform = {}

function fieldTransform.Name(content)
    return "[[" .. content .. "]]"
end

function p.Main( frame )
    local names = {}
    local where = nil
    local args = getArgs(frame)
    local extraHeader = nil
    local sortable = false
    local displayFields = {"Name", "Description", "Pow", "Type"}
    local fields = {"Name", "Description", "Pow", "Type"}
    local levelEnabled = false
    local lookingForLevel = false
    local levels = {}
    local lastPlay = nil
    for k, v in pairs(args) do
        if k == "header" then
            extraHeader = v
        elseif k == "where" then
            where = v
        elseif v == "?sortable" then
            sortable = true
        elseif v == "?level" then
            levelEnabled = true
            table.insert(displayFields, "Level")
        elseif v == "?favors" then
            table.insert(displayFields, "Favors")
            table.insert(fields, "Favors")
        elseif v[1] ~= "?" then
            if lookingForLevel then
                levels[lastPlay] = v
            else
                lastPlay = v
                table.insert(names, v)
            end
            if levelEnabled then
                lookingForLevel = lookingForLevel == false
            end
        end
    end
    if #names == 0 and where == nil then
        return "No moves specified"
    end
    local tables = 'Plays'
    local args = {
        where = "Plays.Name IN ('" .. table.concat(names, "','") .. "')",
        limit = 99999,
    }
    if where then
        args.where = where
        names = {}
    end
    local results = cargo.query( tables, table.concat(fields, ","), args )
    local tbl = mw.html.create('table'):addClass('wikitable')
    tbl:css( 'width', '100%' )
    if sortable then
        tbl:addClass('sortable')
    end
    if extraHeader then
        tbl:tag('tr'):tag('th'):attr("colspan", #displayFields):wikitext(extraHeader)
    end
    local header = tbl:tag('tr')
    for k = 1, #displayFields do
        header:tag('th'):wikitext(displayFields[k])
    end
    local namedResults = {}
    for r = 1, #results do
        namedResults[results[r].Name] = results[r]
        if where then
            table.insert(names, results[r].Name)
        end
    end
    for _, name in ipairs(names) do
        local row = namedResults[name]
        local tr = tbl:tag('tr')
        for k = 1, #displayFields do
            local td = tr:tag('td')
            local field = displayFields[k]
            local content = row and row[field]
            if field == "Level" then
                td:wikitext(levels[name])
            elseif field == "Type" then
                local format = typeFormat[content]
                td:wikitext((format and format.value) or content)
                if format then
                    td:attr("bgcolor", format.bg)
                end
            else
                content = content or (field == "Name" and name) or "--"
                if fieldTransform[field] then
                    content = fieldTransform[field](content)
                end
                if field == "Pow" and row and not hasPow[row["Type"]] then
                    content = "--"
                end
                td:wikitext(frame:preprocess(content))
            end
        end
    end
    return tbl
end

return p