Module:Sprite: Difference between revisions

Undo revision 1891074 by Dhranios (talk) didn't work
Allow separate height and width
Line 60: Line 60:
end
end
local size = setting( 'size' )
local width = setting( 'width' ) or setting( 'size' )
local height = setting( 'height' ) or setting( 'size' )
local sheetWidth = setting( 'sheetsize' )
local sheetWidth = setting( 'sheetsize' )
local tiles = sheetWidth / size
local tiles = sheetWidth / width
local pos = setting( 'pos' ) - 1
local pos = setting( 'pos' ) - 1
local scale = setting( 'scale' )
local scale = setting( 'scale' )
Line 68: Line 69:
if pos then
if pos then
local left = pos % tiles * size * scale
local left = pos % tiles * width * scale
local top = math.floor( pos / tiles ) * size * scale
local top = math.floor( pos / tiles ) * height * scale
styles[#styles + 1] = 'background-position:-' .. left .. 'px -' .. top .. 'px'
styles[#styles + 1] = 'background-position:-' .. left .. 'px -' .. top .. 'px'
end
end
Line 76: Line 77:
styles[#styles + 1] = 'background-size:' .. sheetWidth * scale .. 'px auto'
styles[#styles + 1] = 'background-size:' .. sheetWidth * scale .. 'px auto'
end
end
if size ~= defaultStyle.size or ( not autoScale and scale ~= defaultStyle.scale ) then
if height ~= defaultStyle.size or width ~= defaultStyle.size or ( not autoScale and scale ~= defaultStyle.scale ) then
styles[#styles + 1] = 'height:' .. size * scale .. 'px'
styles[#styles + 1] = 'height:' .. height * scale .. 'px'
styles[#styles + 1] = 'width:' .. size * scale .. 'px'
styles[#styles + 1] = 'width:' .. width * scale .. 'px'
end
end