Minecraft Wiki

除另有声明,转载时均必须注明出处若簡繁轉換出錯,請以遊戲內為準请勇于扩充与修正内容有兴趣逛逛我们的微博沟通交流,欢迎到社区专页需要协助,请在告示板留言

了解更多

Minecraft Wiki
Advertisement

本模块用于实现{{iconbar}}。使用时应在模板页面直接调用模块,而不是使用{{iconbar}}模板。

主参数会自动与直接输入的参数合并(即后者会覆盖前者)。

依赖项

参见


语言
local p = {}
function p.bar( f )
	local args = require( 'Module:ProcessArgs' ).merge()
	local full = args.full
	local half = args.half or 'Half ' .. full
	local empty = args.empty or 'Empty ' .. full
	local value = math.abs( tonumber( args.value ) or 0 ) / 2
	local min = math.ceil( math.abs( tonumber( args.min ) or 0 ) / 2 )
	local size = args.size or ''
	local title = args.title or ''
	local reverse = args.reverse or ''
	
	if title:lower() == 'none' then
		title = ''
	elseif title ~= '' then
		title = ' title="' .. title .. '"'
	else
		title = ' title="' .. value .. '"'
	end

	local fullIcon = ''
	local halfIcon = ''
	local emptyIcon = ''
	
	if tonumber( size ) then
		size = '|' .. size .. 'px'
	elseif size ~= '' then
		size = '|' .. size
	end
	
	if value == 0 then
		emptyIcon = '[[File:' .. empty .. size .. ']]'
	else
		fullIcon = string.rep( '[[File:' .. full .. size .. ']]', math.floor( value ) )
		
		if math.floor( value ) ~= value then
			halfIcon = '[[File:' .. half .. size .. ']]'
		end
	end
	
	if min - value >= 1 then
		emptyIcon = string.rep( '[[File:' .. empty .. size .. ']]', min - math.ceil( value ) )
	end
	
	if reverse ~= '' then
		return '<span class="nowrap"' .. title .. '>' .. emptyIcon .. halfIcon .. fullIcon .. '</span>'
	else
		return '<span class="nowrap"' .. title .. '>' .. fullIcon .. halfIcon .. emptyIcon .. '</span>'
	end
end
return p
Advertisement