Module:Sprite: Difference between revisions
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 / | 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 * | local left = pos % tiles * width * scale | ||
local top = math.floor( pos / tiles ) * | 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:' .. | styles[#styles + 1] = 'height:' .. height * scale .. 'px' | ||
styles[#styles + 1] = 'width:' .. | styles[#styles + 1] = 'width:' .. width * scale .. 'px' | ||
end | end | ||