Module:Sound table/Sandbox

local p = {} local emptyevent = [=[None ]=] local nosubtitle = [=[None ]=]

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 = [=[]=] 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 then tableheader = [=[ ]=] id = id:gsub( '%.', ' .') 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 = [=[ ]=] translationkey = translationkey:gsub( '%.', ' .') 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 .. [=[ ]=] .. parent:expandTemplate{ title = 'notelist', args = { 'sound' } } vardefine( parent, 'tabletype', '' ) end return tostring( result ) end return p