« Module:IconUtils » : différence entre les versions
De Eco - Wiki Français
| [version vérifiée] | [version vérifiée] |
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 3 : | Ligne 3 : | ||
function p.main(param) | function p.main(param) | ||
local Utils = require('Module:Utils') | local Utils = require('Module:Utils') | ||
local ItemData = require('Module:ItemData') or {} | |||
local | |||
local args = Utils.normalise(param) | local args = Utils.normalise(param) | ||
if not args.id or args.id == '' then | |||
if args.id | |||
return "Module:IconUtils 'id' must be specified." | return "Module:IconUtils 'id' must be specified." | ||
end | end | ||
-- | local Icon = args.id .. "_Icon.png" | ||
local IconSize = args.size and args.size ~= '' and args.size or 28 | |||
local IconStyle = args.style and args.style ~= '' and args.style or '1' | |||
-- ========================== | |||
-- Récupération nom auto | |||
-- ========================== | |||
local name = args.name | local name = args.name | ||
local link = args.link | |||
local defaultLang = "French" | |||
if not name or name == '' then | if not name or name == '' or not link or link == '' then | ||
for _, item in pairs(ItemData) do | |||
if type(item) == "table" and item.ID == args.id and item.Name then | |||
local fr = item.Name[defaultLang] | |||
local en = item.Name['English'] | |||
if (not name or name == '') then | |||
if fr and fr ~= '' then | |||
name = fr | |||
elseif en and en ~= '' then | |||
name = en | |||
else | |||
name = args.id | |||
end | |||
end | |||
if (not link or link == '') then | |||
if fr and fr ~= '' then | |||
link = fr | |||
elseif en and en ~= '' then | |||
link = en | |||
else | |||
link = args.id | |||
end | |||
end | |||
end | |||
end | end | ||
end | end | ||
if not name or name == '' then name = args.id end | |||
if not link or link == '' then link = name end | |||
-- Construit le lien final | |||
if | local IconLink = '[[' .. link .. ']]' | ||
local IconTextLine = ' ' .. IconLink | |||
local IconTextBr = '<br>' .. IconLink | |||
if IconStyle == '1' then | |||
return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' | |||
elseif IconStyle == '2' then | |||
return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextLine | |||
elseif IconStyle == '3' then | |||
return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr | |||
elseif IconStyle == '4' then | |||
return '<div class="IconFrame">[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr .. '</div>' | |||
end | end | ||
end | end | ||
return p | return p | ||
Version du 16 novembre 2025 à 10:21
La documentation pour ce module peut être créée à Module:IconUtils/doc
local p = {}
function p.main(param)
local Utils = require('Module:Utils')
local ItemData = require('Module:ItemData') or {}
local args = Utils.normalise(param)
if not args.id or args.id == '' then
return "Module:IconUtils 'id' must be specified."
end
local Icon = args.id .. "_Icon.png"
local IconSize = args.size and args.size ~= '' and args.size or 28
local IconStyle = args.style and args.style ~= '' and args.style or '1'
-- ==========================
-- Récupération nom auto
-- ==========================
local name = args.name
local link = args.link
local defaultLang = "French"
if not name or name == '' or not link or link == '' then
for _, item in pairs(ItemData) do
if type(item) == "table" and item.ID == args.id and item.Name then
local fr = item.Name[defaultLang]
local en = item.Name['English']
if (not name or name == '') then
if fr and fr ~= '' then
name = fr
elseif en and en ~= '' then
name = en
else
name = args.id
end
end
if (not link or link == '') then
if fr and fr ~= '' then
link = fr
elseif en and en ~= '' then
link = en
else
link = args.id
end
end
end
end
end
if not name or name == '' then name = args.id end
if not link or link == '' then link = name end
-- Construit le lien final
local IconLink = '[[' .. link .. ']]'
local IconTextLine = ' ' .. IconLink
local IconTextBr = '<br>' .. IconLink
if IconStyle == '1' then
return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]'
elseif IconStyle == '2' then
return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextLine
elseif IconStyle == '3' then
return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr
elseif IconStyle == '4' then
return '<div class="IconFrame">[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr .. '</div>'
end
end
return p