Módulo:Guild
Ir para navegação
Ir para pesquisar
A documentação para este módulo pode ser criada em Módulo:Guild/doc
--[[
Module:Guild – Dados dos componentes da base de guild.
Uso via predefinição: {{Guild|n=Cozinha|desc=texto livre aqui}}
]]
local p = {}
local function normalize(name)
if not name or name == "" then return nil end
local s = mw.text.trim(name):lower()
s = mw.ustring.gsub(s, "ó", "o")
s = mw.ustring.gsub(s, "ã", "a")
s = mw.ustring.gsub(s, "á", "a")
s = mw.ustring.gsub(s, "é", "e")
s = mw.ustring.gsub(s, " ", "")
return s
end
local aliasMap = {
designer = "Designer",
cofre = "Cofre",
salaoprincipal = "Salão Principal",
salao = "Salão Principal",
quartos = "Quartos",
saladeguerra = "Sala de Guerra",
salaguerra = "Sala de Guerra",
treinamento = "Treinamento",
ferreiro = "Ferreiro",
cozinha = "Cozinha",
estaleiro = "Estaleiro",
}
local data = {
Designer = {
label = "Designer",
levels = {
{ image = "Designer_lvl1.png" },
{ image = "Designer_lvl2.png" },
{ image = "Designer_lvl3.png" },
{ image = "Designer_lvl4.png" },
{ image = "Designer_lvl5.png" },
},
},
Cofre = {
label = "Cofre",
levels = {
{ image = "Cofrelvl1.gif" },
{ image = "Cofrelvl2.gif" },
{ image = "Cofrelvl3.gif" },
{ image = "Cofrelvl4.gif" },
{ image = "Cofrelvl5.gif" },
},
},
["Salão Principal"] = {
label = "Salão Principal",
levels = {
{ image = "Mainhalllvl1.gif" },
{ image = "Mainhalllvl2.gif" },
{ image = "Mainhalllvl3.gif" },
{ image = "Mainhalllvl4.gif" },
{ image = "Mainhalllvl5.gif" },
},
},
Quartos = {
label = "Quartos",
levels = {
{ image = "Quartos_lvl1.gif" },
{ image = "Quartos_lvl2.gif" },
{ image = "Quartos_lvl3.gif" },
{ image = "Quartos_lvl4.gif" },
{ image = "Quartos_lvl5.gif" },
},
},
["Sala de Guerra"] = {
label = "Sala de Guerra",
levels = {
{ image = "SalaDeGuerra_lvl1.png" },
{ image = "SalaDeGuerra_lvl2.png" },
{ image = "SalaDeGuerra_lvl3.png" },
{ image = "SalaDeGuerra_lvl4.png" },
{ image = "SalaDeGuerra_lvl5.png" },
},
},
Treinamento = {
label = "Treinamento",
levels = {
{ image = "Treinamentolvl1.gif" },
{ image = "Treinamentolvl2.gif" },
{ image = "Treinamentolvl3.gif" },
{ image = "Treinamentolvl4.gif" },
{ image = "Treinamentolvl5.gif" },
},
},
Ferreiro = {
label = "Ferreiro",
levels = {
{ image = "Ferreiro_lvl1.png" },
{ image = "Ferreiro_lvl2.png" },
{ image = "Ferreiro_lvl3.png" },
{ image = "Ferreiro_lvl4.png" },
{ image = "Ferreiro_lvl5.png" },
},
},
Cozinha = {
label = "Cozinha",
levels = {
{ image = "Cozinha_lvl1.png" },
{ image = "Cozinha_lvl2.png" },
{ image = "Cozinha_lvl3.png" },
{ image = "Cozinha_lvl4.png" },
{ image = "Cozinhalvl5.gif" },
},
},
Estaleiro = {
label = "Estaleiro",
levels = {
{ image = "Estaleirolvl1.gif" },
{ image = "Estaleirolvl2.gif" },
{ image = "Estaleirolvl3.gif" },
{ image = "Estaleirolvl4.gif" },
{ image = "Estaleirolvl5.gif" },
},
},
}
function p.getComponent(name)
local key = aliasMap[normalize(name)]
if not key then return nil end
return data[key]
end
function p.main(frame)
local args = frame:getParent().args or {}
local n = args.n or args[1] or ""
local comp = p.getComponent(n)
if not comp then
return '<div class="utab">Componente não encontrado: ' .. mw.text.nowiki(n) .. '</div>'
end
local root = mw.html.create('div'):addClass('utab')
local section = root:tag('div'):addClass('utab__section'):attr('data-tab', comp.label)
-- Níveis: imagem + descrição livre por nível (nv1, nv2...)
for i, lvl in ipairs(comp.levels) do
local level = section:tag('div'):addClass('utab__level'):attr('data-level', tostring(i))
local content = level:tag('div'):addClass('utab__content')
content:tag('div'):addClass('utab__mediaImage'):wikitext('[[File:' .. lvl.image .. '|link=]]')
local desc = mw.text.trim(args['nv' .. i] or "")
if desc ~= "" then
content:tag('div'):addClass('utab__desc'):wikitext('\n' .. desc .. '\n')
end
end
return tostring(root)
end
return p