匿名
未登录
中文
讨论
贡献
创建账号
登录
Minecraft基岩版开发Wiki
搜索
致编者:请牢记我们的域名
wiki.mcbe-dev.net
!
致编者:欢迎加入本Wiki的官方交流
QQ群
或
Discord服务器
!
基岩版1.19.31
现已发布!(
了解更多
)
Inner Core
现已支持Xbox模组联机!(
了解更多
)
如果您是第一次来到本Wiki,欢迎
注册一个账户
点击顶部的“编辑”或“编辑源代码”按钮即可编辑当前页面
请知悉:在不登录时也可以编辑和新建页面,但是您当前的IP地址会记录在编辑历史中
编辑“
Module:Sprite
”
来自Minecraft基岩版开发Wiki
命名空间
模块
讨论
更多
更多
页面操作
阅读
编辑
历史
刷新
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
local p = {} function p.base( f ) local args = f if f == mw.getCurrentFrame() then args = require( 'Module:ProcessArgs' ).merge( true ) else f = mw.getCurrentFrame() end local data = args.data and mw.loadData( 'Module:' .. args.data ) or {} local settings = data.settings local Autolink = require( 'Module:Autolink' ) -- Default settings local default = { scale = 1, sheetsize = 256, size = 16, pos = 1, align = 'text-top' } local defaultStyle = default if settings then if not settings.stylesheet then -- Make a separate clone of the current default settings defaultStyle = { scale = 1, sheetsize = 256, size = 16, pos = 1, align = 'text-top' } end for k, v in pairs( settings ) do default[k] = v end end setmetatable( args, { __index = default } ) local sprite = 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) local styles = {} -- for tint local classname = args['classname'] or mw.ustring.lower( ( args['name'] or args['image'] :gsub( 'CSS.png', '' ) ) :gsub( ' ', '-' ) ) .. '-sprite' local css_image = "background" if args['formask'] then classname = classname .. '-mask' css_image = "mask" end sprite:addClass( classname ) local class = args['class'] if class then sprite:addClass( class ) end local width = tonumber(args['width'] or args['size']) local height = tonumber(args['height'] or args['size']) local sheetWidth = tonumber(args['sheetsize']) local tiles = sheetWidth / width local pos = tonumber(args['pos']) - 1 local scale = tonumber(args['scale']) local autoScale = args['autoscale'] if pos then local left = pos % tiles * width * scale local top = math.floor( pos / tiles ) * height * scale if css_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 if not autoScale and scale ~= defaultStyle.scale then if css_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 if height ~= defaultStyle.size or width ~= defaultStyle.size or ( not autoScale and scale ~= defaultStyle.scale ) then styles[#styles + 1] = 'height:' .. height * scale .. 'px' styles[#styles + 1] = 'width:' .. width * scale .. 'px' end local align = args['align'] if align ~= defaultStyle.align then styles[#styles + 1] = 'vertical-align:' .. align end styles[#styles + 1] = args['css'] sprite:cssText( table.concat( styles, ';' ) ) local text = args['text'] local root local spriteText if text then if not args['wrap'] then root = mw.html.create( 'span' ):addClass( 'nowrap' ) end spriteText = mw.html.create( 'span' ):addClass( 'sprite-text' ):wikitext( Autolink.invlink( text, 'nolink', args.data ) ) end local title = args['title'] if title then ( root or sprite ):attr( 'title', title ) end if not root then root = mw.html.create( '' ) end root:node( sprite ) if spriteText then root:node( spriteText ) end local link = args['link'] or '' if link ~= '' and mw.ustring.lower( link ) ~= 'none' then -- External link if link:find( '//' ) then return '[' .. link .. ' ' .. tostring( root ) .. ']' end -- Internal link local linkPrefix = args['linkprefix'] or '' return '[[' .. linkPrefix .. Autolink.invlink( link, 'linkonly', args.data ) .. '|' .. tostring( root ) .. ']]' end return tostring( root ) end function p.sprite( f ) local args = f if f == mw.getCurrentFrame() then args = require( 'Module:ProcessArgs' ).merge( true ) else f = mw.getCurrentFrame() end local data = args.data and mw.loadData( 'Module:' .. args.data ) or {} local categories = {} local idData = args.iddata if not idData then local name = args.name or data.settings.name local id = mw.text.trim( tostring( args[1] or '' ) ) idData = data.ids[id] or data.ids[mw.ustring.lower( id ):gsub( '[%s%+]', '-' )] end local title = mw.title.getCurrentTitle() -- Remove categories on language pages, talk pages, and in User/UserWiki/UserProfile namespaces local disallowCats = args.nocat or title.isTalkPage or title.nsText:find( '^User' ) if idData then if idData.deprecated then args.class = ( args.class or '' ) .. ' sprite-deprecated' if not disallowCats then categories[#categories + 1] = '[[Category:使用已弃用Sprite的页面]]' end end args.pos = idData.pos elseif not disallowCats then categories[#categories + 1] = '[[Category:含有错误Sprite的页面]]' end return p.base( args ), table.concat( categories ) end function p.link( f ) local args = f if f == mw.getCurrentFrame() then args = require( 'Module:ProcessArgs' ).merge( true ) end local link = args[1] if args[1] and not args.id then link = args[1]:match( '^(.-)%+' ) or args[1] end local text if not args.notext then text = args.text or args[2] or link end args[1] = args.id or args[1] args.link = args.link or link args.text = text return p.sprite( args ) end function p.getUrl( image, query, classname ) local f = mw.getCurrentFrame() local t = { url = f:expandTemplate{ title = 'FileUrl', args = { image, query = query } }, } if classname and classname ~= '' then t.style = f:expandTemplate{ title = 'FileUrlStyle', args = { classname, image, query = query } } end return t end function p.getParsedUrlStyle( f ) local args = f:getParent().args local module = args[1] return require( 'Module:' .. module ).settings.url.style end function p.doc( f ) local args = f if f == mw.getCurrentFrame() then args = f.args else f = mw.getCurrentFrame() end local dataPage = mw.text.trim( args[1] ) local data = mw.loadData( 'Module:' .. dataPage ) local getProtection = function( title, action, extra ) local protections = { 'edit' } if extra then protections[#protections + 1] = extra end local addProtection = function( protection ) if protection == 'autoconfirmed' then protection = 'editsemiprotected' elseif protection == 'sysop' then protection = 'editprotected' end protections[#protections + 1] = protection end local direct = title.protectionLevels[action] or {} for _, protection in ipairs( direct ) do addProtection( protection ) end local cascading = title.cascadingProtection.restrictions[action] or {} if #cascading > 0 then protections[#protections + 1] = 'protect' end for _, protection in ipairs( cascading ) do addProtection( protection ) end return table.concat( protections, ',' ) end local spriteStyle = '' if data.settings.url and data.settings.url.style then spriteStyle = data.settings.url.style end local dataTitle = mw.title.new( 'Module:' .. dataPage ) -- Temporary until this is updated local classname = '' if data.settings.stylesheet then classname = data.settings.classname or mw.ustring.lower( data.settings.name:gsub( ' ', '-' ) ) .. '-sprite' end local spritesheet = data.settings.image or data.settings.name .. 'Sprite.png' local spriteTitle = mw.title.new( 'File:' .. spritesheet ) local dataProtection = getProtection( dataTitle, 'edit' ) local spriteProtection = getProtection( spriteTitle, 'upload', 'upload,reupload' ) local body = 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-urlfunc'] = "require( [[Module:Sprite]] ).getUrl( '" .. spritesheet .. "', '$1', '" .. classname .. "' )", ['data-refreshtext'] = mw.text.nowiki( '{{#invoke:sprite|doc|' .. dataPage .. '|refresh=1}}' ), ['data-settings'] = mw.text.jsonEncode( data.settings ), } ) local sections = {} for _, sectionData in ipairs( data.sections or { name = 'Uncategorized' } ) do local sectionTag = 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 local keyedData = {} local i = 1 for name, idData in pairs( data.ids ) do keyedData[i] = { sortKey = mw.ustring.lower( name ), name = name, data = idData } i = i + 1 end table.sort( keyedData, function( a, b ) return a.sortKey < b.sortKey end ) for _, data in ipairs( keyedData ) do local idData = data.data local pos = idData.pos local section = sections[idData.section] local names = section[pos] if not names then local box = 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 local nameElem = mw.html.create( 'li' ):addClass( 'spritedoc-name' ) local codeElem = nameElem:tag( 'code' ):wikitext( data.name ) if idData.deprecated then codeElem:addClass( 'spritedoc-deprecated' ) end names:wikitext( tostring( nameElem ) ) end if args.refresh then return '', '', tostring( body ) end local styles = f:callParserFunction( '#widget:SpriteDoc.css' ) return styles, spriteStyle, tostring( body ) end return p
摘要:
请注意您对Minecraft基岩版开发Wiki的所有贡献都被认为是在知识共享署名-非商业性使用-相同方式共享下发布,请查看在
Minecraft基岩版开发Wiki:版权
的细节。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源。
请勿私自提交受版权保护的材料!
您也可以将取自Mojang(及其网站、说明、指南、艺术概念、渲染图、出版物、第三方网站组件,以及其他此类Mojang已对外公开的受保护材料)的内容上传至Minecraft基岩版开发Wiki。所有权力、署名与利益在合适时仍归属Mojang,也不依照许可被授权。
取消
编辑帮助
(在新窗口中打开)
预览使用本模板的页面
本页使用的模板:
Template:Documentation/styles.css
(
编辑
)
Template:Documentation header
(
编辑
)
Template:Sprite see also
(
编辑
)
Template:Template link
(
编辑
)
Template:Tl
(
编辑
)
Template:Transclude
(
编辑
)
Module:Documentation
(
编辑
)
Module:ProcessArgs
(
编辑
)
Module:Sprite/doc
(
编辑
)
我们提供服务需要使用Cookie。您使用我们的服务,即表示您同意我们使用Cookie。
更多信息
确定
导航
导航
首页
最近更改
随机页面
社区门户
新闻动态
计划
沙盒
关于
导航
开发
附加包
模组SDK
ModPE Installer
BlockLauncher
Inner Core
ModdedPE
基岩版专用服务器
ElementZero
Cloudburst Nukkit
合作伙伴
Mineprogramming Wiki
bedrock.dev
友情链接
中文 Minecraft Wiki
我的世界中文论坛
MCDevs Wiki
Inner Core 中文社区
wiki工具
wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志