Module:Gear

De Inkipédia
Révision datée du 4 mai 2024 à 20:53 par Fxfxfx0 (discussion | contributions) (Copie du Module:Gear)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

Affiche l'icône d'un équipement avec un lien textuel.

Utilisation

{{Gear|<jeu>|<catégorie>|<nom>|<taille>|<icononly>}}

Paramètres

Paramètre Type Statut Description
jeu Nommé ou non nommé (première position) Optionnel, par défaut S Le jeu auquel appartient l'article. Doit être l'un des suivants :
  • S pour Splatoon
  • S2 pour Splatoon 2
  • S3 pour Splatoon 3
catégorie Nommé ou non nommé (deuxième position) Optionnel, par défaut Headgear Le type d'équipement en anglais. Doit être l'un des suivants :
  • Headgear
  • Clothing
  • Shoes
nom Nommé ou non nommé (troisième position) Optionnel, par défaut White Headband Le nom en anglais de l'article.
taille Nommé ou non nommé (quatrième position) Optionnel La largeur en pixels de l'icône. La taille par défaut est de 24px.
icononly Nommé ou non nommé (quatrième ou cinquième position) Optionnel Si présent, le texte sera omis.
mio Nommé seulement Optionnel Pour remplacer manuellement l'icône par un nom de fichier différent. Ce paramètre est particulièrement utile lorsqu'une icône manque et nécessite un remplacement temporaire. 'mio' signifie manual icon override.

Exemples

Entrée

* {{Gear}}
* {{Gear|S|Clothing|Basic Tee}}
* {{Gear|S2|Clothing|Basic Tee|64}}
* {{Gear|S3|Clothing|Basic Tee|200px}}
* {{Gear|S|Clothing|Basic Tee|64|icone-seule}}
* {{Gear|S|Clothing|Basic Tee|icone-seule}}
* {{Gear|S2|Clothing|Basic Tee|64|icone-seule}}
* {{Gear|S|Shoes|Cream Basics|256|mio=S2 Gear Shoes Cream Basics.png}}

Sortie


local p = {}
p.main = function (frame)
    -- Calculate the game parameter
    -- It's the first positional, or in the parameter named 'game'
    -- If game is not specified a default of S will be used
    local game = frame:getParent().args['game'] or frame:getParent().args[1] or 'S'
    
    -- Calculate the category parameter
    -- It's the second positional, or in the parameter named 'category'
    -- If category is not specified a default of Headgear will be used
    local category = frame:getParent().args['category'] or frame:getParent().args[2] or 'Headgear'
    
    -- Calculate the name parameter
    -- It's the third positional, or in the parameter named 'name'
    -- If name is not specified a default of White Headband will be used
    local name = frame:getParent().args['name'] or frame:getParent().args[3] or 'White Headband'
    
    -- Calculate the size
    -- It's the fourth positional if specified, or in the parameter named 'size'
    -- If size is not specified a default of 24px will be used
    local size = frame:getParent().args['size'] or frame:getParent().args[4]
    if size then
	    if tonumber(size) then
	        size = string.format("%dpx", tonumber(size))
	    else
	        -- size is already a string, let's assume it's correct
	        -- unless ofc we think the size is "icononly"
	        -- (from icononly as 4th positional without a named size param)
	        if size == "icononly" then
	        	size = "24px" -- Default value
	        end
	    end
	else
	    size = "24px" -- Default value
	end

    -- Calculate if icononly
    -- It's the fourth or fifth positional if specified, or if a parameter named 'icononly' has value
    local icononly = frame:getParent().args['icononly'] or frame:getParent().args[4] == "icononly" or frame:getParent().args[5] == "icononly"
    
    -- Calculate manual image override 'mio'
    -- Named optional only
    local mio = frame:getParent().args['mio']
    
    -- Put it all together
    local alt = icononly and name or ''
    local result = "[[File:" .. (mio or (game .. "_Gear_" .. category .. "_" .. name .. ".png")) .. "|" .. size .. "|link=" .. name .. "|alt=" .. alt .."]]"
    if not icononly then
    	result = result .. "&#32;[[" .. name .. "]]"
    end

    return result
end

return p