Module:Sprite: Difference between revisions
Jump to navigation
Jump to search
Auburnsummer (talk | contribs) No edit summary Tag: Reverted |
Auburnsummer (talk | contribs) No edit summary Tag: Reverted |
||
Line 12: | Line 12: | ||
local col = tonumber(frame.args['col']) - 1 | local col = tonumber(frame.args['col']) - 1 | ||
local image = frame.args['image'] | local image = frame.args['image'] | ||
local imagePath = frame:callParserFunction{ name = 'filepath', args = image } | |||
local link = frame.args['link'] | |||
local cellWidth = sheetWidth / noOfColumns | local cellWidth = sheetWidth / noOfColumns | ||
local cellHeight = sheetHeight / noOfRows | local cellHeight = sheetHeight / noOfRows | ||
Line 39: | Line 41: | ||
left = tostring((offsetX - cellWidth * col) * ratio) .. 'px' | left = tostring((offsetX - cellWidth * col) * ratio) .. 'px' | ||
}) | }) | ||
: | :tag('a') | ||
:attr({ | |||
href = link | |||
}) | |||
:tag('img') | |||
:attr({ | |||
class = imageClass, | |||
src = imagePath | |||
}) | |||
:done() | :done() | ||
return tostring(span) | return tostring(span) |
Revision as of 10:49, 29 May 2022
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 offsetX = tonumber(frame.args['offsetX']) * -1
local offsetY = tonumber(frame.args['offsetY']) * -1
local row = tonumber(frame.args['row']) - 1
local col = tonumber(frame.args['col']) - 1
local image = frame.args['image']
local imagePath = frame:callParserFunction{ name = 'filepath', args = image }
local link = frame.args['link']
local cellWidth = sheetWidth / noOfColumns
local cellHeight = sheetHeight / noOfRows
local outline = frame.args['outline']
local imageClass
if outline ~= '' then
imageClass = "pixelart blackstroke"
else
imageClass = "pixelart"
end
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',
['--blackstroke-color'] = outline
})
:tag('span')
:css({
position = 'absolute',
height = tostring(sheetHeight * ratio) .. 'px',
width = tostring(sheetWidth * ratio) .. 'px',
top = tostring((offsetY - cellHeight * row) * ratio) .. 'px',
left = tostring((offsetX - cellWidth * col) * ratio) .. 'px'
})
:tag('a')
:attr({
href = link
})
:tag('img')
:attr({
class = imageClass,
src = imagePath
})
:done()
return tostring(span)
end
return p