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

De Wiki Gla
Ir para navegação Ir para pesquisar
 
(6 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 11: Linha 11:
     html:addClass("questlog-wrapper")
     html:addClass("questlog-wrapper")


     -- Imagem
     -- Imagem do NPC
     html:tag("div")
     html:tag("div")
         :addClass("questlog-img")
         :addClass("questlog-img")
Linha 22: Linha 22:
         line = mw.text.trim(line)
         line = mw.text.trim(line)
         if line ~= "" then
         if line ~= "" then
             if line:match("^RESPOSTA:") then
             if line:match("^R:") then
                 bubble:tag("div")
                 local resposta = mw.ustring.gsub(line, "^R:%s*", "")
                    :addClass("questlog-resp")
                local div = bubble:tag("div"):addClass("questlog-resp")
                    :wikitext(mw.ustring.gsub(line, "^RESPOSTA:%s*", ""))
                div:tag("span"):wikitext("Jogador: ")
             elseif line:match("^" .. npc .. ":") then
                div:tag("span"):wikitext("'''" .. resposta .. "'''")
                 local conteudo = mw.ustring.gsub(line, "^"..npc..":%s*", "")
 
             elseif line:match("^NPC:") then
                 local fala = mw.ustring.gsub(line, "^NPC:%s*", "")
                 bubble:tag("div")
                 bubble:tag("div")
                     :addClass("questlog-text")
                     :addClass("questlog-text")
                     :wikitext("'''"..npc..":''' " .. conteudo)
                     :wikitext("'''"..npc..":''' " .. fala)
 
             else
             else
                 bubble:tag("div")
                 bubble:tag("div")
Linha 39: Linha 42:
     end
     end


     -- Itens
     -- Itens recebidos
     if itens and itens ~= "" then
     if itens and itens ~= "" then
         local wrapper = bubble:tag("div"):css("margin-top", "20px")
         local wrapper = bubble:tag("div"):css("margin-top", "20px")
Linha 48: Linha 51:
             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 temExtensao = nome:match("%.png$") or nome:match("%.gif$") or nome:match("%.jpg$") or nome:match("%.webp$")
                local arquivo = temExtensao and nome or (nome .. ".png")
                 local span = itemDiv:tag("span"):addClass("item-wrapper")
                 local span = itemDiv:tag("span"):addClass("item-wrapper")
                 span:wikitext(string.format("[[Arquivo:%s.png|48px|link=]]", nome))
                 span:wikitext(string.format("[[Arquivo:%s|link=]]", arquivo))
                 span:tag("span")
                 span:tag("span")
                     :addClass("item-count")
                     :addClass("item-count")

Edição atual tal como às 02h27min de 22 de maio de 2025

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

local p = {}

function p.exibir(frame)
    local args = frame:getParent().args
    local img = args.img or "SemImagem"
    local npc = args.nomenpc or "NPC"
    local texto = args.descricao or ""
    local itens = args.itens or ""

    local html = mw.html.create("div")
    html:addClass("questlog-wrapper")

    -- Imagem do NPC
    html:tag("div")
        :addClass("questlog-img")
        :wikitext(string.format("[[Arquivo:%s.png|link=]]", img))

    -- Balão de fala
    local bubble = html:tag("div"):addClass("questlog-bubble")

    for line in texto:gmatch("[^\r\n]+") do
        line = mw.text.trim(line)
        if line ~= "" then
            if line:match("^R:") then
                local resposta = mw.ustring.gsub(line, "^R:%s*", "")
                local div = bubble:tag("div"):addClass("questlog-resp")
                div:tag("span"):wikitext("Jogador: ")
                div:tag("span"):wikitext("'''" .. resposta .. "'''")

            elseif line:match("^NPC:") then
                local fala = mw.ustring.gsub(line, "^NPC:%s*", "")
                bubble:tag("div")
                    :addClass("questlog-text")
                    :wikitext("'''"..npc..":''' " .. fala)

            else
                bubble:tag("div")
                    :addClass("questlog-text")
                    :wikitext(line)
            end
        end
    end

    -- Itens recebidos
    if itens and itens ~= "" then
        local wrapper = bubble:tag("div"):css("margin-top", "20px")
        wrapper:tag("div"):addClass("label"):wikitext("Itens Recebidos")
        local itemDiv = wrapper:tag("div"):addClass("questlog-items"):css("margin-top", "10px")

        for item in mw.text.gsplit(itens, ",", true) do
            local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$")
            if nome and qtd then
                local temExtensao = nome:match("%.png$") or nome:match("%.gif$") or nome:match("%.jpg$") or nome:match("%.webp$")
                local arquivo = temExtensao and nome or (nome .. ".png")
                local span = itemDiv:tag("span"):addClass("item-wrapper")
                span:wikitext(string.format("[[Arquivo:%s|link=]]", arquivo))
                span:tag("span")
                    :addClass("item-count")
                    :wikitext("x" .. qtd)
            end
        end
    end

    return tostring(html)
end

return p