モジュール:SpriteFile

提供:Minecraft Wiki
これはこのページの過去の版です。Cook Me Plox (トーク | 投稿記録) による 2024年2月16日 (金) 16:28(個人設定で未設定ならUTC)時点の版であり、現在の版とは大きく異なる場合があります。
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

このモジュールは従来の{{sprite}}の代替となる機能です。このモジュールはテンプレートからテンプレート:Spriteを介さず直接呼び出して使用します。

親の引数と与えられた引数は、後者が前者を上書きする形で統合され、すべての引数は半角スペースを変換してすべての引数は空白を取り除き、空の引数をnilに設定するように正規化される。

依存関係

関連項目

Minecraft
Minecraft(レガシー)
Minecraft Dungeons
その他
[閲覧] [編集] [履歴] [更新]上記の解説は、モジュール:SpriteFile/docから参照されています。
local p = {}

local autolink = require( 'モジュール:Autolink' ).invlink

function p.sprite( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'モジュール:ProcessArgs' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	
	-- Default settings
	local default = {
		scale = 1,
		size = 16,
		align = 'text-top'
	}
	
	local Reverselink = require( 'モジュール:Reverselink' )
	
	local id = mw.text.trim( tostring( Reverselink.xlink(args[1]) or '' ) )
	if not args.keepcase then
		id = mw.ustring.lower( id ):gsub( '[%s%+]', '-' )
	end
	
	local link = ( args.link or '' )
	if mw.ustring.lower( link ) == 'none' then
		link = ''
	elseif link ~= '' then
		local linkPrefix = ( not link:find( '//' ) and args.linkprefix ) or ''
		link = linkPrefix .. link
	end
	
	link = autolink( link, 'linkonly', args.name )
	
	local scale = args.scale or default.scale
	local height = ( args.height or args.size or default.size ) * scale
	local width = ( args.width or args.size or default.size ) * scale
	local size = width .. 'x' .. height .. 'px'
	
	local styles = {}
	if height ~= default.size then
		styles[#styles + 1] = 'height:' .. height .. 'px'
	end
	if width ~= default.size then
		styles[#styles + 1] = 'width:' .. width .. 'px'
	end
	
	local name = args.name
	if name == 'InvSprite' then
		name = 'Invicon'
	end
	local file = name .. ' ' .. id .. '.png'
	local altText = file .. ': Minecraftの' .. id .. 'のスプライト画像'
	if link ~= '' then
		altText = altText .. ' linking to ' .. link
	end
	if id == '' then
		file = 'Grid Unknown.png'
		altText = '不明なスプライト画像'
	end
	local sprite = mw.html.create( 'span' ):addClass( 'sprite-file' )
	local img = '[[File:' .. file .. '|' .. size .. '|link=' .. link .. '|alt=' .. altText .. '|class=pixel-image|' .. ( args.title or '' ) .. ']]'
	sprite:node( img )
	
	local align = args.align or default.align
	if align ~= default.align then
		styles[#styles + 1] = '--vertical-align:' .. align
	end
	styles[#styles + 1] = args.css
	
	sprite:cssText( table.concat( styles, ';' ) )
	
	local root
	local spriteText
	if args.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( args.text, 'nolink', args.name ) )
		if args.title then
			spriteText:attr( 'title', autolink( args.title, 'nolink', args.name ) )
		end
		if link ~= '' then
			-- External link
			if link:find( '//' ) then
				spriteText = '[' .. link .. ' ' .. tostring( spriteText ) .. ']'
			else
				spriteText = '[[' .. link .. '|' .. tostring( spriteText ) .. ']]'
			end
		end
	end
	
	if not root then
		root = mw.html.create( '' )
	end
	root:node( sprite )
	if spriteText then
		root:node( spriteText )
	end
	
	return tostring( root )
end

function p.link( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'モジュール: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

return p