Module:Sprite

local p = {}

function p.base(f) local args = f	if f == mw.getCurrentFrame then args = require( 'Module:ProcessArgs' ).merge( true ) else f = mw.getCurrentFrame end local default = { scale = 1, sheetsize = 256, size = 16, pos = 1 }	local data = args.data and mw.loadData( 'Module:' .. args.data ) or {} local settings = data.settings if settings then for k, v in pairs( settings ) do			default[k] = v		end end local setting = function( arg ) return args[arg] or default[arg] end local height = setting('height') or setting('size') local width = setting('width') or setting('size') local sheetsize = setting('sheetsize') local tiles = sheetsize/width local pos = setting('pos') local scale = setting('scale') local autoscale = setting('autoscale') local name = setting('name') local tint = setting('tint') local styles = {"display: inline-block"} if pos then local x = pos % tiles * width * scale local y = math.floor( pos / tiles ) * height * scale styles[#styles + 1] = 'background-position:-' .. x .. 'px -' .. y .. 'px' end if tint then styles[#styles+1] = 'background: linear-gradient(' .. tint .. ', ' .. tint .. ');' end styles[#styles + 1] = 'background-size:' .. sheetsize * scale .. 'px auto' styles[#styles + 1] = 'height:' .. height * scale .. 'px' styles[#styles + 1] = 'width:' .. width * scale .. 'px' local sprite = mw.html.create('span') sprite:cssText(table.concat(styles, ';')):addClass(name .. '-sprite'):addClass('sprite-image') return sprite end

function p.sprite(f) local args = f	if f == mw.getCurrentFrame then args = require( 'Module:ProcessArgs' ).merge( true ) else f = mw.getCurrentFrame end local sprite = p.base(f) return sprite end

function p.test(frame) local root = mw.html.create('span') local sprite = mw.html.create( 'span' ) sprite:wikitext("") sprite:cssText(table.concat({"left:-" .. frame.args.size*frame.args.x .. "px", "top:-" .. frame.args.size*frame.args.y .. "px", "position: absolute"}, ';')) root:cssText(table.concat({"width: " .. frame.args.size .. "px", "height: " .. frame.args.size .. "px", "overflow: hidden", "position: relative"}, ';')) root:node(sprite) return tostring(root) end

function p.tagtest end

return p