Module:Réactions

Version datée du 14 mai 2026 à 00:35 par Kims (discussion | contributions)
(diff) ← Version précédente | Version actuelle (diff) | Version suivante → (diff)
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 Joseph MacCready (Fallout 4)|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]]",
}

_NO_REACTION = "[[Fichier:Icon_cross.png|sans_cadre|15px|alt=Pas de réaction|link=|Pas de réaction]]"

function build_header()
	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(_NPC) 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)
	local event = args['événement'] or ''
	local row = '<tr><td>' .. event .. '</td>'
	for i, v in ipairs(_NPC) do
		local npc_reaction = args[v]
		local cell
		if npc_reaction then
			cell = _REACTIONS[npc_reaction] or npc_reaction
		else
			cell = _NO_REACTION
		end
		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 return build_header()
	elseif row_type == 'ligne' then return build_row(args)
	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