Mudanças entre as edições de "Módulo:Item"
Ir para navegação
Ir para pesquisar
(init) |
m |
||
| Linha 5: | Linha 5: | ||
local FALLBACK_LANG = "en" | local FALLBACK_LANG = "en" | ||
local DEFAULT_FRAME_SIZE = 32 | local DEFAULT_FRAME_SIZE = 32 | ||
local CATEGORY_LABELS = { | |||
currency = "Moeda", | |||
key_item = "Item-Chave", | |||
consumable = "Consumível", | |||
material = "Material", | |||
potion = "Poção", | |||
medal = "Medalha", | |||
chip = "Chip", | |||
crystal = "Cristal", | |||
food = "Comida", | |||
quest_item = "Item de Quest", | |||
book = "Livro", | |||
tool = "Ferramenta", | |||
misc = "Diversos", | |||
weapon = "Arma", | |||
set_piece = "Peça de Set", | |||
cosmetic = "Cosmético" | |||
} | |||
local function formatDots(n) | |||
local s = tostring(n) | |||
local pos = #s % 3 | |||
if pos == 0 then pos = 3 end | |||
local parts = { s:sub(1, pos) } | |||
for i = pos + 1, #s, 3 do | |||
parts[#parts + 1] = s:sub(i, i + 2) | |||
end | |||
return table.concat(parts, ".") | |||
end | |||
function Item.resolve(query) | function Item.resolve(query) | ||
| Linha 27: | Linha 57: | ||
or item.desc[FALLBACK_LANG] | or item.desc[FALLBACK_LANG] | ||
or nil | or nil | ||
end | |||
function Item.getValue(item) | |||
if not item then return nil end | |||
return item.value | |||
end | |||
function Item.getLevel(item) | |||
if not item then return nil end | |||
return item.level | |||
end | end | ||
| Linha 40: | Linha 80: | ||
end | end | ||
return DEFAULT_FRAME_SIZE, DEFAULT_FRAME_SIZE | return DEFAULT_FRAME_SIZE, DEFAULT_FRAME_SIZE | ||
end | |||
function Item.getCategoryLabel(item) | |||
if not item or not item.category then return nil end | |||
return CATEGORY_LABELS[item.category] | |||
end | end | ||
| Linha 47: | Linha 92: | ||
if not item then return "" end | if not item then return "" end | ||
local nome = Item.getName(item, lang) | local nome = Item.getName(item, lang) | ||
local desc = Item.getDesc(item, lang) | local desc = Item.getDesc(item, lang) | ||
local image = Item.getImage(item) | local image = Item.getImage(item) | ||
local catLabel = Item.getCategoryLabel(item) | |||
local value = Item.getValue(item) | |||
local level = Item.getLevel(item) | |||
if not image then return "" end | if not image then return "" end | ||
local w, h = Item.getSpriteSize(item) | local w, h = Item.getSpriteSize(item) | ||
| Linha 64: | Linha 107: | ||
:css("height", h .. "px") | :css("height", h .. "px") | ||
wrapper:tag("span") | |||
:wikitext(string.format("[[Arquivo:%s|%dx%dpx|link=]]", image, w, h)) | |||
if qty and options.showCount ~= false then | if qty and options.showCount ~= false then | ||
| Linha 80: | Linha 117: | ||
end | end | ||
countSpan:wikitext(tostring(qty)) | countSpan:wikitext(tostring(qty)) | ||
end | |||
if options.showTooltip ~= false then | |||
local tip = wrapper:tag("span"):addClass("item-tooltip") | |||
local body = tip:tag("span"):addClass("item-tooltip-body") | |||
body:tag("span"):addClass("item-tooltip-name"):wikitext(nome) | |||
if catLabel then | |||
body:tag("span"):addClass("item-tooltip-cat"):wikitext(catLabel) | |||
end | |||
local hasExtra = desc or value or level | |||
if hasExtra then | |||
body:tag("span"):addClass("item-tooltip-sep") | |||
end | |||
if desc then | |||
body:tag("span"):addClass("item-tooltip-desc"):wikitext(desc) | |||
end | |||
if value or level then | |||
local footer = body:tag("span"):addClass("item-tooltip-footer") | |||
if value then | |||
footer:tag("span"):addClass("item-tooltip-val") | |||
:wikitext("Valor: " .. formatDots(value)) | |||
end | |||
if level then | |||
footer:tag("span"):addClass("item-tooltip-lvl") | |||
:wikitext("Nv. " .. tostring(level)) | |||
end | |||
end | |||
tip:tag("span"):addClass("item-tooltip-arrow") | |||
end | end | ||
Edição das 22h40min de 16 de março de 2026
A documentação para este módulo pode ser criada em Módulo:Item/doc
local Item = {}
local ItemDB = require("Módulo:ItemDB")
local DEFAULT_LANG = "pt"
local FALLBACK_LANG = "en"
local DEFAULT_FRAME_SIZE = 32
local CATEGORY_LABELS = {
currency = "Moeda",
key_item = "Item-Chave",
consumable = "Consumível",
material = "Material",
potion = "Poção",
medal = "Medalha",
chip = "Chip",
crystal = "Cristal",
food = "Comida",
quest_item = "Item de Quest",
book = "Livro",
tool = "Ferramenta",
misc = "Diversos",
weapon = "Arma",
set_piece = "Peça de Set",
cosmetic = "Cosmético"
}
local function formatDots(n)
local s = tostring(n)
local pos = #s % 3
if pos == 0 then pos = 3 end
local parts = { s:sub(1, pos) }
for i = pos + 1, #s, 3 do
parts[#parts + 1] = s:sub(i, i + 2)
end
return table.concat(parts, ".")
end
function Item.resolve(query)
if not query or query == "" then return nil end
return ItemDB.get(query)
end
function Item.getName(item, lang)
if not item or not item.names then return "" end
lang = lang or DEFAULT_LANG
return item.names[lang]
or item.names[DEFAULT_LANG]
or item.names[FALLBACK_LANG]
or item.image or ""
end
function Item.getDesc(item, lang)
if not item or not item.desc then return nil end
lang = lang or DEFAULT_LANG
return item.desc[lang]
or item.desc[DEFAULT_LANG]
or item.desc[FALLBACK_LANG]
or nil
end
function Item.getValue(item)
if not item then return nil end
return item.value
end
function Item.getLevel(item)
if not item then return nil end
return item.level
end
function Item.getImage(item)
if not item then return nil end
return item.image
end
function Item.getSpriteSize(item)
if item and item.sprite then
return item.sprite.frameWidth or DEFAULT_FRAME_SIZE,
item.sprite.frameHeight or DEFAULT_FRAME_SIZE
end
return DEFAULT_FRAME_SIZE, DEFAULT_FRAME_SIZE
end
function Item.getCategoryLabel(item)
if not item or not item.category then return nil end
return CATEGORY_LABELS[item.category]
end
function Item.renderOne(item, qty, lang, options)
options = options or {}
lang = lang or DEFAULT_LANG
if not item then return "" end
local nome = Item.getName(item, lang)
local desc = Item.getDesc(item, lang)
local image = Item.getImage(item)
local catLabel = Item.getCategoryLabel(item)
local value = Item.getValue(item)
local level = Item.getLevel(item)
if not image then return "" end
local w, h = Item.getSpriteSize(item)
local wrapper = mw.html.create("span")
:addClass("item-wrapper")
:css("width", w .. "px")
:css("height", h .. "px")
wrapper:tag("span")
:wikitext(string.format("[[Arquivo:%s|%dx%dpx|link=]]", image, w, h))
if qty and options.showCount ~= false then
local countSpan = wrapper:tag("span"):addClass("item-count")
local isBerries = item.category == "currency" and image:lower():find("berries")
if not isBerries then
countSpan:tag("span"):addClass("item-count-x"):wikitext("x")
end
countSpan:wikitext(tostring(qty))
end
if options.showTooltip ~= false then
local tip = wrapper:tag("span"):addClass("item-tooltip")
local body = tip:tag("span"):addClass("item-tooltip-body")
body:tag("span"):addClass("item-tooltip-name"):wikitext(nome)
if catLabel then
body:tag("span"):addClass("item-tooltip-cat"):wikitext(catLabel)
end
local hasExtra = desc or value or level
if hasExtra then
body:tag("span"):addClass("item-tooltip-sep")
end
if desc then
body:tag("span"):addClass("item-tooltip-desc"):wikitext(desc)
end
if value or level then
local footer = body:tag("span"):addClass("item-tooltip-footer")
if value then
footer:tag("span"):addClass("item-tooltip-val")
:wikitext("Valor: " .. formatDots(value))
end
if level then
footer:tag("span"):addClass("item-tooltip-lvl")
:wikitext("Nv. " .. tostring(level))
end
end
tip:tag("span"):addClass("item-tooltip-arrow")
end
return tostring(wrapper)
end
function Item.renderLine(itemList, lang, options)
options = options or {}
lang = lang or DEFAULT_LANG
if not itemList or #itemList == 0 then return "" end
local container = mw.html.create("div")
:addClass("reward-items")
for _, entry in ipairs(itemList) do
container:wikitext(Item.renderOne(entry.item, entry.qty, lang, options))
end
return tostring(container)
end
return Item