Advertisement

Ce module implémente {{Tableau de son}}.

[voir | modifier | historique | purger]La documentation ci-dessus est insérée depuis Module:Tableau de son/doc.
local p = {}
local emptyevent = [=[''None''<ref group="sound" name="emptyevent">Ce paramètre n'est pas défini pour les évènements vides.</ref>]=]
local nosubtitle = [=[''None''<ref group="sound" name="nosubtitle">[https://bugs.mojang.com/issues/?jql=project%20%3D%20MC%20AND%20resolution%20%3D%20Unresolved%20AND%20text%20~%20%22sound%20missing%22 Reports on Mojira].</ref>]=]

local function vardefine( f, name, value )
	f:callParserFunction( '#vardefine', name, value )
end

local function var( f, name, defaultvalue )
	local result = f:callParserFunction( '#var', name, defaultvalue )
	if result == '' then
		return nil
	end
	return result
end

local function addCategory( nocat, value, categoryName )
	if not nocat then
		local category = [=[[[Catégorie:Paramètre de son manquant ]=] .. categoryName .. [=[]]]=]
		
		value = value .. category
	end
	
	return value
end

function p.table( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'Module:ProcessArgs' ).norm()
	else
		f = mw.getCurrentFrame()
	end
	local parent = f:getParent() or f
	local result = ''
	
	if not var( parent, 'soundstable' ) then
		vardefine( parent, 'soundstable', 1 )
		if args.nocat then
			vardefine( parent, 'nocat', 1 )
		end
		local bedrockordungeons = false
			local bedrock = false
		local dungeons = false
		if args.bedrock or args.type=='bedrock' then
			vardefine( parent, 'bedrock', 1 )
			bedrockordungeons = true
			bedrock = true
			vardefine( parent, 'bedrockordungeons', 1 )
		end
		if args.dungeons or args.type=='dungeons' then
			vardefine( parent, 'dungeons', 1 )
			bedrockordungeons = true
			dungeons = true
			vardefine( parent, 'bedrockordungeons', 1 )
		end
		result = result .. [=[<table class="wikitable">]=]
		local headerrow = mw.html.create( 'tr' )
		local headings = { 'Son' }
		
		if not bedrockordungeons then
			table.insert( headings, '[[Sous-titres|Sous-titre]]' )
		end
		if not dungeons then
			local sourceheading = parent:expandTemplate{ title = 'abbr', args = { 'Source', 'La catégorie à laquelle appartient ce son; quel bouton contrôle ce son dans le menu Musique & sons.' } }
			table.insert( headings, sourceheading )
		end
		
		if not dungeons then
            table.insert( headings, "Espace de nom d'ID")
        end
		if not bedrockordungeons then
			table.insert( headings, 'Clef de traduction' )
		end
		if not dungeons then
			table.insert( headings, 'Volume' )
			table.insert( headings, 'Pitch' )
		end
		if not bedrockordungeons then
			table.insert( headings, "Distance<br>d'atténuation" )
		end
		
		for i, header in ipairs( headings ) do
			headerrow
				:tag( 'th' )
				:wikitext( header ) 
		end
		
		result = result .. tostring( headerrow )
	end
	
	-- Header variables
	local nocat = var( parent, 'nocat' )
	local bedrockordungeons = var( parent, 'bedrockordungeons' )
	local bedrock = var( parent, 'bedrock' )
	local dungeons = var( parent, 'dungeons' )
	
	local cells = {}
	
	local sound = ''
	if args.sound == '-' then
		sound =  [=['Aucun']=]
	elseif args.sound == nil then
		sound = addCategory( nocat, '?', 'sons' )
	else
		-- First parameter is empty because we don't want a sound name
		local sounds = { '', args.sound }
		for count = 2, 20 do
			local index = 'sound' .. count
			if args[index] then
				table.insert( sounds, args[index] )
			end
		end
		
		sound = parent:expandTemplate{ title = 'Son', args = sounds }
	end
	table.insert( cells, sound )
	
	if not bedrockordungeons then
		local subtitle = args.subtitle
		if args.subtitle == '-' then
			subtitle = parent:preprocess( nosubtitle )
		elseif args.sound == '-' then
			subtitle = parent:preprocess( emptyevent )
		elseif args.translationkey == '-' then
			local content = parent:expandTemplate{ title = 'bug', args = { args.subtitle } }
			subtitle = [=[''Aucun'']=] .. parent:extensionTag( 'ref', content, { group = 'son', name = 'bug' .. args.subtitle } )
		elseif args.subtitle ~= nil then
			subtitle = args.subtitle
		else
			subtitle = addCategory( nocat, '?', 'sous-titres' )
		end
		table.insert( cells, subtitle )
	end
	
	if not dungeons then
		local source = args.source or addCategory( nocat, '?', 'source du son' )
		table.insert( cells, source )
	end

	
if not dungeons then
	    local id
	    if args.id then
	    	id = [=[<code style="white-space: nowrap">]=] .. args.id .. [=[</code>]=]
	    else
	    	id = addCategory( nocat, '?', 'ID du son' )
	    end
	    table.insert( cells, id )
    end
	
	if not bedrockordungeons then
		local translationkey
		if args.sound == '-' then
			translationkey = parent:preprocess( emptyevent )
		elseif args.subtitle == '-' then
			translationkey = parent:preprocess( nosubtitle )
		elseif args.translationkey == '-' then
			local content = parent:expandTemplate{ title = 'bug', args = { args.subtitle } }
			translationkey = [=[''Aucune'']=] .. parent:extensionTag( 'ref', content, { group = 'son', name = 'bug' .. args.subtitle } )
		elseif args.translationkey ~= nil then
			translationkey = [=[<code style="white-space: nowrap">]=] .. args.translationkey .. [=[</code>]=]
		else
			translationkey = addCategory( nocat, '?', 'clef de traduction' )
		end
		table.insert( cells, translationkey )
	end
	
	if not dungeons then
		table.insert( cells, args.volume or addCategory( nocat, '?', 'volume du son' ) )
		table.insert( cells, args.pitch or addCategory( nocat, '?', 'pitch du son' ) )
	end
	if not bedrockordungeons then
		table.insert( cells, args.distance or addCategory( nocat, '?', "distance d'atténuation du son" ) )
	end
	
	local row = mw.html.create( 'tr' )
	for i, cell in ipairs( cells ) do
		row
			:tag( 'td' )
			:wikitext( cell ) 
	end
	result = result .. tostring( row )
	
	if args.foot then
		-- Reset the variables we used
		vardefine(parent, 'soundstable', '')
		vardefine(parent, 'nocat', '')
		vardefine(parent, 'bedrock', '')
		vardefine(parent, 'dungeons', '')
		vardefine(parent, 'bedrockordungeons', '')
		
		-- Add table ending
		result = result .. [=[</table>]=] .. parent:expandTemplate{ title = 'Liste de notes', args = { 'son' } }
	end
	
	return tostring( result )
end
return p

EN SAVOIR PLUS