This module implements {{Sound table}}
.
Usage[]
This module should not be invoked; {{Sound table}}
should be called. See template documentation for more information.
[view | edit | history | purge]The above documentation is transcluded from Module:Sound table/doc.
local p = {}
local emptyevent = [=[''None''<ref group="sound" name="emptyevent">Empty events do not have this parameter set.</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 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 = [=[[[Category:Pages missing ]=] .. 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 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.type=='bedrock' then
vardefine( parent, 'bedrock', 1 )
bedrock = true
vardefine( parent, 'tabletype', 'Bedrock' )
elseif args.dungeons or args.type=='dungeons' then
vardefine( parent, 'dungeons', 1 )
dungeons = true
vardefine( parent, 'tabletype', 'Dungeons' )
elseif args.legends or args.type=='legends' then
vardefine( parent, 'legends', 1 )
legends = true
vardefine( parent, 'tabletype', 'Legends' )
elseif args.historical or args.type=='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 = { 'Sound' }
if java then -- Subtitles
table.insert( headings, '[[Subtitles]]' )
--elseif legends then
-- table.insert( headings, '[[Legends:Subtitles|Subtitles]]' )
end
if not ( dungeons or legends ) then
local sourceheading = parent:expandTemplate{ title = 'tooltip', args = { 'Source', 'The category this sound falls into; what volume slider controls this sound in the Music and Sounds menu.' } }
table.insert( headings, sourceheading )
end
local descriptionheading = parent:expandTemplate{ title = 'tooltip', args = { 'Description', 'When the game calls this sound event.' } }
table.insert( headings, descriptionheading )
if not ( dungeons or legends ) then
table.insert( headings, '[[Resource location]]')
end
if java then
table.insert( headings, 'Translation key' )
end
if not ( dungeons or legends ) then
table.insert( headings, 'Volume' )
table.insert( headings, 'Pitch' )
end
if not ( bedrock or dungeons or legends ) then
table.insert( headings, 'Attenuation<br>distance' )
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.rowspan then
vardefine( parent, 'rowspancooldown', tonumber( args.rowspan ) )
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.rowspan or var( parent, 'rowspancooldown' ) == nil or tonumber( var( parent, 'rowspancooldown' ) ) <= 0 then
local sound = ''
if args.sound == '-' then
sound = [=[''None'']=]
elseif args.sound == nil then
sound = addCategory( nocat, '?', 'sounds' )
else
local sounds = { args.sound }
for count = 2, 20 do
local index = 'sound' .. 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\">[[File:".. soundarg .."|class=sound-audio]]</span></span>"
end
end
table.insert( cells, sound )
table.insert( rowspans, args.rowspan )
end
if java then
local subtitle = args.subtitle
if args.subtitle == '-' then
subtitle = parent:preprocess( nosubtitle )
elseif args.sound == '-' and args.subtitle == nil then
subtitle = parent:preprocess( emptyevent )
elseif args.translationkey == '-' then
local content = parent:expandTemplate{ title = 'bug', args = { args.subtitle } }
subtitle = [=[''None'']=] .. parent:extensionTag( 'ref', content, { group = 'sound', name = 'bug' .. args.subtitle } )
elseif args.subtitle ~= nil then
subtitle = args.subtitle
else
subtitle = addCategory( nocat, '?', 'subtitles' )
end
table.insert( cells, subtitle )
table.insert( rowspans, 1 )
end
if not ( dungeons or legends ) then
local source = addCategory( nocat, '?', 'sound source' )
if args.overridesource then
source = args.source
elseif args.source == 'Master Volume' or args.source == 'master' then
source = 'Master Volume'
elseif args.source == 'Music' or args.source == 'music' then
source = 'Music'
elseif args.source == 'Jukebox/Note Blocks' or args.source == 'record' then
source = 'Jukebox/Note Blocks'
elseif args.source == 'Weather' or args.source == 'weather' then
source = 'Weather'
elseif args.source == 'Hostile Creatures' or args.source == 'hostile' then
source = 'Hostile Creatures'
elseif args.source == 'Friendly Creatures' or args.source == 'neutral' then
source = 'Friendly Creatures'
elseif args.source == 'Players' or args.source == 'player' then
source = 'Players'
elseif args.source == 'Blocks' or args.source == 'block' then
source = 'Blocks'
elseif args.source == 'Ambient/Environment' or args.source == 'ambient' then
source = 'Ambient/Environment'
elseif args.source == 'Voice/Speech' or args.source == 'voice' then
source = 'Voice/Speech'
elseif args.source == 'Sound' or args.source == 'sound' then
source = 'Sound'
elseif args.source == 'Entity-Dependent' or args.source == 'dependent' then
source = "''Entity-Dependent''"
elseif args.source == 'None' or args.source == 'none' or args.source == '-' then
source = "''None''"
end
table.insert( cells, source )
table.insert( rowspans, 1 )
end
local desc = args.description or addCategory( nocat, '?', 'sound description' )
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, '?', 'sound 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.sound == '-' and args.translationkey == nil 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 = [=[''None'']=] .. parent:extensionTag( 'ref', content, { group = 'sound', name = 'bug' .. args.subtitle } )
elseif args.translationkey == "''None''" or args.translationkey == "None" then
translationkey = [=[''None'']=]
elseif args.translationkey ~= nil then
translationkey = [=[<code>]=] .. args.translationkey .. [=[</code>]=]
translationkey = translationkey:gsub( '%.', '<wbr/>.')
else
translationkey = addCategory( nocat, '?', 'subtitle key' )
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.volume or addCategory( nocat, '?', 'sound volume' ) )
table.insert( rowspans, 1 )
table.insert( cells, args.pitch or addCategory( nocat, '?', 'sound pitch' ) )
table.insert( rowspans, 1 )
end
if not ( bedrock or dungeons or legends ) then
table.insert( cells, args.distance or addCategory( nocat, '?', 'sound attenuation distance' ) )
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.foot 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>[[Category:Pages with sound tables]][[Category:Pages with ]=] .. var( parent, 'tabletype' ) .. [=[ sound tables]]]=] .. parent:expandTemplate{ title = 'notelist', args = { 'sound' } }
vardefine( parent, 'tabletype', '' )
end
return tostring( result )
end
return p