![]() |
VOOZH | about |
This module implements {{Convert}}.
localp={} functionp.normalizeUnit(u) localunit=u ifu=='tick'oru=='ticks'oru=='gt'oru=='game ticks'thenunit='game tick' elseifu=='rt'oru=='redstone ticks'thenu='redstone tick' elseifu=='s'oru=='sec'oru=='secs'oru=='seconds'thenunit='second' elseifu=='m'oru=='min'oru=='mins'oru=='minutes'thenunit='minute' elseifu=='day'oru=='days'oru=='igd'oru=='in game day'thenunit='in-game day' end returnunit end functionp.convert(value,inputUnit,outputUnit) inputUnit=p.normalizeUnit(inputUnitor'game tick')-- using default value of 'game tick' outputUnit=p.normalizeUnit(outputUnitor'second')-- using default value of 'second' localconvertedValue=value localconversions={ ['second -> game tick']=convertedValue*20,['game tick -> second']=convertedValue/20, ['second -> redstone tick']=convertedValue*10,['redstone tick -> second']=convertedValue/10, ['minute -> second']=convertedValue*60,['second -> minute']=convertedValue/60, ['minute -> game tick']=convertedValue*20*60,['game tick -> minute']=convertedValue/20/60, ['minute -> redstone tick']=convertedValue*10*60,['redstone tick -> minute']=convertedValue/10/60, ['game tick -> redstone tick']=convertedValue/2,['redstone tick -> game tick']=convertedValue*2, ['in-game day -> minute']=convertedValue*20,['minute -> in-game day']=convertedValue/20, ['in-game day -> second']=convertedValue*20*60,['second -> in-game day']=convertedValue/20/60, ['in-game day -> game tick']=convertedValue*24000,['game tick -> in-game day']=convertedValue/24000, } convertedValue=conversions[inputUnit..' -> '..outputUnit] returnconvertedValue end functionp.output(f) localargs=f iff==mw.getCurrentFrame()then args=require('Module:ProcessArgs').merge(true) end localvalue=args[1]*1or1-- using default value of 1 localsourceUnit=args[2] ifnotargs[2]thenreturn1end ifnotargs[3]thenreturnvalue..' '..sourceUnitend localseparator=args['separator']orargs['sep']orargs['s']or'(' localstartSeparator=' '..separator..' ' localendSeparator='' ifseparator=='('thenstartSeparator=' ('endSeparator=')'end localfullOutput='' fori,unitinipairs(args)do if(i>2andargs[i])then unit=p.normalizeUnit(unit) localoutputVal=p.convert(value,sourceUnit,unit) ifunit=='game tick'orunit=='redstone tick'thenunit='[['..unit..']]'end ifoutputVal~=1thenunit=unit..'s'end-- plural localmidSeparator=startSeparator ifi>3andmidSeparator==' ('thenmidSeparator='; 'end fullOutput=fullOutput..midSeparator..outputVal..' '..unit end end sourceUnit=p.normalizeUnit(sourceUnit) ifvalue~=1thensourceUnit=sourceUnit..'s'end returnvalue..' '..sourceUnit..fullOutput..endSeparator end returnp