Mudanças entre as edições de "Módulo:Quest"

De Wiki Gla
Ir para navegação Ir para pesquisar
Linha 1: Linha 1:
local p = {}
local p = {}
local itemData = require("Módulo:ItemData")
local itemData = require("Módulo:Itemdata")


local function formatNumber(n)
local function formatNumber(n)
Linha 8: Linha 8:
end
end


local function normalizarChave(nome)
local function buscarChaveCorreta(nome)
     nome = mw.text.trim(nome)
     local base = mw.text.trim(nome):lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
    nome = nome:gsub("_", " ")
     for chave, _ in pairs(itemData) do
    -- Capitaliza só a primeira letra do nome inteiro
        local kbase = chave:lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
    nome = nome:sub(1, 1):upper() .. nome:sub(2)
        if kbase == base then
     local temExt = nome:match("%.png$") or nome:match("%.gif$") or nome:match("%.jpg$") or nome:match("%.webp$")
            return chave
    if not temExt then
         end
         nome = nome .. ".png"
     end
     end
     return nome
     return nil
end
end


Linha 25: Linha 24:
         local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$")
         local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$")
         if nome and qtd then
         if nome and qtd then
             local chave = normalizarChave(nome)
             local chave = buscarChaveCorreta(nome) or (nome .. ".png")
             qtd = tonumber(qtd) or 0
             qtd = tonumber(qtd) or 0
             resultado[chave] = (resultado[chave] or 0) + qtd
             resultado[chave] = (resultado[chave] or 0) + qtd
Linha 47: Linha 46:
     local args = frame:getParent().args or {}
     local args = frame:getParent().args or {}
     local bonus = args.bonus or ""
     local bonus = args.bonus or ""
     local content = mw.title.getCurrentTitle():getContent()
     local content = mw.title.getCurrentTitle():getContent()
     local rewardCalls = {}
     local rewardCalls = {}
Linha 53: Linha 51:
     for bloco in content:gmatch("{{%s*[Rr]eward.-}}") do
     for bloco in content:gmatch("{{%s*[Rr]eward.-}}") do
         local itens = bloco:match("itens%s*=%s*([^|}]+)")
         local itens = bloco:match("itens%s*=%s*([^|}]+)")
         if itens then
         if itens then table.insert(rewardCalls, itens) end
            table.insert(rewardCalls, itens)
        end
    end
 
    if bonus and bonus ~= "" then
        table.insert(rewardCalls, bonus)
     end
     end
    if bonus and bonus ~= "" then table.insert(rewardCalls, bonus) end


     local total = mergeRecompensas(rewardCalls)
     local total = mergeRecompensas(rewardCalls)
 
     if next(total) == nil then return "" end
     if next(total) == nil then
        return ""
    end


     local html = mw.html.create("div")
     local html = mw.html.create("div")
     html:addClass("introquest-items")
     html:addClass("introquest-items")
    local berriesItem = nil
    local outros = {}


     for nome, qtd in pairs(total) do
     for nome, qtd in pairs(total) do
Linha 76: Linha 69:
         local desc = data.desc
         local desc = data.desc
         local tooltip = nomeCompleto
         local tooltip = nomeCompleto
         if desc and desc ~= "" then
         if desc and desc ~= "" then tooltip = tooltip .. "\n—\n" .. desc end
            tooltip = tooltip .. "\n—\n" .. desc
        end


         local wrapper = html:tag("span")
         local bloco = {
        wrapper:addClass("item-wrapper")
            arquivo = nome,
        wrapper:addClass("introquest-item")
            qtd = (nome:lower():match("^berries") and "" or "x") .. formatNumber(qtd),
        wrapper:attr("data-tooltip", tooltip)
            tooltip = tooltip
        }


         wrapper:tag("span")
         if nome:lower() == "berries.gif" then
             :wikitext(string.format("[[Arquivo:%s|link=]]", nome))
            berriesItem = bloco
        else
             table.insert(outros, bloco)
        end
    end


         wrapper:tag("span")
    local function addBloco(bloco)
            :addClass("item-count")
         local wrap = html:tag("span"):addClass("item-wrapper introquest-item"):attr("data-tooltip", bloco.tooltip)
            :wikitext((nome:lower():match("^berries") and "" or "x") .. formatNumber(qtd))
        wrap:tag("span"):wikitext(string.format("[[Arquivo:%s|link=]]", bloco.arquivo))
        wrap:tag("span"):addClass("item-count"):wikitext(bloco.qtd)
     end
     end
    if berriesItem then addBloco(berriesItem) end
    for _, b in ipairs(outros) do addBloco(b) end


     return tostring(html)
     return tostring(html)
