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

Kharmitch (discussion | contributions)
Aucun résumé des modifications
Kims (discussion | contributions)
Aucun résumé des modifications
 
(8 versions intermédiaires par le même utilisateur non affichées)
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 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 = {
_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]]",
}
}
_NO_REACTION = "[[Fichier:Icon_cross.png|sans_cadre|15px|alt=Pas de réaction|link=|Pas de réaction]]"


function build_header()
function build_header()
Ligne 33 : Ligne 52 :
'<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(_NPC) 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 60 : Ligne 68 :
local row = '<tr><td>' .. event .. '</td>'
local row = '<tr><td>' .. event .. '</td>'
for i, v in ipairs(_NPC) do
for i, v in ipairs(_NPC) do
npc_reaction = args[v] or 'indifférent'
local npc_reaction = args[v]
reaction = _REACTIONS[npc_reaction] or npc_reaction
local cell
row = row .. '<td>' .. reaction .. '</td>'
if npc_reaction then
cell = _REACTIONS[npc_reaction] or npc_reaction
else
cell = _NO_REACTION
end
row = row .. '<td>' .. cell .. '</td>'
end
end
row = row .. '</tr>'
row = row .. '</tr>'
Ligne 75 : Ligne 88 :
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 return build_header()
elseif row_type == 'ligne' then return build_row(args)
elseif row_type == 'ligne' then return build_row(args)

Dernière version du 14 mai 2026 à 00:35

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