Module:Creep drop infobox

From Little-Known Galaxy Wiki
Jump to navigation Jump to search

This module is used in the {{Creep infobox}} template.

Subpages

local argsUtil = require("Module:ArgsUtil")
local cargoUtil = require("Module:CargoUtil")

local p = {}

function p.main(frame)
    -- Get the arguments and merge them
    local args = argsUtil.merge(frame.args, frame:getParent().args)
    local tableID = args[1]

    -- If no tableID is provided, return an empty string
    if not tableID or tableID == "" then
        return "No tableID provided."
    end

    -- Escape tableID to prevent SQL injection
    local escapedTableID = cargoUtil.escapeString(tableID)

    -- Query the cargo table
    local queryOptions = {
        tables = "lootTable",
        fields = "itemName",
        where = 'tableID="' .. escapedTableID .. '"'
    }

    local results = cargoUtil.queryData(queryOptions)

    -- Initialize an empty table for storing icon links
    local icons = {}

    -- Iterate over the results and build the icon links
    for _, row in ipairs(results) do
        local itemName = row.itemName

        -- Suppress results where itemName is "nothing" (case-insensitive check)
        if itemName and itemName:lower() ~= "nothing" then
            -- Create the icon link
            table.insert(icons, '[[File:' .. itemName .. '.png|45px|link=' .. itemName .. ']]')
        end
    end

    -- Concatenate all icons and return them as a string
    return table.concat(icons, " ")
end

return p