Liste les objets ou les créatures en les précédant de leur icône.
Attend chaque objet ou créature comme paramètre. Une quantité x
, x..y
, ou x-y
peut être utilisée comme paramètre suivant.
Paramètres
Paramètre | Par défaut | Description |
---|---|---|
iconsize | 30px | taille de l'icône |
columns | 1 | nombre de colonnes |
columnWidth | 15em | largeur de chaque colonne |
listtype | choisir 'ol' pour une liste numérotée, 'none' pour une liste sans boulets | |
showQuantityOne | false | régler sur true montre aussi '1 ×' si la quantité '1' est donnée
|
showQuantityAsPerCent | false | régler sur true pour monter par ex. '50%' si la quantité 0.5 est donnée
|
Utilisation/Exemples
{{ItemList|Ankylosaure|Branchages}}
{{ItemList|iconsize=50px|Argentavis|Quetzal|Ptéranodon}}
{{ItemList|iconsize=20px|columns=2|Branchages|Bois|Viande crue supérieure|Dodo|Mésopithèque|Porte en bois}}
{{ItemList|iconsize=20px|columnWidth=20em|Branchages|Bois|Viande crue supérieure|Dodo|Mésopithèque|Porte en bois}}
{{ItemList|listtype=ol|Baies|Carotte|Maïs}}
{{ItemList|listtype=none|Baies|Soufre (Scorched Earth)|Argile (Primitive Plus)}}
{{ItemList|Ankylosaure|1|Branchages|10..20}}
- Ankylosaure
- 10..20 × Branchages
{{ItemList|showQuantityOne=true|Ankylosaure|1|Branchages|10-20}}
- 1 × Ankylosaure
- 10-20 × Branchages
{{ItemList|showQuantityAsPerCent=true|Marmite suspendue|1|Forge|0.5}}
- 100% Marmite suspendue
- 50% Forge
Affiche une liste séparée par des virgules depuis une liste de données:
{{ItemList|columnWidth=20em|{{Dv|Ptéranodon|canDragCreatures}}}}
La documentation ci-dessus est transcluse de Module:ItemList/doc. (modifier | historique)
local p = {}
local DLCLink = require('Module:DLCLink').link
function p.itemlist( f )
local args = f:getParent().args
local listType = 'ul'
local extraStyle = ''
local delimiter = args.delimiter or ','
local noDlcIcon = args.noDlcIcon or false
if noDlcIcon and ( noDlcIcon == '' or noDlcIcon == 0) then -- lua evaluates anything to true except nil and false
noDlcIcon = false
end
if args.columns ~= nil then
extraStyle = extraStyle..'column-count:'..args.columns..';'
end
if args.columnWidth ~= nil then
extraStyle = extraStyle..'column-width:'..args.columnWidth..';'
end
if args.noMargin ~= nil then
extraStyle = extraStyle..'margin:0;'
end
if args.marginLeft ~= nil then
extraStyle = extraStyle..'margin-left:'..args.marginLeft..';'
end
if args.listtype ~= nil then
if args.listtype == 'ol' then
listType = 'ol'
else -- none
extraStyle = extraStyle..'list-style:none;margin-left:0;'
end
end
-- split first value at comma, e.g. for data from module:dv
local items = {}
for v in mw.text.gsplit(args[1], delimiter, true) do
if #v > 0 then -- skip empty
table.insert(items, v)
end
end
-- append rest parameters
for _,v in ipairs(args) do
if _ > 1 and #v > 0 then
table.insert(items, v)
end
end
-- prepend mod wiki namespace to items if "mod" argument is specified
if args.mod ~= nil then
for i, v in ipairs(items) do
items[i] = "Mod:"..args.mod.."/"..v
end
end
-- read arguments list into itemList (consists of tables, at index 1 is the text, at index 2 the quantity (optional))
local itemList, i, lastItem = {}, 0, nil
for _, item in ipairs(items) do
item = item:match "^%s*(.-)%s*$" -- trim
if string.len(item) > 0 then
if lastItem and (item:match "^[%d.]*$" or item:match "^[%d.]*%-[%d.]*$") then
itemList[i][2] = item -- item is quantity
lastItem = nil
else
table.insert(itemList, {item, nil} ) -- item is text
i = i + 1
lastItem = item
end
end
end
return p.create(itemList, {
listType = listType,
extraStyle = extraStyle,
iconSize = args.iconsize,
asPerCent = args.showQuantityAsPerCent or false,
showOne = args.showQuantityOne or false,
noDlcIcon = noDlcIcon,
})
end
function p.create(items, options)
options = options or {}
local output = {}
local quantitySign = options.asPerCent and '% ' or ' × '
local iconSize = options.iconSize or '30px'
for _, item in ipairs(items) do
local name, qty = item, nil
if type(item) == 'table' then
name, qty = item[1], item[2]
end
if options.asPerCent and qty ~= nil then
qty = qty * 100
end
local fileName = string.gsub(string.gsub(name, '[:/]', ' '), '+', '-')
output[#output+1] = '<li>'
if qty ~= nil and (qty ~= '1' or options.showOne) then
output[#output+1] = qty..quantitySign
end
output[#output+1] = '[[File:'..fileName..'.png|'..iconSize..'|link='..name..'|alt=]] '
output[#output+1] = DLCLink(name, options.noDlcIcon)
output[#output+1] = '</li>'
end
if #output == 0 then
return nil
end
-- if the list is long and has no explicit style, break it into columns automatically
if #output > 5 and (options.extraStyle == '' or options.extraStyle == nil) then
options.extraStyle = 'column-width:15em;'
end
local listType = options.listType or 'ul'
return '<'..listType..(options.extraStyle ~= '' and ' style="'..options.extraStyle..'"' or '')
..' class="itemlist">'..table.concat(output, '')..'</'..listType..'>'
end
return p