Module:Inventaire

De Les Archives de Vault-Tec

La documentation pour ce module peut être créée à Module:Inventaire/doc

local p = {}

local LF = '\n'

--------------------------------
-----     Référentiel      ----- 
--------------------------------

local data = {
	["armes"] = {
		image        = "Master of the Arsenal.png",
		description  = "Ce personnage possède des armes."
	},
	["vêtements"] = {
		image        = "30 Reilly's Rangers.png",
		description  = "Ce personnage possède des vêtements."
	},
	["autres objets"] = {
		image        = "You Run Barter Town.png",
		description  = "Ce personnage possède des objets divers."
	},
	["sur mort"] = {
		image        = "26 You Gotta Shoot 'Em in the Head.png",
		description  = "Les objets suivants sont uniquement disponibles sur son cadavre."
	},
	["vide"] = {
		image        = "Neutral test color.png",
		description  = "L'inventaire de ce personnage est vide."
	}
}

--------------------------------

function buildRow(argValue, def)
	local note = argValue or ''
	if note ~= '' then note = LF .. note .. LF end
	
	return mw.html.create( 'li' )
		:addClass( 'avt-interactions-row' )
		:tag( 'div' )
			:addClass( 'avt-interactions-img' )
			:wikitext( '[[Fichier:'..def.image..'|x50px|alt=|link=]]' )
			:done()
		:tag( 'div' )
			:addClass( 'avt-interactions-text' )
			:tag( 'p' )
				:wikitext(def.description)
				:done()
			:wikitext( note )
			:done()
		:done()
end

function p._build(args)
	local res = mw.html.create( 'ul' )
		:addClass( 'avt-interactions' )
	
	local isEmpty = true
	
	for key, value in pairs(args) do
		local def = data[key:lower()]
		if def and value ~= '-' and value ~= 'vide' then
			isEmpty = false
			res:node(buildRow(value, def))
		end
	end
	
	-- cas particulier l'inventaire du pnj est vide
	if isEmpty then
		res:node(buildRow(nil, data.vide))
	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] = val
			end
		end
	end
	
	return p._build(args)
end

return p