« Module:Réactions » : différence entre les versions

Kims (discussion | contributions)
Correction pour que le module n'appel que les compagnons appelés
Kims (discussion | contributions)
Aucun résumé des modifications
Ligne 18 : Ligne 18 :
'longfellow',
'longfellow',
'gage',
'gage',
}
_NPC_LABELS = {
['cait']      = '[[Cait]]',
['codsworth']  = '[[Codsworth]]',
['curie']      = '[[Curie]]',
['danse']      = '[[Danse]]',
['deacon']    = '[[Deacon]]',
['hancock']    = '[[John Hancock|Hancock]]',
['maccready']  = '[[Robert MacCready|MacCready]]',
['piper']      = '[[Piper Wright|Piper]]',
['preston']    = '[[Preston Garvey|Preston]]',
['strong']    = '[[Strong]]',
['valentine']  = '[[Nick Valentine|Valentine]]',
['x688']      = '[[X6-88]]',
['longfellow'] = '[[Vieux Longfellow|Longfellow]]',
['gage']      = '[[Porter Gage|Gage]]',
}
}


_REACTIONS = {
_REACTIONS = {
["adore"] = "[[Fichier:Adore.png|sans_cadre|15px|alt=Adore|link=|Adore]]",
["adore"]       = "[[Fichier:Adore.png|sans_cadre|15px|alt=Adore|link=|Adore]]",
["aime"] = "[[Fichier:Aime.png|sans_cadre|15px|alt=Aime|link=|Aime]]",
["aime"]       = "[[Fichier:Aime.png|sans_cadre|15px|alt=Aime|link=|Aime]]",
["indifférent"] = "[[Fichier:Indifférent.png|sans_cadre|15px|alt=Indifférent|link=|Indifférent]]",
["indifférent"] = "[[Fichier:Indifférent.png|sans_cadre|15px|alt=Indifférent|link=|Indifférent]]",
["aimepas"] = "[[Fichier:AimePas.png|sans_cadre|15px|alt=N'aime pas|link=|N'aime pas]]",
["aimepas"]     = "[[Fichier:AimePas.png|sans_cadre|15px|alt=N'aime pas|link=|N'aime pas]]",
["déteste"] = "[[Fichier:Déteste.png|sans_cadre|15px|alt=Déteste|link=|Déteste]]",
["déteste"]     = "[[Fichier:Déteste.png|sans_cadre|15px|alt=Déteste|link=|Déteste]]",
}
}


function build_header()
-- Retourne la liste ordonnée des compagnons présents dans args
function get_present_npcs(args)
local present = {}
for i, v in ipairs(_NPC) do
if args[v] then
table.insert(present, v)
end
end
return present
end
 
function build_header(present_npcs)
local header = {
local header = {
'<table class="va-table va-table-left-col1 va-table-center va-table-full va-table-narrow">',
'<table class="va-table va-table-left-col1 va-table-center va-table-full va-table-narrow">',
'<tr>',
'<tr>',
'<th class="" style="width:30%">Évènement</th>',
'<th class="" style="width:30%">Évènement</th>',
'<th style="width:5%">[[Cait]]</th>',
'<th style="width:5%">[[Codsworth]]</th>',
'<th style="width:5%">[[Curie]]</th>',
'<th style="width:5%">[[Danse]]</th>',
'<th style="width:5%">[[Deacon]]</th>',
'<th style="width:5%">[[John Hancock|Hancock]]</th>',
'<th style="width:5%">[[Robert MacCready|MacCready]]</th>',
'<th style="width:5%">[[Piper Wright|Piper]]</th>',
'<th style="width:5%">[[Preston Garvey|Preston]]</th>',
'<th style="width:5%">[[Strong]]</th>',
'<th style="width:5%">[[Nick Valentine|Valentine]]</th>',
'<th style="width:5%">[[X6-88]]</th>',
'<th style="width:5%">[[Vieux Longfellow|Longfellow]]</th>',
'<th style="width:5%">[[Porter Gage|Gage]]</th>',
'</tr>',
}
}
for i, v in ipairs(present_npcs) do
table.insert(header, '<th style="width:5%">' .. _NPC_LABELS[v] .. '</th>')
end
table.insert(header, '</tr>')
return table.concat(header, "")
return table.concat(header, "")
end
end
Ligne 56 : Ligne 73 :
end
end


function build_row(args)
function build_row(args, present_npcs)
local event = args['événement'] or ''
local event = args['événement'] or ''
local row = '<tr><td>' .. event .. '</td>'
local row = '<tr><td>' .. event .. '</td>'
for i, v in ipairs(_NPC) do
for i, v in ipairs(present_npcs) do
local npc_reaction = args[v]
local npc_reaction = args[v]
local cell
local cell = _REACTIONS[npc_reaction] or npc_reaction
if npc_reaction then
cell = _REACTIONS[npc_reaction] or npc_reaction
else
cell = ''
end
row = row .. '<td>' .. cell .. '</td>'
row = row .. '<td>' .. cell .. '</td>'
end
end
Ligne 80 : Ligne 92 :
val = mw.text.trim(val)
val = mw.text.trim(val)
if val ~= '' then
if val ~= '' then
args[cle] = mw.text.trim(val)
args[cle] = val
end
end
end
end
end
end
 
