« Module:Réactions » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 45 : | Ligne 45 : | ||
} | } | ||
function get_present_npcs(args) | function get_present_npcs(args) | ||
local present = {} | local present = {} | ||
| Ligne 53 : | Ligne 51 : | ||
table.insert(present, v) | table.insert(present, v) | ||
end | end | ||
end | |||
return present | |||
end | |||
-- Lit les compagnons depuis les args positionnels 2, 3, 4... | |||
function get_npcs_from_positional(args) | |||
local present = {} | |||
local i = 2 | |||
while args[i] do | |||
local npc = mw.text.trim(args[i]) | |||
if _NPC_LABELS[npc] then | |||
table.insert(present, npc) | |||
end | |||
i = i + 1 | |||
end | end | ||
return present | return present | ||
| Ligne 79 : | Ligne 91 : | ||
for i, v in ipairs(present_npcs) do | for i, v in ipairs(present_npcs) do | ||
local npc_reaction = args[v] | local npc_reaction = args[v] | ||
local cell = _REACTIONS[npc_reaction] or npc_reaction | local cell | ||
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 101 : | Ligne 118 : | ||
if row_type == 'début' then | if row_type == 'début' then | ||
local present_npcs = | local present_npcs = get_npcs_from_positional(args) | ||
return build_header(present_npcs) | return build_header(present_npcs) | ||
elseif row_type == 'ligne' then | elseif row_type == 'ligne' then | ||
Version du 14 mai 2026 à 00:18
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',
}
_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]]",
}
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
-- Lit les compagnons depuis les args positionnels 2, 3, 4...
function get_npcs_from_positional(args)
local present = {}
local i = 2
while args[i] do
local npc = mw.text.trim(args[i])
if _NPC_LABELS[npc] then
table.insert(present, npc)
end
i = i + 1
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
if npc_reaction then
cell = _REACTIONS[npc_reaction] or npc_reaction
else
cell = ''
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
local present_npcs = get_npcs_from_positional(args)
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