Linha 97: Linha 97:


function p.requisitos(frame)
function p.requisitos(frame)
     local args = frame:getParent().args or {}
     local args = frame:getParent().args or ""
     local raw = args.requisitos or ""
     local raw = args.requisitos or ""
     if mw.text.trim(raw) == "" then return "" end
     if mw.text.trim(raw) == "" then return "" end
Linha 104: Linha 104:
     for item in mw.text.gsplit(raw, ",", true) do
     for item in mw.text.gsplit(raw, ",", true) do
         local clean = mw.text.trim(item)
         local clean = mw.text.trim(item)
         if clean ~= "" then
         if clean ~= "" then table.insert(output, "* " .. clean) end
            table.insert(output, "* " .. clean)
        end
     end
     end
     return table.concat(output, "\n")
     return table.concat(output, "\n")
end
end


return p
return p

Edição das 12h40min de 11 de junho de 2025

A documentação para este módulo pode ser criada em Módulo:Quest/doc

local p = {}
local itemData = require("Módulo:Itemdata")

local function formatNumber(n)
    local s = tostring(n)
    local result = s:reverse():gsub("(%d%d%d)", "%1,"):reverse()
    return result:gsub("^,", "")
end

local function buscarChaveCorreta(nome)
    local base = mw.text.trim(nome):lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
    for chave, _ in pairs(itemData) do
        local kbase = chave:lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
        if kbase == base then
            return chave
        end
    end
    return nil
end

local function parseItens(raw)
    local resultado = {}
    for item in mw.text.gsplit(raw or "", ",", true) do
        local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$")
        if nome and qtd then
            local chave = buscarChaveCorreta(nome) or (nome .. ".png")
            qtd = tonumber(qtd) or 0
            resultado[chave] = (resultado[chave] or 0) + qtd
        end
    end
    return resultado
end

local function mergeRecompensas(lista)
    local total = {}
    for _, raw in ipairs(lista) do
        local dados = parseItens(raw)
        for nome, qtd in pairs(dados) do
            total[nome] = (total[nome] or 0) + qtd
        end
    end
    return total
end

function p.total(frame)
    local args = frame:getParent().args or {}
    local bonus = args.bonus or ""
    local content = mw.title.getCurrentTitle():getContent()
    local rewardCalls = {}

    for bloco in content:gmatch("{{%s*[Rr]eward.-}}") do
        local itens = bloco:match("itens%s*=%s*([^|}]+)")
        if itens then table.insert(rewardCalls, itens) end
    end
    if bonus and bonus ~= "" then table.insert(rewardCalls, bonus) end

    local total = mergeRecompensas(rewardCalls)
    if next(total) == nil then return "" end

    local html = mw.html.create("div")
    html:addClass("introquest-items")

    local berriesItem = nil
    local outros = {}

    for nome, qtd in pairs(total) do
        local data = itemData[nome] or {}
        local nomeCompleto = data.nome or nome
        local desc = data.desc
        local tooltip = nomeCompleto
        if desc and desc ~= "" then tooltip = tooltip .. "\n—\n" .. desc end

        local bloco = {
            arquivo = nome,
            qtd = (nome:lower():match("^berries") and "" or "x") .. formatNumber(qtd),
            tooltip = tooltip
        }

        if nome:lower() == "berries.gif" then
            berriesItem = bloco
        else
            table.insert(outros, bloco)
        end
    end

    local function addBloco(bloco)
        local wrap = html:tag("span"):addClass("item-wrapper introquest-item"):attr("data-tooltip", bloco.tooltip)
        wrap:tag("span"):wikitext(string.format("[[Arquivo:%s|link=]]", bloco.arquivo))
        wrap:tag("span"):addClass("item-count"):wikitext(bloco.qtd)
    end

    if berriesItem then addBloco(berriesItem) end
    for _, b in ipairs(outros) do addBloco(b) end

    return tostring(html)
end

function p.requisitos(frame)
    local args = frame:getParent().args or ""
    local raw = args.requisitos or ""
    if mw.text.trim(raw) == "" then return "" end

    local output = {}
    for item in mw.text.gsplit(raw, ",", true) do
        local clean = mw.text.trim(item)
        if clean ~= "" then table.insert(output, "* " .. clean) end
    end
    return table.concat(output, "\n")
end

return p