Module:Sprite

Revision as of 08:24, 27 May 2022 by Auburnsummer (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Sprite/doc

local p = {}

p.main = function( frame )
	local ratio = tonumber(frame.args['ratio'])
	local sheetWidth = tonumber(frame.args['sheetWidth'])
	local sheetHeight = tonumber(frame.args['sheetHeight'])
	local noOfRows = tonumber(frame.args['noOfRows'])
	local noOfColumns = tonumber(frame.args['noOfColumns'])
	local cellWidth = sheetWidth / noOfRows
	local cellHeight = sheetHeight / noOfColumns
	
	local span = mw.html.create('span')
		:css({
			position = 'relative',
			height = tostring(cellHeight * ratio) .. 'px',
			width = tostring(cellWidth * ratio) .. 'px',
			overflow = 'hidden',
			display = 'inline-block',
			['vertical-align'] = 'middle'
		})
		:tag('span')
		:css({
			position = 'absolute'
		})
		:done()
	return tostring(span)
end

return p