local row_type = args[1] or ''
local row_type = args[1] or ''
 
if row_type == 'début' then return build_header()
if row_type == 'début' then
elseif row_type == 'ligne' then return build_row(args)
-- On stocke la liste des compagnons présents dans une frame partagée
elseif row_type == 'fin'   then return build_footer()
-- via les args du cadre parent pour les lignes suivantes
else error("Paramètre 1 non reconnu. Attendu : début, ligne ou fin.") end
local present_npcs = get_present_npcs(args)
-- Fallback : si 'début' n'a pas de compagnons (cas normal),
-- on génère un header vide qui sera complété par les lignes
return build_header(present_npcs)
elseif row_type == 'ligne' then
local present_npcs = get_present_npcs(args)
return build_row(args, present_npcs)
elseif row_type == 'fin' then
return build_footer()
else
error("Paramètre 1 non reconnu. Attendu : début, ligne ou fin.")
end
end
end


return p
return p

Version du 14 mai 2026 à 00:16

Documentation du module

Ce module génère le contenu du modèle {{Réactions}}.

Documentation transclues de Module:Réactions/doc.
local p = {}

local tooltip = require( 'Module:Infobulle' )

_NPC = {
	'cait',
	'codsworth',
	'curie',
	'danse',
	'deacon',
	'hancock',
	'maccready',
	'piper',
	'preston',
	'strong',
	'valentine',
	'x688',
	'longfellow',
	'gage',
}

_NPC_LABELS = {
	['cait']       = '[[Cait]]',
	['codsworth']  = '[[Codsworth]]',
	['curie']      = '[[Curie]]',
	['danse']      = '[[Danse]]',
	['deacon']     = '[[Deacon]]',
	['hancock']    = '[[John Hancock|Hancock]]',
	['maccready']  = '[[Robert MacCready|MacCready]]',
	['piper']      = '[[Piper Wright|Piper]]',
	['preston']    = '[[Preston Garvey|Preston]]',
	['strong']     = '[[Strong]]',
	['valentine']  = '[[Nick Valentine|Valentine]]',
	['x688']       = '[[X6-88]]',
	['longfellow'] = '[[Vieux Longfellow|Longfellow]]',
	['gage']       = '[[Porter Gage|Gage]]',
}

_REACTIONS = {
	["adore"]       = "[[Fichier:Adore.png|sans_cadre|15px|alt=Adore|link=|Adore]]",
	["aime"]        = "[[Fichier:Aime.png|sans_cadre|15px|alt=Aime|link=|Aime]]",
	["indifférent"] = "[[Fichier:Indifférent.png|sans_cadre|15px|alt=Indifférent|link=|Indifférent]]",
	["aimepas"]     = "[[Fichier:AimePas.png|sans_cadre|15px|alt=N'aime pas|link=|N'aime pas]]",
	["déteste"]     = "[[Fichier:Déteste.png|sans_cadre|15px|alt=Déteste|link=|Déteste]]",
}

-- Retourne la liste ordonnée des compagnons présents dans args
function get_present_npcs(args)
	local present = {}
	for i, v in ipairs(_NPC) do
		if args[v] then
			table.insert(present, v)
		end
	end
	return present
end

function build_header(present_npcs)
	local header = {
		'<table class="va-table va-table-left-col1 va-table-center va-table-full va-table-narrow">',
		'<tr>',
		'<th class="" style="width:30%">Évènement</th>',
	}
	for i, v in ipairs(present_npcs) do
		table.insert(header, '<th style="width:5%">' .. _NPC_LABELS[v] .. '</th>')
	end
	table.insert(header, '</tr>')
	return table.concat(header, "")
end

function build_footer()
	return '</table>'
end

function build_row(args, present_npcs)
	local event = args['événement'] or ''
	local row = '<tr><td>' .. event .. '</td>'
	for i, v in ipairs(present_npcs) do
		local npc_reaction = args[v]
		local cell = _REACTIONS[npc_reaction] or npc_reaction
		row = row .. '<td>' .. cell .. '</td>'
	end
	row = row .. '</tr>'
	return row
end

function p.build(frame)
	local args = {}
	local args_parent = frame:getParent().args
	for cle, val in pairs(args_parent) do
		if val then
			val = mw.text.trim(val)
			if val ~= '' then
				args[cle] = val
			end
		end
	end

	local row_type = args[1] or ''

	if row_type == 'début' then
		-- On stocke la liste des compagnons présents dans une frame partagée
		-- via les args du cadre parent pour les lignes suivantes
		local present_npcs = get_present_npcs(args)
		-- Fallback : si 'début' n'a pas de compagnons (cas normal),
		-- on génère un header vide qui sera complété par les lignes
		return build_header(present_npcs)
	elseif row_type == 'ligne' then
		local present_npcs = get_present_npcs(args)
		return build_row(args, present_npcs)
	elseif row_type == 'fin' then
		return build_footer()
	else
		error("Paramètre 1 non reconnu. Attendu : début, ligne ou fin.")
	end
end

return p