« Module:Compétences » : différence entre les versions

De Starfield Wiki
Aucun résumé des modifications
Gestion des compétences inconnues
Ligne 1 : Ligne 1 :
local p = {}
local p = {}
local UNKNOWN_SKILL = "[[Catégorie:Compétence inconnue]]"


-- Merci de conserver le tri
-- Merci de conserver le tri
Ligne 44 : Ligne 46 :
-- L'utilisateur doit passer un tableau associatif des compétences qu'il
-- L'utilisateur doit passer un tableau associatif des compétences qu'il
-- veut afficher au format `{["nom_compétence"]="niveau_compétence"}`.
-- veut afficher au format `{["nom_compétence"]="niveau_compétence"}`.
-- La compétence est ignorée si elle n'existe pas.
-- Si l'utilisateur renseigne inconnue alors la fonction ajoute
-- Les compétences sont triées par rang décroissant.
-- la catégorie "Compétence inconnue".
function p._skills_list(args)
function p._skills_list(args)
local list = mw.html.create('ul')
local list = mw.html.create("ul")
local names = {}
local names = {}
for name, rank in pairs(args) do table.insert(names, name) end
for name, rank in pairs(args) do table.insert(names, name) end
table.sort(names, function(n1, n2) return args[n1] > args[n2] end)
table.sort(names, function(n1, n2) return args[n1] > args[n2] end)
local contains_unknown_skill = false
for _, name in ipairs(names) do
for _, name in ipairs(names) do
Ligne 61 : Ligne 65 :
:wikitext(text)
:wikitext(text)
:done()
:done()
else
contains_unknown_skill = true
end
end
end
end
Ligne 66 : Ligne 72 :
list:allDone()
list:allDone()
local wrapper = mw.html.create('div')
local wrapper = mw.html.create("div")
:addClass('liste-simple')
:addClass("liste-simple")
:node(list)
:node(list)
:done()
:done()
return tostring(wrapper)
local category = ""
if contains_unknown_skill then
category = UNKNOWN_SKILL
end
return tostring(wrapper) .. category
end
end



Version du 3 juillet 2023 à 09:03

Documentation[voir] [modifier] [purger]

Ce module implémente le modèle {{Compétences}}.

Ajouter une compétence

Il suffit d'ajouter la ligne suivante dans la table SKILLS.

["<nom_compétence_minuscule>"] = "<lien_page_compétence>",
  • <nom_compétence_minuscule> désigne le paramètre que doit entrer l'utilisateur pour utiliser cette compétence.
  • <lien_page_compétence> doit correspondre au nom de l'article associé à la compétence. Il est possible d'utiliser la barre verticale | pour afficher le lien différemment.

Merci d'aligner le symbole = avec les reste de lignes et de toujours trier les compétences dans l'ordre alphabétique.


local p = {}

local UNKNOWN_SKILL = "[[Catégorie:Compétence inconnue]]"

-- Merci de conserver le tri
-- TODO: Traduire les compétences une fois le jeu sorti
-- TODO: Faire évoluer cette liste pour prendre en charge les images de
--       chaque rang.
local SKILLS = {
	["astrodynamics"]                = "Astrodynamics",
	["astrophysics"]                 = "Astrophysics",
	["boost pack training"]          = "Boost pack training",
	["ballistics"]                   = "Ballistics",
	["botany"]                       = "Botany",
	["chemistry"]                    = "Chemistry",
	["decontamination"]              = "Decontamination",
	["gastronomy"]                   = "Gastronomy",
	["geology"]                      = "Geology",
	["instigation"]                  = "Instigation",
	["intimidation"]                 = "Intimidation",
	["lasers"]                       = "Lasers",
	["leadership"]                   = "Leadership",
	["marksmanship"]                 = "Marksmanship",
	["martial arts"]                 = "Martial arts",
	["missile weapon systems"]       = "Missile weapon systems",
	["negotiation"]                  = "Negotiation",
	["neurostrikes"]                 = "Neurostrikes",
	["outpost engineering"]          = "Outpost engineering",
	["outpost management"]           = "Outpost management",
	["particle beam weapon systems"] = "Particle beam weapon systems",
	["payloads"]                     = "Payloads",
	["piloting"]                     = "Piloting",
	["rapid reloading"]              = "Rapid reloading",
	["rifle certification"]          = "Rifle certification",
	["robotics"]                     = "Robotics",
	["security"]                     = "Security",
	["shotgun certification"]        = "Shotgun certification",
	["sniper certification"]         = "Sniper certification",
	["starship engineering"]         = "Starship engineering",
	["targeting"]                    = "Targeting",
	["xenosociology"]                = "Xenosociology",
}

-- Génère une liste des compétences avec leur niveau.
-- Fonction à appeler depuis un autre module
-- L'utilisateur doit passer un tableau associatif des compétences qu'il
-- veut afficher au format `{["nom_compétence"]="niveau_compétence"}`.
-- Si l'utilisateur renseigne inconnue alors la fonction ajoute
-- la catégorie "Compétence inconnue".
function p._skills_list(args)
	local list = mw.html.create("ul")
	
	local names = {}
	for name, rank in pairs(args) do table.insert(names, name) end
	table.sort(names, function(n1, n2) return args[n1] > args[n2] end)
	
	local contains_unknown_skill = false
	
	for _, name in ipairs(names) do
		link = SKILLS[name:lower()]
		if link then
			-- TODO: Améliorer le visuel
			text = "[[" .. link .. "]] ➡️ "  .. tostring(args[name])
			list:tag('li')
					:wikitext(text)
					:done()
		else
			contains_unknown_skill = true
		end
	end
	
	list:allDone()
	
	local wrapper = mw.html.create("div")
		:addClass("liste-simple")
		:node(list)
		:done()
	
	local category = ""
	if contains_unknown_skill then
		category = UNKNOWN_SKILL
	end
	
	return tostring(wrapper) .. category
end

-- Génère une liste des compétences avec leur niveau.
-- Fonction à appeler depuis un modèle
function p.skills_list(frame)
	local args = {}
	local argsParent = frame:getParent().args
	for cle, val in pairs(argsParent) do
		if val then
			args[cle] = mw.text.trim(val)
		end
	end
	return p._skills_list(args)
end

return p