Minecraft Wiki
Advertisement
[створити | історія | оновити]Документація
У цього модуля немає документації. Якщо ви знаєте, як використовувати цей модуль, будь ласка, додайте відповідну інформацію.
local p = {}
local emptyevent = [=[''Немає''<ref group="звук" name="emptyevent">Порожні події не мають цього параметра.</ref>]=]
local nosubtitle = [=[''Немає''<ref group="звук" 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 curNs = mw.title.getCurrentTitle().namespace
local function addCategory( nocat, value, categoryName )
	if (curNs == 0) or (curNs == 10) or (curNs == 10000) or (curNs == 10002) or (curNs == 10004) and (not nocat) then
		local category = [=[[[Категорія:Сторінки з відсутніми ]=] .. categoryName .. [=[]]]=]
		
		value = value .. category
	end
	
	return value
end

function p.table( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'Модуль: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['некат'] then
			vardefine( parent, 'nocat', 1 )
		end
		local java = false
		local bedrock = false
		local historical = false
		local dungeons = false
		local legends = false
		vardefine( parent, 'java', '' )
		vardefine( parent, 'bedrock', '' )
		vardefine( parent, 'historical', '' )
		vardefine( parent, 'dungeons', '' )
		vardefine( parent, 'legends', '' )
		if args.bedrock or args['тип']=='bedrock' then
			vardefine( parent, 'bedrock', 1 )
			bedrock = true
			vardefine( parent, 'tabletype', 'Bedrock' )
		elseif args.dungeons or args['тип']=='dungeons' then
			vardefine( parent, 'dungeons', 1 )
			dungeons = true
			vardefine( parent, 'tabletype', 'Dungeons' )
		elseif args.legends or args['тип']=='legends' then
			vardefine( parent, 'legends', 1 )
			legends = true
			vardefine( parent, 'tabletype', 'Legends' )
		elseif args.historical or args['тип']=='historical' then
			vardefine( parent, 'historical', 1 )
			historical = true
			vardefine( parent, 'tabletype', 'historical' )
		else
			vardefine( parent, 'java', 1 )
			java = true
			vardefine( parent, 'tabletype', 'Java' )
		end
		if legends or args.forcecollapsed then
			tableheader = [=[<table class="wikitable mw-collapsible mw-collapsed">]=]
		else
			tableheader = [=[<table class="wikitable mw-collapsible mw-expanded">]=]
		end
		result = result .. tableheader
		local headerrow = mw.html.create( 'tr' )
		local headings = { 'Звук' }

		if java then -- Subtitles
			table.insert( headings, '[[Субтитри]]' )
		--elseif legends then
		--	table.insert( headings, '[[Legends:Subtitles|Subtitles]]' )
		end
		if not ( dungeons or legends ) then
			local sourceheading = parent:expandTemplate{ title = 'Сплтекст', args = { 'Джерело', 'Категорія, до якої належить цей звук; який повзунок гучності відповідає за ций звук у меню «Музика та звуки».' } }
			table.insert( headings, sourceheading )
		end
		local descriptionheading = parent:expandTemplate{ title = 'Сплтекст', args = { 'Опис', 'Коли гра викликає це звукову подію.' } }
		table.insert( headings, descriptionheading )
		if not ( dungeons or legends ) then
            table.insert( headings, '[[Розташування ресурсу]]')
        end
		if java then
			table.insert( headings, 'Ключ перекладу' )
		end
		if not ( dungeons or legends ) then
			table.insert( headings, 'Гучність' )
			table.insert( headings, 'Висота звуку' )
		end
		if not ( bedrock or dungeons or legends ) then
			table.insert( headings, 'Відстань<br>загасання' )
		end
		
		for i, header in ipairs( headings ) do
			headerrow
				:tag( 'th' )
				:wikitext( header ) 
		end
		
		result = result .. tostring( headerrow )
	end
	if var( parent, 'rowspancooldown' ) and tonumber( var( parent, 'rowspancooldown' ) ) > 0 then
		vardefine( parent, 'rowspancooldown', var( parent, 'rowspancooldown' ) - 1 )
	end
	if args['рядки'] then
		vardefine( parent, 'rowspancooldown', tonumber( args['рядки'] ) )
	end
	-- Header variables
	local nocat = var( parent, 'nocat' )
	local java = var( parent, 'java' )
	local bedrock = var( parent, 'bedrock' )
	local dungeons = var( parent, 'dungeons' )
	local legends = var( parent, 'legends' )
	local historical = var( parent, 'historical' )
	
	local cells = {}
	local rowspans = {}
	
	if args['рядки'] or var( parent, 'rowspancooldown' ) == nil or tonumber( var( parent, 'rowspancooldown' ) ) <= 0 then
		local sound = ''
		if args['звук'] == '-' then
			sound = [=[''Немає'']=]
		elseif args['звук'] == nil then
			sound = addCategory( nocat, '?', 'звуками' )
		else
			local sounds = { args['звук'] }
			for count = 2, 20 do
				local index = 'звук' .. count
				if args[index] then
					table.insert( sounds, args[index] )
				end
			end
			
			-- Use html instead of {{sound}} to avoid the #while in the template
			for i, soundarg in ipairs( sounds ) do
				sound = sound .. "<span class=\"sound\"><span class=\"sound-title\"></span><span style=\"display:none\">[[Файл:".. soundarg .."|class=sound-audio]]</span></span>"
			end
		end
		table.insert( cells, sound )
		table.insert( rowspans, args['рядки'] )
	end
	
	if java then
		local subtitle = args['субтитри']
		if args['субтитри'] == '-' then
			subtitle = parent:preprocess( nosubtitle )
		elseif args['звук'] == '-' and args['субтитри'] == nil then
			subtitle = parent:preprocess( emptyevent )
		elseif args['ключперекладу'] == '-' then
			local content = parent:expandTemplate{ title = 'помилка', args = { args['субтитри'] } }
			subtitle = [=[''Немає'']=] .. parent:extensionTag( 'ref', content, { group = 'звук', name = 'помилка' .. args['субтитри'] } )
		elseif args['субтитри'] ~= nil then
			subtitle = args['субтитри']
		else
			subtitle = addCategory( nocat, '?', 'субтитрами' )
		end
		table.insert( cells, subtitle )
		table.insert( rowspans, 1 )
	end
	
	if not ( dungeons or legends ) then
		local source = addCategory( nocat, '?', 'джерелами звуку' )
		if args['перевизначитиджерело'] then
			source = args['джерело']
		elseif args['джерело'] == 'Загальна гучність' or args['джерело'] == 'загальне' then
			source = 'Загальна гучність'
		elseif args['джерело'] == 'Музика' or args['джерело'] == 'музика' then
			source = 'Музика'
		elseif args['джерело'] == 'Програвач, нотні блоки' or args['джерело'] == 'платівка' then
			source = 'Програвач, нотні блоки'
		elseif args['джерело'] == 'Погода' or args['джерело'] == 'погода' then
			source = 'Погода'
		elseif args['джерело'] == 'Ворожі істоти' or args['джерело'] == 'ворожі' then
			source = 'Ворожі істоти'
		elseif args['джерело'] == 'Дружні істоти' or args['джерело'] == 'нейтральні' then
			source = 'Дружні істоти'
		elseif args['джерело'] == 'Гравці' or args['джерело'] == 'гравець' then
			source = 'Гравці'
		elseif args['джерело'] == 'Блоки' or args['джерело'] == 'блок' then
			source = 'Блоки'
		elseif args['джерело'] == 'Середовище' or args['джерело'] == 'середовище' then
			source = 'Середовище'
		elseif args['джерело'] == 'Голос, мовлення' or args['джерело'] == 'голос' then
			source = 'Голос, мовлення'
		elseif args['джерело'] == 'Звук' or args['джерело'] == 'звук' then
			source = 'Звук'
		elseif args['джерело'] == 'Сутнісно-залежний' or args['джерело'] == 'залежний' then
			source = "''Сутнісно-залежний''"
		elseif args['джерело'] == 'Немає' or args['джерело'] == 'немає' or args['джерело'] == '-' then
			source = "''Немає''"
		end
        table.insert( cells, source )
        table.insert( rowspans, 1 )
	end

	local desc = args['опис'] or addCategory( nocat, '?', 'описами звуку' )
	table.insert( cells, desc )
	table.insert( rowspans, 1 )
	
    if not ( dungeons or legends ) then
	    local id
	    if args.id then
	    	id = [=[<code>]=] .. args.id .. [=[</code>]=]
	    	id = id:gsub( '%.', '<wbr/>.')
	    else
	    	id = addCategory( nocat, '?', 'значеннями звукових ID' )
	    end
	    if args.idnote then
	    	id = id .. args.idnote
	    end
	    table.insert( cells, id )
	    table.insert( rowspans, 1 )
    end
	
	if java then
		local translationkey
		if args['звук'] == '-' and args['ключперекладу'] == nil then
			translationkey = parent:preprocess( emptyevent )
		elseif args['субтитри'] == '-' then
			translationkey = parent:preprocess( nosubtitle )
		elseif args['ключперекладу'] == '-' then
			local content = parent:expandTemplate{ title = 'помилка', args = { args['субтитри'] } }
			translationkey = [=[''Немає'']=] .. parent:extensionTag( 'ref', content, { group = 'звук', name = 'помилка' .. args['субтитри'] } )
		elseif args['ключперекладу'] == "''Немає''" or args['ключперекладу'] == "Немає" then
			translationkey = [=[''Немає'']=]
		elseif args['ключперекладу'] ~= nil then
			translationkey = [=[<code>]=] .. args['ключперекладу'] .. [=[</code>]=]
			translationkey = translationkey:gsub( '%.', '<wbr/>.')
		else
			translationkey = addCategory( nocat, '?', 'ключами перекладу' )
		end
		if args.translationkeynote then
			translationkey = translationkey .. args.translationkeynote
		end
		table.insert( cells, translationkey )
		table.insert( rowspans, 1 )
	end
	
	if not ( dungeons or legends ) then
		table.insert( cells, args['гучність'] or addCategory( nocat, '?', 'значеннями гучності звуку' ) )
		table.insert( rowspans, 1 )
		table.insert( cells, args['висотазвуку'] or addCategory( nocat, '?', 'значеннями висоти звуку' ) )
		table.insert( rowspans, 1 )
	end
	if not ( bedrock or dungeons or legends ) then
		table.insert( cells, args['відстань'] or addCategory( nocat, '?', 'значеннями відстані загасання звуку' ) )
		table.insert( rowspans, 1 )
	end
	
	local row = mw.html.create( 'tr' )
	for i, cell in ipairs( cells ) do
		row
			:tag( 'td' )
			:attr( 'rowspan', rowspans[i] )
			:wikitext( cell ) 
	end
	result = result .. tostring( row )
	
	if args['підвал'] then
		-- Reset the variables we used
		vardefine( parent, 'soundstable', '' )
		vardefine( parent, 'nocat', '' )
		vardefine( parent, 'bedrock', '' )
		vardefine( parent, 'dungeons', '' )
		vardefine( parent, 'historical', '' )
		vardefine( parent, 'rowspancooldown', 0 )
		
		-- Add table ending
		result = result .. [=[</table>[[Категорія:Сторінки зі звуковими таблицями]][[Категорія:Сторінки зі звуковими таблицями ]=] .. var( parent, 'tabletype' ) .. [=[]]]=] .. parent:expandTemplate{ title = 'нотатки', args = { 'звук' } }
		vardefine( parent, 'tabletype', '' )
	end
	
	return tostring( result )
end
return p
Advertisement