Diferencia entre revisiones de «Módulo:Iconbar»
Ir a la navegación
Ir a la búsqueda
m Protegió «Módulo:Iconbar» ([Editar=Solo permitir administradores] (indefinido) [Pueden trasladar=Solo permitir administradores] (indefinido)) |
importado>ImportMC Actualización: Añade parámetros link y alt y clase pixel-image |
||
| Línea 1: | Línea 1: | ||
local p = {} | local p = {} | ||
function p.bar( f ) | function p.bar( f ) | ||
local args = require( ' | local args = require( 'Módulo:ProcessArgs' ).merge() | ||
local alt = args.alt or '' | |||
local link = args.link or '' | |||
local full = args.full | local full = args.full | ||
local half = args.half or 'Half ' .. full | local half = args.half or 'Half ' .. full | ||
| Línea 18: | Línea 20: | ||
title = ' title="' .. value .. '"' | title = ' title="' .. value .. '"' | ||
end | end | ||
local fullIcon = '' | local fullIcon = '' | ||
local halfIcon = '' | local halfIcon = '' | ||
| Línea 30: | Línea 32: | ||
if value == 0 then | if value == 0 then | ||
emptyIcon = '[[File:' .. empty .. size .. ']]' | emptyIcon = '[[File:' .. empty .. size .. '|link=' .. link .. '|alt=' .. alt .. ']]' | ||
else | else | ||
fullIcon = string.rep( '[[File:' .. full .. size .. ']]', math.floor( value ) ) | fullIcon = string.rep( '[[File:' .. full .. size .. '|link=' .. link .. '|alt=' .. alt .. ']]', math.floor( value ) ) | ||
if math.floor( value ) ~= value then | if math.floor( value ) ~= value then | ||
halfIcon = '[[File:' .. half .. size .. ']]' | halfIcon = '[[File:' .. half .. size .. '|link=' .. link .. '|alt=' .. alt .. ']]' | ||
end | end | ||
end | end | ||
if min - value >= 1 then | if min - value >= 1 then | ||
emptyIcon = string.rep( '[[File:' .. empty .. size .. ']]', min - math.ceil( value ) ) | emptyIcon = string.rep( '[[File:' .. empty .. size .. '|link=' .. link .. '|alt=' .. alt .. ']]', min - math.ceil( value ) ) | ||
end | end | ||
if reverse ~= '' then | if reverse ~= '' then | ||
return '<span class="nowrap"' .. title .. '>' .. emptyIcon .. halfIcon .. fullIcon .. '</span>' | return '<span class="pixel-image nowrap"' .. title .. '>' .. emptyIcon .. halfIcon .. fullIcon .. '</span>' | ||
else | else | ||
return '<span class="nowrap"' .. title .. '>' .. fullIcon .. halfIcon .. emptyIcon .. '</span>' | return '<span class="pixel-image nowrap"' .. title .. '>' .. fullIcon .. halfIcon .. emptyIcon .. '</span>' | ||
end | end | ||
end | end | ||
return p | return p | ||
Revisión actual - 12:00 8 nov 2026
Uso
Este módulo dibuja barras de iconos (corazones, muslos de comida, armadura…) a partir de un valor numérico. Se invoca desde la página de cada plantilla con {{#invoke:Iconbar|bar}}, sin pasar por la plantilla Iconbar.
Los parámetros de la plantilla que llama se combinan con los de la invocación, y estos últimos tienen prioridad. Desde esta versión se admiten además los parámetros link y alt para el enlace y el texto alternativo de cada icono.
Dependencias
local p = {}
function p.bar( f )
local args = require( 'Módulo:ProcessArgs' ).merge()
local alt = args.alt or ''
local link = args.link or ''
local full = args.full
local half = args.half or 'Half ' .. full
local empty = args.empty or 'Empty ' .. full
local value = math.abs( tonumber( args.value ) or 0 ) / 2
local min = math.ceil( math.abs( tonumber( args.min ) or 0 ) / 2 )
local size = args.size or ''
local title = args.title or ''
local reverse = args.reverse or ''
if title:lower() == 'none' then
title = ''
elseif title ~= '' then
title = ' title="' .. title .. '"'
else
title = ' title="' .. value .. '"'
end
local fullIcon = ''
local halfIcon = ''
local emptyIcon = ''
if tonumber( size ) then
size = '|' .. size .. 'px'
elseif size ~= '' then
size = '|' .. size
end
if value == 0 then
emptyIcon = '[[File:' .. empty .. size .. '|link=' .. link .. '|alt=' .. alt .. ']]'
else
fullIcon = string.rep( '[[File:' .. full .. size .. '|link=' .. link .. '|alt=' .. alt .. ']]', math.floor( value ) )
if math.floor( value ) ~= value then
halfIcon = '[[File:' .. half .. size .. '|link=' .. link .. '|alt=' .. alt .. ']]'
end
end
if min - value >= 1 then
emptyIcon = string.rep( '[[File:' .. empty .. size .. '|link=' .. link .. '|alt=' .. alt .. ']]', min - math.ceil( value ) )
end
if reverse ~= '' then
return '<span class="pixel-image nowrap"' .. title .. '>' .. emptyIcon .. halfIcon .. fullIcon .. '</span>'
else
return '<span class="pixel-image nowrap"' .. title .. '>' .. fullIcon .. halfIcon .. emptyIcon .. '</span>'
end
end
return p