VOOZH about

URL: https://minecraft.wiki/w/Module:Sprite

⇱ Module:Sprite – Minecraft Wiki


Module:Sprite

From Minecraft Wiki
Jump to navigation Jump to search
Documentation[view] [edit] [history] [purge]Jump to code ↴

This module implements {{sprite}}. It should generally be invoked directly on template pages, rather than using the sprite template.

Parent arguments are automatically merged with directly passed arguments (the latter overwriting the former) and all arguments are normalised to trim whitespace and set empty arguments to nil.

Dependencies

See also

Minecraft
Minecraft (legacy)

Minecraft Dungeons

Minecraft Legends

Minecraft Story Mode

Franchise

Other
[view] [edit] [history] [purge]The above documentation is transcluded from Module:Sprite/doc.
localp={}
functionp.base(f)
localargs=f
iff==mw.getCurrentFrame()then
args=require('Module:ProcessArgs').merge(true)
else
f=mw.getCurrentFrame()
end
localdata=args.dataandmw.loadData('Module:'..args.data)or{}
localsettings=data.settings
-- Default settings
localdefault={
scale=1,
sheetsize=256,
size=16,
pos=1,
align='text-top'
}
localdefaultStyle=default
ifsettingsthen
ifnotsettings.stylesheetthen
-- Make a separate clone of the current default settings
defaultStyle=mw.clone(default)
end
fork,vinpairs(settings)do
default[k]=v
end
end
localsetting=function(arg)
returnargs[arg]ordefault[arg]
end
localsprite=mw.html.create('span'):addClass('sprite')
-- mw.html's css method performs very slow escaping, which doubles the time it takes
-- to run, so we'll construct the styles manually, and put them in the cssText
-- method, which only does html escaping (which isn't slow)
localstyles={}
-- for tint
localclassname=setting('classname')ormw.ustring.lower(setting('name'):gsub(' ','-'))..'-sprite'
localcss_image="background"
ifsetting('formask')then
classname=classname..'-mask'
css_image="mask"
end
sprite:addClass(classname)
localclass=setting('class')
ifclassthen
sprite:addClass(class)
end
localwidth=setting('width')orsetting('size')
localheight=setting('height')orsetting('size')
localsheetWidth=setting('sheetsize')
localtiles=sheetWidth/width
localpos=setting('pos')-1
localscale=setting('scale')
localautoScale=setting('autoscale')
ifposthen
localleft=pos%tiles*width*scale
localtop=math.floor(pos/tiles)*height*scale
ifcss_image=='mask'then
styles[#styles+1]='-webkit-mask-position:-'..left..'px -'..top..'px'
end
styles[#styles+1]=css_image..'-position:-'..left..'px -'..top..'px'
end
ifnotautoScaleandscale~=defaultStyle.scalethen
ifcss_image=='mask'then
styles[#styles+1]='-webkit-mask-size:'..sheetWidth*scale..'px auto'
end
styles[#styles+1]=css_image..'-size:'..sheetWidth*scale..'px auto'
end
ifheight~=defaultStyle.sizeorwidth~=defaultStyle.sizeor(notautoScaleandscale~=defaultStyle.scale)then
styles[#styles+1]='height:'..height*scale..'px'
styles[#styles+1]='width:'..width*scale..'px'
end
localalign=setting('align')
ifalign~=defaultStyle.alignthen
styles[#styles+1]='vertical-align:'..align
end
styles[#styles+1]=setting('css')
sprite:cssText(table.concat(styles,';'))
localtext=setting('text')
localroot
localspriteText
iftextthen
ifnotargs['wrap']then
root=mw.html.create('span'):addClass('nowrap')
end
spriteText=mw.html.create('span'):addClass('sprite-text'):wikitext(text)
end
localtitle=setting('title')
iftitlethen
(rootorsprite):attr('title',title)
end
ifnotrootthen
root=mw.html.create('')
end
root:node(sprite)
ifspriteTextthen
root:node(spriteText)
end
locallink=setting('link')or''
iflink~=''andmw.ustring.lower(link)~='none'then
-- External link
iflink:find('//')then
return'['..link..' '..tostring(root)..']'
end
-- Internal link
locallinkPrefix=setting('linkprefix')or''
return'[['..linkPrefix..link..'|'..tostring(root)..']]'
end
returntostring(root)
end
functionp.sprite(f)
localargs=f
iff==mw.getCurrentFrame()then
args=require('Module:ProcessArgs').merge(true)
else
f=mw.getCurrentFrame()
end
localdata=args.dataandmw.loadData('Module:'..args.data)or{}
localcategories={}
localidData=args.iddata
ifnotidDatathen
localname=args.nameordata.settings.name
localid=mw.text.trim(tostring(args[1]or''))
idData=data.ids[id]ordata.ids[mw.ustring.lower(id):gsub('[%s%+]','-')]
end
localtitle=mw.title.getCurrentTitle()
-- Remove categories on language pages, talk pages, and in User/UserWiki/UserProfile namespaces
localdisallowCats=args.nocatortitle.isTalkPageortitle.nsText:find('^User')
ifidDatathen
ifidData.deprecatedthen
args.class=(args.classor'')..' sprite-deprecated'
ifnotdisallowCatsthen
categories[#categories+1]=f:expandTemplate{title='Translation category',args={'Pages using deprecated sprite names',project=0}}
end
end
args.pos=idData.pos
elseifnotdisallowCatsthen
categories[#categories+1]=f:expandTemplate{title='Translation category',args={'Pages with missing sprites',project=0}}
end
returnp.base(args),table.concat(categories)
end
functionp.link(f)
localargs=f
iff==mw.getCurrentFrame()then
args=require('Module:ProcessArgs').merge(true)
end
locallink=args[1]
ifargs[1]andnotargs.idthen
link=args[1]:match('^(.-)%+')orargs[1]
end
localtext
ifnotargs.notextthen
text=args.textorargs[2]orlink
end
args[1]=args.idorargs[1]
args.link=args.linkorlink
args.text=text
returnp.sprite(args)
end
functionp.doc(f)
localargs=f
iff==mw.getCurrentFrame()then
args=f.args
else
f=mw.getCurrentFrame()
end
localdataPage=mw.text.trim(args[1])
localdata=mw.loadData('Module:'..dataPage)
localgetProtection=function(title,action,extra)
localprotections={'edit'}
ifextrathen
protections[#protections+1]=extra
end
localaddProtection=function(protection)
ifprotection=='autoconfirmed'then
protection='editsemiprotected'
elseifprotection=='sysop'then
protection='editprotected'
end
protections[#protections+1]=protection
end
localdirect=title.protectionLevels[action]or{}
for_,protectioninipairs(direct)do
addProtection(protection)
end
localcascading=title.cascadingProtection.restrictions[action]or{}
if#cascading>0then
protections[#protections+1]='protect'
end
for_,protectioninipairs(cascading)do
addProtection(protection)
end
returntable.concat(protections,',')
end
localspriteStyle=''
ifdata.settings.urlanddata.settings.url.stylethen
spriteStyle=data.settings.url.style
end
localdataTitle=mw.title.new('Module:'..dataPage)
-- Temporary until this is updated
localspritesheet=data.settings.imageordata.settings.name..'Sprite.png'
localspriteTitle=mw.title.new('File:'..spritesheet)
localdataProtection=getProtection(dataTitle,'edit')
localspriteProtection=getProtection(spriteTitle,'upload','upload,reupload')
localbody=mw.html.create('div'):attr({
id='spritedoc',
['data-dataprotection']=dataProtection,
['data-datatimestamp']=f:callParserFunction('REVISIONTIMESTAMP','Module:'..dataPage),
['data-datapage']='Module:'..dataPage,
['data-spritesheet']=spritesheet,
['data-spriteprotection']=spriteProtection,
['data-refreshtext']=mw.text.nowiki('{{#invoke:sprite|doc|'..dataPage..'|refresh=1}}'),
['data-settings']=mw.text.jsonEncode(data.settings),
})
localsections={}
for_,sectionDatainipairs(data.sectionsor{name='Uncategorized'})do
localsectionTag=body:tag('div'):addClass('spritedoc-section'):attr('data-section-id',sectionData.id)
sectionTag:tag('h3'):wikitext(sectionData.name)
sections[sectionData.id]={boxes=sectionTag:tag('ul'):addClass('spritedoc-boxes')}
end
localkeyedData={}
locali=1
forname,idDatainpairs(data.ids)do
keyedData[i]={
sortKey=mw.ustring.lower(name),
name=name,
data=idData
}
i=i+1
end
table.sort(keyedData,function(a,b)
returna.sortKey<b.sortKey
end)
for_,datainipairs(keyedData)do
localidData=data.data
localpos=idData.pos
localsection=sections[idData.section]
localnames=section[pos]
ifnotnamesthen
localbox=section.boxes:tag('li'):addClass('spritedoc-box'):attr('data-pos',pos)
box:tag('div'):addClass('spritedoc-image')
:wikitext(p.base{pos=pos,data=dataPage,nourl=spriteStyle~=''})
names=box:tag('ul'):addClass('spritedoc-names')
section[pos]=names
end
localnameElem=mw.html.create('li'):addClass('spritedoc-name')
localcodeElem=nameElem:tag('code'):wikitext(data.name)
ifidData.deprecatedthen
codeElem:addClass('spritedoc-deprecated')
end
names:wikitext(tostring(nameElem))
end
ifargs.refreshthen
return'','',tostring(body)
end
localstyles=f:extensionTag('templatestyles','',{src='Sprite/doc.css'})
returnstyles,spriteStyle,tostring(body)
end
returnp
Retrieved from "https://minecraft.wiki/w/Module:Sprite?oldid=2316120"

Navigation menu