Module:Réactions
Ce module génère le contenu du modèle {{Réactions}}.
local p = {}
local tooltip = require( 'Module:Infobulle' )
_NPC = {
'cait',
'codsworth',
'curie',
'danse',
'deacon',
'hancock',
'maccready',
'piper',
'preston',
'strong',
'valentine',
'x688',
'longfellow',
'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]]",
}
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>',
'<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>',
}
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
npc_reaction = args[v] or 'indifférent'
reaction = _REACTIONS[npc_reaction] or npc_reaction
row = row .. '<td>' .. reaction .. '</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] = mw.text.trim(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