« Module:Fermentation » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 1 : | Ligne 1 : | ||
local p = {} | local p = {} | ||
local OUI = 'oui' | |||
local LF = '\n' | local LF = '\n' | ||
-------------------------------- | ------------------------------------------------ | ||
----- Référentiel | ----- Référentiel des interactions ----- | ||
-------------------------------- | ------------------------------------------------ | ||
local data = { | local data = { | ||
["fermentable"] = { }, | -- Interaction spéciale si aucune autre, ne pas toucher -------- | ||
["fermenté"] = {}, | ["aucune"] = { | ||
["mature"] = {} | image = "Neutral test color.png", | ||
description = "Ce personnage ne possède pas d'interaction particulière." | |||
}, | |||
---------------------------------------------------------------- | |||
["fermentable"] = { | |||
checkIfYes = false, | |||
image = "Deep Sleep.png", | |||
description = function(args) | |||
return "Ce personnage loue un lit à " .. args["lit"] .. " [[capsule]]s la nuit." | |||
end | |||
}, | |||
["fermenté"] = { | |||
checkIfYes = true, | |||
image = "Radiated.png", | |||
description = "Ce personnage souffre de la [[Nouvelle Peste]]." | |||
}, | |||
["mature"] = { | |||
checkIfYes = true, | |||
image = "OpticsEnhancer.png", | |||
description = "Ce personnage possède une [[tête parlante]]." | |||
} | |||
} | } | ||
-------------------------------- | ------------------------------------------------ | ||
function buildRow( | function buildRow(args, def) | ||
local note = | local note = def.note | ||
if note | if note then | ||
if type(note) == 'function' then | |||
return | note = note(args) | ||
end | |||
end | |||
return mw.html.create( 'li' ) | |||
:addClass( 'avt-interactions-row' ) | |||
:node(image) | |||
:tag( 'div' ) | :tag( 'div' ) | ||
:addClass( ' | :addClass( 'avt-interactions-text' ) | ||
: | :node(description) | ||
: | :node(note) | ||
:done() | :done() | ||
end | |||
function p._build(args) | function p._build(args) | ||
local res = mw.html.create( 'ul' ) | local res = mw.html.create( 'ul' ) | ||
:addClass( 'avt-interactions' ) | :addClass( 'avt-interactions' ) | ||
for | -- on trie les arguments par ordre alphabétique | ||
local keys = {} | |||
for k, v in pairs(args) do | |||
table.insert(keys, k) | |||
end | |||
table.sort(keys) | |||
local isEmpty = true | |||
for i, key in ipairs(keys) do | |||
argValue = args[key] | |||
local def = data[key:lower()] | local def = data[key:lower()] | ||
if def and | if def and (not def.checkIfYes or argValue:lower() == OUI) and argValue ~= '-' then | ||
isEmpty = false | isEmpty = false | ||
res:node(buildRow( | res:node(buildRow(args, def)) | ||
end | end | ||
end | |||
-- cas particulier le pnj n'a aucune interaction | |||
if isEmpty then | |||
res:node(buildRow(args, data.aucune)) | |||
end | end | ||
Ligne 56 : | Ligne 94 : | ||
val = mw.text.trim(val) | val = mw.text.trim(val) | ||
if val ~= '' then | if val ~= '' then | ||
args[cle] = val | args[cle] = mw.text.trim(val) | ||
end | end | ||
end | end |
Version du 19 juillet 2021 à 17:10
La documentation pour ce module peut être créée à Module:Fermentation/doc
local p = {}
local OUI = 'oui'
local LF = '\n'
------------------------------------------------
----- Référentiel des interactions -----
------------------------------------------------
local data = {
-- Interaction spéciale si aucune autre, ne pas toucher --------
["aucune"] = {
image = "Neutral test color.png",
description = "Ce personnage ne possède pas d'interaction particulière."
},
----------------------------------------------------------------
["fermentable"] = {
checkIfYes = false,
image = "Deep Sleep.png",
description = function(args)
return "Ce personnage loue un lit à " .. args["lit"] .. " [[capsule]]s la nuit."
end
},
["fermenté"] = {
checkIfYes = true,
image = "Radiated.png",
description = "Ce personnage souffre de la [[Nouvelle Peste]]."
},
["mature"] = {
checkIfYes = true,
image = "OpticsEnhancer.png",
description = "Ce personnage possède une [[tête parlante]]."
}
}
------------------------------------------------
function buildRow(args, def)
local note = def.note
if note then
if type(note) == 'function' then
note = note(args)
end
end
return mw.html.create( 'li' )
:addClass( 'avt-interactions-row' )
:node(image)
:tag( 'div' )
:addClass( 'avt-interactions-text' )
:node(description)
:node(note)
:done()
end
function p._build(args)
local res = mw.html.create( 'ul' )
:addClass( 'avt-interactions' )
-- on trie les arguments par ordre alphabétique
local keys = {}
for k, v in pairs(args) do
table.insert(keys, k)
end
table.sort(keys)
local isEmpty = true
for i, key in ipairs(keys) do
argValue = args[key]
local def = data[key:lower()]
if def and (not def.checkIfYes or argValue:lower() == OUI) and argValue ~= '-' then
isEmpty = false
res:node(buildRow(args, def))
end
end
-- cas particulier le pnj n'a aucune interaction
if isEmpty then
res:node(buildRow(args, data.aucune))
end
res:allDone()
return res
end
function p.build(frame)
local args = {}
local argsParent = frame:getParent().args
for cle, val in pairs(argsParent) do
if val then
val = mw.text.trim(val)
if val ~= '' then
args[cle] = mw.text.trim(val)
end
end
end
return p._build(args)
end
return p