Mudanças entre as edições de "Módulo:I.Skills"
Ir para navegação
Ir para pesquisar
m (primeiro fix) |
m |
||
| Linha 36: | Linha 36: | ||
end | end | ||
return nil | return nil | ||
end | |||
-- Processa weapon (aplica colorize nas descrições) | |||
local function processWeapon(weapon) | |||
if not weapon or type(weapon) ~= "table" then | |||
return weapon | |||
end | |||
local processed = {} | |||
-- Copia todos os campos do weapon | |||
for k, v in pairs(weapon) do | |||
processed[k] = v | |||
end | |||
-- Processa descrição do weapon (se existir) | |||
if weapon.desc then | |||
processed.desc_i18n = processDesc(weapon.desc) | |||
-- Remove desc se desc_i18n foi criado (para evitar duplicação) | |||
if processed.desc_i18n then | |||
processed.desc = nil | |||
end | |||
end | |||
return processed | |||
end | end | ||
| Linha 60: | Linha 84: | ||
desc_i18n = processDesc(sub.desc), | desc_i18n = processDesc(sub.desc), | ||
flags = sub.flags, | flags = sub.flags, | ||
weapon = sub.weapon, | weapon = processWeapon(sub.weapon), | ||
back = sub.back | back = sub.back | ||
} | } | ||
| Linha 110: | Linha 134: | ||
desc_i18n = processDesc(sk.desc), | desc_i18n = processDesc(sk.desc), | ||
flags = sk.flags, | flags = sk.flags, | ||
weapon = sk.weapon, | weapon = processWeapon(sk.weapon), | ||
weaponicon = data.weaponicon | weaponicon = data.weaponicon | ||
} | } | ||
Edição das 22h03min de 31 de dezembro de 2025
A documentação para este módulo pode ser criada em Módulo:I.Skills/doc
-- Módulo:I.Skills — skill(), skin() com suporte nativo a subskills recursivas
local p = {}
local utils = require("Módulo:I.Utils")
local trim = utils.trim
local colorize = utils.colorize
-- Fallback se colorize não existir
if not colorize or type(colorize) ~= "function" then
colorize = function(txt)
if not txt or txt == "" then
return ""
end
-- Versão simplificada sem colorização
return tostring(txt)
end
end
local cUtils = require("Módulo:C.Utils")
local requireCharModule = cUtils.requireCharModule
-- Processa descrição (desc table → desc_i18n)
local function processDesc(desc)
if not desc then return nil end
if type(desc) == "string" then
return { pt = colorize(desc) }
end
if type(desc) == "table" then
local desc_i18n = {}
for code, text in pairs(desc) do
if type(text) == "string" and text ~= "" then
desc_i18n[code] = colorize(text)
end
end
return next(desc_i18n) and desc_i18n or nil
end
return nil
end
-- Processa weapon (aplica colorize nas descrições)
local function processWeapon(weapon)
if not weapon or type(weapon) ~= "table" then
return weapon
end
local processed = {}
-- Copia todos os campos do weapon
for k, v in pairs(weapon) do
processed[k] = v
end
-- Processa descrição do weapon (se existir)
if weapon.desc then
processed.desc_i18n = processDesc(weapon.desc)
-- Remove desc se desc_i18n foi criado (para evitar duplicação)
if processed.desc_i18n then
processed.desc = nil
end
end
return processed
end
-- Processa subskills recursivamente (suporte ilimitado a níveis)
local function processSubskills(subskills, suborder)
if not subskills or not suborder or type(subskills) ~= "table" or type(suborder) ~= "table" then
return nil
end
local arr = {}
for _, subName in ipairs(suborder) do
local sub = subskills[subName]
if type(sub) == "table" then
local subObj = {
name = subName,
n = subName,
icon = sub.icon or "",
level = sub.level or "",
energy = sub.energy,
powerpve = sub.powerpve,
powerpvp = sub.powerpvp,
cooldown = sub.cooldown,
video = sub.video or "",
desc_i18n = processDesc(sub.desc),
flags = sub.flags,
weapon = processWeapon(sub.weapon),
back = sub.back
}
-- RECURSÃO NATIVA: processa sub-subskills (e sub-sub-subskills, etc.)
if type(sub.subskills) == "table" and type(sub.suborder) == "table" then
subObj.subs = processSubskills(sub.subskills, sub.suborder)
subObj.suborder = sub.suborder
end
table.insert(arr, subObj)
end
end
return #arr > 0 and arr or nil
end
-- Gera JSON de skills a partir do módulo
function p.skill(frame)
local parent = frame:getParent() or frame
local args = parent.args or {}
local moduleName = trim(args.module or "")
if moduleName == "" then
return "[]"
end
local data = requireCharModule(moduleName) or {}
if not data.order or not data.skills then
return "[]"
end
local skillsArr = {}
-- Itera sobre order para manter ordem correta
for idx, skillName in ipairs(data.order) do
local sk = data.skills[skillName]
if type(sk) == "table" then
local skillObj = {
name = skillName,
n = skillName,
icon = sk.icon or "Nada.png",
level = sk.level or "NIVEL",
energy = sk.energy,
powerpve = sk.powerpve,
powerpvp = sk.powerpvp,
cooldown = sk.cooldown,
video = sk.video or "",
desc_i18n = processDesc(sk.desc),
flags = sk.flags,
weapon = processWeapon(sk.weapon),
weaponicon = data.weaponicon
}
-- Processa subskills recursivamente (suporte nativo ilimitado)
if type(sk.subskills) == "table" and type(sk.suborder) == "table" then
skillObj.subs = processSubskills(sk.subskills, sk.suborder)
skillObj.suborder = sk.suborder
end
table.insert(skillsArr, skillObj)
end
end
return mw.text.jsonEncode(skillsArr)
end
-- Gera JSON de skins a partir do módulo
function p.skin(frame)
local parent = frame:getParent() or frame
local args = parent.args or {}
local moduleName = trim(args.module or "")
if moduleName == "" then
return "[]"
end
local data = requireCharModule(moduleName) or {}
if not data.skins or type(data.skins) ~= "table" then
return "[]"
end
-- Processa skins do módulo
local skinsArr = {}
for _, skin in ipairs(data.skins) do
if type(skin) == "table" then
local skinObj = {
name = skin.name or "",
sprite = skin.sprite or "",
tooltip = skin.tooltip or "",
offset_x = skin.offset_x,
tile = skin.tile or "",
tile_x = skin.tile_x,
tile_y = skin.tile_y,
youtube = skin.youtube
}
-- Se tooltip é table, converte para JSON string
if type(skin.tooltip) == "table" then
skinObj.tooltip = mw.text.jsonEncode(skin.tooltip)
end
table.insert(skinsArr, skinObj)
end
end
return mw.text.jsonEncode(skinsArr)
end
return p