Module:Sprite: Difference between revisions

Jump to navigation Jump to search
m (1 revision imported: Sprite from Feed the Beast wiki)
No edit summary
 
(33 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local p = {}
local p = {}


local g = require("Module:Common")
p.main = function( frame )
 
local ratio = tonumber(frame.args['ratio'])
function p.calcSpriteSheetPos(index, spriteSize, sheetSize)
local sheetWidth = tonumber(frame.args['sheetWidth'])
local iconsOnRow = sheetSize / spriteSize
local sheetHeight = tonumber(frame.args['sheetHeight'])
return {
local noOfRows = tonumber(frame.args['noOfRows'])
top = -math.floor(index / iconsOnRow) * spriteSize,
local noOfColumns = tonumber(frame.args['noOfColumns'])
left = -math.mod(index, iconsOnRow) * spriteSize
local offsetX = tonumber(frame.args['offsetX']) * -1
}
local offsetY = tonumber(frame.args['offsetY']) * -1
end
local row = tonumber(frame.args['row']) - 1
 
local col = tonumber(frame.args['col']) - 1
function p.makeSprite(image, index, spriteSize, sheetSize, link, title, align)
local image = frame.args['image']
local output = "<span style=\"position: relative; height: "
local cellWidth = sheetWidth / noOfColumns
output = output .. spriteSize .. "px; width: "
local cellHeight = sheetHeight / noOfRows
output = output .. spriteSize .. "px; overflow: hidden; display: inline-block; vertical-align: "
local outline = frame:getArgument('outline')
output = output .. (align or "middle") .. ";\"><span style=\"position: absolute; height: "
local imageClass
output = output .. sheetSize .. "px; width: " .. sheetSize .. "px;"
if outline ~= nil then
local spritePos = p.calcSpriteSheetPos(index, spriteSize, sheetSize)
imageClass = "pixelart blackstroke"
if spritePos.top ~= 0 then
else
output = output .. "top: " .. spritePos.top .. "px;"
imageClass = "pixelart"
end
end
output = output .. "left: " .. spritePos.left .. "px;\">[[File:" .. image
local span = mw.html.create('span')
if g.isGiven(link) then
:cssText(
output = output .. "|link=" .. link
string.format(
end
[[
if g.isGiven(title) then
position: relative;
output = output .. "|" .. title
height: %dpx;
end
width: %dpx;
output = output .. "]]</span></span>"
overflow: hidden;
return output
display: inline-block;
end
vertical-align: middle;
 
]],
function p.main(frame)
cellHeight * ratio,
local frame, args = g.getFrameAndArgs(frame)
cellWidth * ratio
)
if not (g.isGiven(args.pos) and tonumber(args.pos)) then
)
args.pos = 1
:tag('span')
end
:cssText(
string.format(
if not (g.isGiven(args.size) and tonumber(args.size)) then
[[
args.size = 16
position: absolute;
end
height: %dpx;
width: %dpx;
if not (g.isGiven(args.sheetsize) and tonumber(args.sheetsize)) then
top: %dpx;
args.sheetsize = 256
left: %dpx;
end
]],
sheetHeight * ratio,
return p.makeSprite(args.image, tonumber(args.pos) - 1, args.size,
sheetWidth * ratio,
args.sheetsize, args.link, args.title, args.align)
(offsetY - cellHeight * row) * ratio,
(offsetX - cellWidth * col) * ratio
)
)
:wikitext(string.format('[[%s|%dpx|class=pixelart]]', image, sheetWidth * ratio))
:done()
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