« Module:Fermentation » : différence entre les versions

De Les Archives de Vault-Tec
Kims (discussion | contributions)
Aucun résumé des modifications
Kims (discussion | contributions)
Aucun résumé des modifications
 
(51 versions intermédiaires par le même utilisateur non affichées)
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"] = {
["fermentable"] = {
image        = "Master of the Arsenal.png",
description  = function(args)
description  = "Ce personnage possède des armes."
return "Version fermentable :  "
},
.. args["fermentable"]
["fermenté"] = {
.. "."
image        = "30 Reilly's Rangers.png",
end
description  = "Ce personnage possède des vêtements."
},
},
["fermenté"] = {
description  = function(args)
return "Version fermenté :  "
.. args["fermenté"]
.. "."
end
}, 
["mature"] = {
["mature"] = {
image        = "You Run Barter Town.png",
description  = function(args)
description  = "Ce personnage possède des objets divers."
return "Version mature :  "
},
.. args["mature"]
["vide"] = {
.. "."
image        = "Neutral test color.png",
end
description  = "L'inventaire de ce personnage est vide."
}
}
}
}


--------------------------------
------------------------------------------------
 
function buildRow(args, def)
function buildRow(argValue, def)
local description = def.description
local note = argValue or ''
if type(def.description) == 'function' then
if note ~= '' then note = LF .. note .. LF end
description = description(args)
end
description = mw.html.create( 'p' )
:wikitext( description )
:done()
local note = def.note
if note then
if type(note) == 'function' then
note = note(args)
end
end
return mw.html.create( 'li' )
return mw.html.create( 'li' )
:addClass( 'avt-interactions-row' )
:addClass( 'avt-interactions-row' )
:tag( 'div' )
:node(description)
:addClass( 'avt-interactions-img' )
:node(note)
:wikitext( '[[Fichier:'..def.image..'|x50px|alt=|link=]]' )
:done()
:tag( 'div' )
:addClass( 'avt-interactions-text' )
:tag( 'p' )
:wikitext(def.description)
:done()
:wikitext( note )
:done()
:tag( 'li' )
:wikitext( '[[Fichier:Icon_range_inverse.png|x50px|center]]' )
:done()
:done()
end
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' )
local isEmpty = true
for key, value in pairs(args) do
-- 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 value ~= '-' and value ~= 'vide' then
if def and (not def.checkIfYes or argValue:lower() == OUI) and argValue ~= '-' then
isEmpty = false
isEmpty = false
res:node(buildRow(value, def))
res:node(buildRow(args, def))
end
end
end
-- cas particulier l'inventaire du pnj est vide
if isEmpty then
res:node(buildRow(nil, data.vide))
end
end
Ligne 81 : Ligne 91 :
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

Dernière version du 19 juillet 2021 à 18:06

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 = {
	["fermentable"] = {
			description  = function(args)
			return "Version fermentable :  "
				.. args["fermentable"]
				.. "."
		end	
	},
	["fermenté"] = {			
			description  = function(args)
			return "Version fermenté :  "
				.. args["fermenté"]
				.. "."
		end	
	},   
	["mature"] = {
					description  = function(args)
			return "Version mature :  "
				.. args["mature"]
				.. "."
		end	
	}
}

------------------------------------------------
function buildRow(args, def)
		local description = def.description
	if type(def.description) == 'function' then
		description = description(args)
	end
	description = mw.html.create( 'p' )
		:wikitext( description )
		:done()
	
	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(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
	
	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