Mudanças entre as edições de "Módulo:Lari1"
Ir para navegação
Ir para pesquisar
| Linha 1: | Linha 1: | ||
local p = {} | local p = {} | ||
local Item = require("Módulo:Item") | |||
function | local function formatNumber(num) | ||
num = tonumber(num) or 0 | |||
if num >= 1e9 then return string.format("%.0f", num / 1e6) .. "KKK" | |||
elseif num >= 1e6 then return string.format("%.0f", num / 1e6) .. "KK" | |||
elseif num >= 1e4 then return string.format("%.0f", num / 1e3) .. "K" | |||
local | else | ||
local s = tostring(num) | |||
return s:reverse():gsub("(%d%d%d)", "%1."):reverse():gsub("^%.", "") | |||
end | |||
end | |||
local function parseItemEntry(entry) | |||
entry = mw.text.trim(entry) | |||
if entry == "" then return nil, nil end | |||
local ident, qtdStr | |||
if entry:find(";") then | |||
ident, qtdStr = entry:match("^(.-)%s*;%s*(%d+)$") | |||
else | |||
ident, qtdStr = entry:match("^(.-)%s*:%s*(%d+)$") | |||
end | end | ||
if not ident or not qtdStr then return nil, nil end | |||
return mw.text.trim(ident), tonumber(qtdStr) | |||
end | |||
function p.reward(frame) | |||
local args = frame:getParent().args | |||
local | local itensRaw = mw.text.trim(args["itens"] or "") | ||
local lang = mw.text.trim(args["lang"] or "pt") | |||
if itensRaw == "" then return "" end | |||
-- | local wrap = mw.html.create("div"):addClass("lk-reward-wrap") | ||
local lbl = wrap:tag("div"):addClass("lk-reward-lbl"):wikitext("Recompensa Final") | |||
local line = wrap:tag("div"):addClass("reward-items") | |||
for entry in mw.text.gsplit(itensRaw, ",", true) do | |||
for | local ident, qtdNum = parseItemEntry(entry) | ||
if ident and qtdNum then | |||
local item = Item.resolve(ident) | |||
if not item then | |||
item = { | |||
id = 0, | |||
image = ident:match("%.%w+$") and ident or (ident .. ".png"), | |||
names = { pt = ident, en = ident }, | |||
category = "misc" | |||
} | |||
end | |||
line:wikitext(Item.renderOne(item, formatNumber(qtdNum), lang, { | |||
showTooltip = true, | |||
showCount = true | |||
})) | |||
end | end | ||
end | end | ||
return tostring(wrap) | |||
return | |||
end | end | ||
return p | return p | ||
Edição das 12h38min de 17 de março de 2026
A documentação para este módulo pode ser criada em Módulo:Lari1/doc
local p = {}
local Item = require("Módulo:Item")
local function formatNumber(num)
num = tonumber(num) or 0
if num >= 1e9 then return string.format("%.0f", num / 1e6) .. "KKK"
elseif num >= 1e6 then return string.format("%.0f", num / 1e6) .. "KK"
elseif num >= 1e4 then return string.format("%.0f", num / 1e3) .. "K"
else
local s = tostring(num)
return s:reverse():gsub("(%d%d%d)", "%1."):reverse():gsub("^%.", "")
end
end
local function parseItemEntry(entry)
entry = mw.text.trim(entry)
if entry == "" then return nil, nil end
local ident, qtdStr
if entry:find(";") then
ident, qtdStr = entry:match("^(.-)%s*;%s*(%d+)$")
else
ident, qtdStr = entry:match("^(.-)%s*:%s*(%d+)$")
end
if not ident or not qtdStr then return nil, nil end
return mw.text.trim(ident), tonumber(qtdStr)
end
function p.reward(frame)
local args = frame:getParent().args
local itensRaw = mw.text.trim(args["itens"] or "")
local lang = mw.text.trim(args["lang"] or "pt")
if itensRaw == "" then return "" end
local wrap = mw.html.create("div"):addClass("lk-reward-wrap")
local lbl = wrap:tag("div"):addClass("lk-reward-lbl"):wikitext("Recompensa Final")
local line = wrap:tag("div"):addClass("reward-items")
for entry in mw.text.gsplit(itensRaw, ",", true) do
local ident, qtdNum = parseItemEntry(entry)
if ident and qtdNum then
local item = Item.resolve(ident)
if not item then
item = {
id = 0,
image = ident:match("%.%w+$") and ident or (ident .. ".png"),
names = { pt = ident, en = ident },
category = "misc"
}
end
line:wikitext(Item.renderOne(item, formatNumber(qtdNum), lang, {
showTooltip = true,
showCount = true
}))
end
end
return tostring(wrap)
end
return p