Módulo:Questlog
Ir para navegação
Ir para pesquisar
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
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("^RESPOSTA:") then
local resposta = mw.ustring.gsub(line, "^RESPOSTA:%s*", "")
bubble:tag("div")
:addClass("questlog-resp")
:wikitext(string.format("[[Arquivo:Chatresposta.png|16px|class=chat-icon|link=]] %s", 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
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 span = itemDiv:tag("span"):addClass("item-wrapper")
span:wikitext(string.format("[[Arquivo:%s.png|48px|link=]]", nome))
span:tag("span")
:addClass("item-count")
:wikitext("x" .. qtd)
end
end
end
return tostring(html)
end
return p