Module:Sprite: Difference between revisions

Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
 
(6 intermediate revisions by the same user not shown)
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
local outline = frame.args['outline']
local outline = frame:getArgument('outline')
local imageClass
local imageClass
if outline ~= '' then
if outline ~= nil then
imageClass = "pixelart blackstroke"
imageClass = "pixelart blackstroke"
else
else
Line 24: Line 22:
end
end
local span = mw.html.create('span')
local span = mw.html.create('span')
:css({
:cssText(
position = 'relative',
string.format(
height = tostring(cellHeight * ratio) .. 'px',
[[
width = tostring(cellWidth * ratio) .. 'px',
position: relative;
overflow = 'hidden',
height: %dpx;
display = 'inline-block',
width: %dpx;
['vertical-align'] = 'middle',
overflow: hidden;
['--blackstroke-color'] = outline
display: inline-block;
})
vertical-align: middle;
]],
cellHeight * ratio,
cellWidth * ratio
)
)
:tag('span')
:tag('span')
:css({
:cssText(
position = 'absolute',
string.format(
height = tostring(sheetHeight * ratio) .. 'px',
[[
width = tostring(sheetWidth * ratio) .. 'px',
position: absolute;
top = tostring((offsetY - cellHeight * row) * ratio) .. 'px',
height: %dpx;
left = tostring((offsetX - cellWidth * col) * ratio) .. 'px'
width: %dpx;
})
top: %dpx;
:tag('a')
left: %dpx;
:attr({
]],
href = link
sheetHeight * ratio,
})
sheetWidth * ratio,
:tag('img')
(offsetY - cellHeight * row) * ratio,
:attr({
(offsetX - cellWidth * col) * ratio
class = imageClass,
)
src = imagePath
)
})
:wikitext(string.format('[[%s|%dpx|class=pixelart]]', image, sheetWidth * ratio))
:allDone()
:done()
return tostring(span)
return tostring(span)
end
end


return p
return p

Latest revision as of 04:28, 31 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 cellWidth = sheetWidth / noOfColumns
	local cellHeight = sheetHeight / noOfRows
	local outline = frame:getArgument('outline')
	local imageClass
	if outline ~= nil then
		imageClass = "pixelart blackstroke"
	else
		imageClass = "pixelart"
	end
	local span = mw.html.create('span')
		:cssText(
			string.format(
				[[
					position: relative;
					height: %dpx;
					width: %dpx;
					overflow: hidden;
					display: inline-block;
					vertical-align: middle;
				]],
				cellHeight * ratio,
				cellWidth * ratio
			)
		)
		:tag('span')
		:cssText(
			string.format(
				[[
					position: absolute;
					height: %dpx;
					width: %dpx;
					top: %dpx;
					left: %dpx;
				]],
				sheetHeight * ratio,
				sheetWidth * ratio,
				(offsetY - cellHeight * row) * ratio,
				(offsetX - cellWidth * col) * ratio
			)
		)
		:wikitext(string.format('[[%s|%dpx|class=pixelart]]', image, sheetWidth * ratio))
		:done()
	return tostring(span)
end

return p