![]() |
VOOZH | about |
This module implements {{SoundTable}}.
localp={} -- Raw variables localemptyevent=[=[''None''​<ref group="sound" name="emptyevent">Empty events do not have this parameter set.</ref>]=] localnosubtitle=[=[''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>]=] -- Variables localtypeHead=''-- args.type localheadConfig -- Rowspan autocalculation localrowspanIndex localrowspans -- Current namespace for categories localcurNs=mw.title.getCurrentTitle().namespace localnocat=false -- Add category localfunctionaddCategory(categoryName) if(typeHead=='java')or(typeHead=='bedrock')or(curNs==0)or(curNs==10)and(notnocat)then localeditionSuffix='' iftypeHead=='java'then editionSuffix='Java' elseiftypeHead=='bedrock'then editionSuffix='Bedrock' end return'[[Category:Pages with '..editionSuffix..' '..categoryName..' missing]]' elseif(typeHead~='java'andtypeHead~='bedrock')or(curNs==10000)or(curNs==10002)or(curNs==10004)or(curNs==10006)and(notnocat)then return'[[Category:Pages missing '..categoryName..']]' end return'' end -- Takes all args and puts them into a json string functionp.printArgs(frame) localargs=require('Module:ProcessArgs').norm(frame:getParent().args) args["errorCat"]="[[Category:Pages with broken sound tables]]"-- Add error category when {{SoundLine}} isn't wrapped by {{SoundTable}} returnmw.text.jsonEncode(args) end -- Deserialize the templates inside wrapper localfunctiondeserialize(args) locale localout={} fork,vinpairs(args)do e,out[k]=pcall(mw.text.jsonDecode,v) ifnotethen localerrorCat='' localerrorMsg=mw.message.new('scribunto-common-error-category') ifnoterrorMsg:isDisabled()then errorCat='[[Category:'..errorMsg:plain()..']]' end out[k]={description=v..' <strong class="error">Lua error: '..out[k]..errorCat..' Input:'..v..'</strong>'} end end returnout end -- Processes lines --[[ f - frame, access to parser for parsing stuff args - arguments/parameters prnt - the result string ]] localfunctionprocessLine(f,args,prnt) prnt('<tr>') ifargs.soundandheadConfig[1]==truethen localsound='' ifargs.sound=='-'then sound="''None''" elseifargs.sound==nilthen sound='?'..addCategory('sounds') else localsounds={args['sound']} forcount=2,20do localindex='sound'..count ifargs[index]then table.insert(sounds,args[index]) end end fori,soundarginipairs(sounds)do sound=sound.."<span class=\"sound\"><span class=\"sound-title\"></span>[[File:"..soundarg.."|class=sound-audio]]</span>" end end prnt('<td rowspan="') --.. rowspan .. rowspanIndex=rowspanIndex+1 ifrowspans[rowspanIndex]=='?'thenrowspans[rowspanIndex]=0end prnt((rowspans[rowspanIndex]or0)+1) prnt('">'..sound..'</td>') else rowspans[rowspanIndex]=rowspans[rowspanIndex]+1 end ifheadConfig[2]==truethen localsubtitle=args.subtitle ifsubtitle=='-'then subtitle=f:preprocess(nosubtitle) elseifargs.sound=='-'andsubtitle==nilthen subtitle=f:preprocess(emptyevent) elseifargs.translationkey=='-'then localcontent=f:expandTemplate{title='bug',args={args.subtitle}} subtitle="''None''"..'​'..f:extensionTag('ref','​'..content..'​',{group='sound',name='bug'..args.subtitle})..'​' elseifargs.subtitle~=nilthen subtitle='​'..args.subtitle else subtitle='​ ?'..addCategory('subtitles') end prnt('<td>'..tostring(subtitle)..'</td>') end ifheadConfig[3]==truethen localsource='?'..addCategory('sound source') ifargs.overridesourcethen source=args.source elseifargs.source=='master'orargs.source=='Master Volume'then source='Master Volume' elseifargs.source=='music'orargs.source=='Music'then source='Music' elseifargs.source=='record'orargs.source=='Jukebox/Note Blocks'then source='Jukebox/Note Blocks' elseifargs.source=='weather'orargs.source=='Weather'then source='Weather' elseifargs.source=='hostile'orargs.source=='Hostile Creatures'orargs.source=='Hostile Mobs'then source='Hostile Mobs' elseifargs.source=='neutral'orargs.source=='Friendly Creatures'orargs.source=='Friendly Mobs'then source='Friendly Mobs' elseifargs.source=='player'orargs.source=='Players'then source='Players' elseifargs.source=='block'orargs.source=='Blocks'then source='Blocks' elseifargs.source=='ambient'orargs.source=='Ambient/Environment'then source='Ambient/Environment' elseifargs.source=='voice'orargs.source=='Voice/Speech'then source='Voice/Speech' elseifargs.source=='ui'orargs.source=='UI'then source='UI' elseifargs.source=='sound'orargs.source=='Sound'then source='Sound' elseifargs.source=='dependent'orargs.source=='Entity-Dependent'then source="''[[Sound#Entity-dependent categories|Entity-Dependent]]''" elseifargs.source=='none'orargs.source=='-'then source="''None''" end prnt('<td>'..source..'</td>') end ifheadConfig[4]==truethen localdesc=args.descriptionor'?'..addCategory('sound description') prnt('<td>'..desc..'</td>') end ifheadConfig[5]==truethen localid ifargs.idthen id='<code>'..args.id..'</code>' id=id:gsub('%.','<wbr/>.') else id='?'..addCategory('sound ID') end ifargs.idnotethen id=id..'​'..args.idnote..'​' end prnt('<td>'..id..'</td>') end ifheadConfig[6]==truethen localtranslationkey ifargs.sound=='-'andargs.translationkey==nilthen translationkey=f:preprocess(emptyevent) elseifargs.subtitle=='-'then translationkey=f:preprocess(nosubtitle) elseifargs.translationkey=='-'then localcontent=f:expandTemplate{title='bug',args={args.subtitle}} translationkey="''None''"..'​'..f:extensionTag('ref','​'..content..'​',{group='sound',name='bug'..args.subtitle})..'​' elseifstring.lower(args.translationkeyor'')=="none"then translationkey="''None'' ​" elseifargs.translationkey~=nilthen translationkey='<code>'..args.translationkey..'</code>'..'​' translationkey=translationkey:gsub('%.','<wbr/>.') else translationkey='​ ?'..addCategory('subtitle key') end ifargs.translationkeynotethen translationkey=translationkey..'​'..args.translationkeynote..'​' end prnt('<td>'..translationkey..'</td>') end ifheadConfig[7]==truethen localvolume ifargs.volumethen volume=args.volume:gsub('(%d)%-(%d)','%1–%2') else volume='?'..addCategory('sound volume') end prnt('<td>'..volume..'</td>') end ifheadConfig[8]==truethen localpitch ifargs.pitchthen pitch=args.pitch:gsub('(%d)%-(%d)','%1–%2') else pitch='?'..addCategory('sound pitch') end prnt('<td>'..pitch..'</td>') end ifheadConfig[9]==truethen localdistance ifargs.distancethen distance=args.distance:gsub('(%d)%-(%d)','%1–%2') else distance='?'..addCategory('sound attenuation distance') end prnt('<td>'..distance..'</td>') end ifheadConfig[10]==truethen localdescriptivename=args.descriptivename ifargs.descriptivenamethen descriptivename=descriptivename:gsub('%_','<wbr/>_') else descriptivename='?'..addCategory('descriptive sound name') end prnt('<td>'..descriptivename..'</td>') end ifheadConfig[11]==truethen localguid=args.guid ifargs.guidthen guid='<code>'..args.guid..'</code>' guid=guid:gsub('%-','<wbr/>-') else guid='?'..addCategory('sound GUID') end prnt('<td>'..guid..'</td>') end ifheadConfig[12]==truethen localeventpath=args.eventpath ifargs.eventpaththen eventpath='<code>'..eventpath:gsub('%/','<wbr/>/')..'</code>' else eventpath='?'..addCategory('sound event path') end prnt('<td>'..eventpath..'</td>') end ifheadConfig[13]==truethen localfunctioncountBullets(x) localoutputReturn='' localbullets={args[x]} forcount=2,20do localindex=x..count ifargs[index]then table.insert(bullets,args[index]) end end fori,bulletarginipairs(bullets)do outputReturn=outputReturn..'<li><code>'..bulletarg..'</code></li>' end outputReturn='<ul>'..outputReturn..'</ul>' returnoutputReturn end localoneshot='' ifargs.oneshotthen oneshot=tostring(args.oneshot):lower() ifoneshot=='true'oroneshot=='1'then oneshot='True' elseifoneshot=='false'oroneshot=='0'then oneshot='False' end elseifargs.oneshottrue2then oneshot='\'\'\'True:\'\'\''..countBullets('oneshottrue')..'\'\'\'False:\'\'\''..countBullets('oneshotfalse') else oneshot='?'..addCategory('one-shot sound status') end oneshot=oneshot:gsub('%.','<wbr>.') prnt('<td>'..oneshot..'</td>') end ifheadConfig[14]==truethen localfunctioncountBullets(x) localoutputReturn='' localbullets={args[x]} forcount=2,20do localindex=x..count ifargs[index]then table.insert(bullets,args[index]) end end fori,bulletarginipairs(bullets)do outputReturn=outputReturn..'<li><code>'..bulletarg..'</code></li>' end outputReturn='<ul>'..outputReturn..'</ul>' returnoutputReturn end localstreaming='' ifargs.streamingthen streaming=tostring(args.streaming):lower() ifstreaming=='true'orstreaming=='1'then streaming='True' elseifstreaming=='false'orstreaming=='0'then streaming='False' end elseifargs.streamingtrue2then streaming='\'\'\'True:\'\'\''..countBullets('streamingtrue')..'\'\'\'False:\'\'\''..countBullets('streamingfalse') else streaming='?'..addCategory('streaming sound status') end streaming=streaming:gsub('%.','<wbr>.') prnt('<td>'..streaming..'</td>') end ifheadConfig[15]==truethen localfunctioncountBullets(x) localoutputReturn='' localbullets={args[x]} forcount=2,20do localindex=x..count ifargs[index]then table.insert(bullets,args[index]) end end fori,bulletarginipairs(bullets)do outputReturn=outputReturn..'<li><code>'..bulletarg..'</code></li>' end outputReturn='<ul>'..outputReturn..'</ul>' returnoutputReturn end localis3d='' ifargs.is3dthen is3d=tostring(args.is3d):lower() ifis3d=='true'oris3d=='1'then is3d='True' elseifis3d=='false'oris3d=='0'then is3d='False' end elseifargs.is3dtrue2then is3d='\'\'\'True:\'\'\''..countBullets('is3dtrue')..'\'\'\'False:\'\'\''..countBullets('is3dfalse') else is3d='?'..addCategory('3D sound status') end is3d=is3d:gsub('%.','<wbr>.') prnt('<td>'..is3d..'</td>') end ifheadConfig[16]==truethen localbank='' localfunctioncountBanks(x) localoutputReturn='' localbanks={args[x]} forcount=2,20do localindex=x..count ifargs[index]then table.insert(banks,args[index]) end end fori,bankarginipairs(banks)do outputReturn=outputReturn..'<li><code>'..bankarg:gsub('%_','<wbr/>_')..'</code></li>' end outputReturn='<ul>'..outputReturn..'</ul>' returnoutputReturn end ifargs.bankandargs.bank2then bank=countBanks('bank') elseifargs.bankandnotargs.bank2then bank='<code>'..args.bank..'</code>' elseifargs.season1bankthen bank='\'\'\'Season One:\'\'\'<br>'..countBanks('season1bank')..'<br>\'\'\'Season Two:\'\'\'<br>'..countBanks('season2bank') else bank='?'..addCategory('sound bank') end bank=bank:gsub('</code><code>','</code>, <code>') prnt('<td>'..bank..'</td>') end ifheadConfig[17]==truethen localseason=args.seasonor'?'..addCategory('seasons in sound table') prnt('<td>'..season..'</td>') end prnt('</tr>') end -- Count rowspan -- If argument isn't nil, then it moves rowspanIndex one up. If it is, it adds one to the final rowspan of that rowspan index localfunctioncountRowspan(args) ifargs.sound~=nilthen rowspanIndex=rowspanIndex+1 end ifargs.sound==nilthen rowspans[rowspanIndex]=(rowspans[rowspanIndex]or0)+1 end end -- Main function functionp.main(frame) returnp._main(frame,frame:getParent().args) end -- The dummy main function, do not call this one! functionp._main(f,args) locallines=deserialize(args) localresult={} ifargs.nocatandargs.nocat~=''thennocat=trueend rowspans={} rowspanIndex=0 for_,vinipairs(lines)do countRowspan(v) end rowspanIndex=0 typeHead=args['type']or'' local_collapse='' if(args['forcecollapsed']andargs['forcecollapsed']~='')or(typeHead=='legends'andnot(args['forceexpanded']andargs['forceexpanded']~=''))then_collapse='collapsed'end table.insert(result,'<table class="wikitable collapsible '.._collapse..'" data-description="Sound">') headConfig={}--[[ [1]: Include Sound? (bool) [2]: Include Subtitles? (bool) [3]: Include Source? (bool) [4]: Include Description? (bool) [5]: Include Identifier? (bool) [6]: Include Translation key? (bool) [7]: Include Volume? (bool) [8]: Include Pitch? (bool) [9]: Include Attenuation distance? (bool) [10]: Include Descriptive name? (bool) [11]: Include GUID? (bool) [12]: Include Event path? (bool) [13]: Include One-shot? (bool) [14]: Include Streaming? (bool) [15]: Include 3D? (bool) [16]: Include Sound bank? (bool) [17]: Include Season? (bool) ]] iftypeHead=='java'then headConfig={true,true,true,true,true,true,true,true,true,false,false,false,false,false,false,false,false} elseiftypeHead=='bedrock'then headConfig={true,true,true,true,true,true,true,true,false,false,false,false,false,false,false,false,false} elseiftypeHead=='dungeons'ortypeHead=='legends'ortypeHead=='earth'then headConfig={true,false,false,true,true,false,false,false,false,false,false,false,false,false,false} elseiftypeHead=='storymode'then headConfig={true,false,false,false,false,false,false,false,false,true,true,true,true,true,true,true,true} elseiftypeHead=='storymodemusic'then headConfig={false,false,false,false,false,false,false,false,false,true,true,true,true,true,true,true,true} elseiftypeHead=='historical'then headConfig={true,false,true,true,true,false,true,true,true,false,false,false,false,false,false,false,false} else-- Simple table.insert(result,'') headConfig={true,false,false,true,false,false,false,false,false,false,false,false,false,false,false,false,false} end localheaderrow=mw.html.create('tr') localcolspan=0 fori,headerinipairs(headConfig)do ifheader==truethen localh=headerrow:tag('th') colspan=colspan+1 -- the "switch" statement in Lua ifi==1then h:wikitext('Sound') elseifi==2andtypeHead=='bedrock'then h:wikitext("[[Closed captions]]") elseifi==2andtypeHead~='bedrock'then h:wikitext('[[Closed captions]]') elseifi==3then h:wikitext('<span class="explain" title="The category this sound falls into; what volume slider controls this sound in the Music and Sounds menu.">Source</span>') elseifi==4then h:wikitext('<span class="explain" title="When the game calls this sound event.">Description</span>') elseifi==5then h:wikitext('[[Identifier]]') elseifi==6andtypeHead=='bedrock'then h:wikitext("Translation key") elseifi==6andtypeHead~='bedrock'then h:wikitext('Translation key') elseifi==7then h:wikitext('Volume') elseifi==8then h:wikitext('Pitch') elseifi==9then h:wikitext('Attenuation<br/>distance') elseifi==10then h:wikitext('<span class="explain" title="The readable part of the audio file name.">Descriptive file name</span>') elseifi==11then h:wikitext('<span class="explain" title="The unique identifier (GUID) of the audio file. Some sounds include their GUIDs in the file names.">GUID</span>') elseifi==12then h:wikitext('<span class="explain" title="The FMOD event path used to trigger this sound in-game.">Event path</span>') elseifi==13then h:wikitext('<span class="explain" title="Whether the FMOD sound event plays only once and does not loop.">One-shot</span>') elseifi==14then h:wikitext('<span class="explain" title="Whether the FMOD sound is streamed from disk instead of being fully loaded into memory.">Streaming</span>') elseifi==15then h:wikitext('<span class="explain" title="Whether the FMOD sound is spatialized in 3D space.">3D</span>') elseifi==16then h:wikitext('<span class="explain" title="The FMOD sound bank(s) containing the audio.">Sound bank</span>') elseifi==17then h:wikitext('Season') end end end local_title=args['title']or'Sounds' local_navbar='' ifargs['templatepage']then_navbar='<div class="navbox-navbar">'..f:expandTemplate{title='Navbar',args={args['templatepage'],mini="1"}}..'</div>'end table.insert(result,'<tr><th colspan="'..colspan..'">'.._navbar.._title..'</th></tr>'..tostring(headerrow)..'</tr>') for_,vinipairs(lines)do processLine(f,v,function(a)table.insert(result,a)end) end localedition='' iftypeHead=='historical'ortypeHead=='simple'thenedition=typeHeadelseiftypeHead=='storymode'ortypeHead=='storymodemusic'thenedition='Story Mode'elseedition=''..string.upper(string.sub(typeHead,1,1))..string.sub(typeHead,2)end table.insert(result,'</table>[[Category:Pages with sound tables]][[Category:Pages with '..edition..' sound tables]]'..f:expandTemplate{title='notelist',args={'sound'}}) returntable.concat(result) end returnp