Bureaucrats, emailconfirmed, Interface administrators, staff, Administrators, translation-admin, translator, Widget editors
154
edits
(Should fix it) |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
local types = { | local types = { | ||
inventory = [[Module:InvSprite]], | inventory = [[Module:InvSprite]], | ||
gm4 = [[Module:Gm4Sprite]] | gm4 = [[Module:Gm4Sprite]], | ||
effect = [[Module:EffectSprite]] | |||
} | } | ||
Line 31: | Line 32: | ||
setmetatable(t, {__index = file}) | setmetatable(t, {__index = file}) | ||
return t | |||
end | |||
function getSpriteSheet( image ) | |||
if not(image) then return nil end | |||
local f = mw.getCurrentFrame() | |||
local t = { | |||
url = f:expandTemplate{ | |||
title = 'SpriteSheet', | |||
args = {image} | |||
} | |||
} | |||
if t == "" then return nil end | |||
return t | return t | ||
Line 59: | Line 76: | ||
local size = image.width | local size = image.width | ||
o = { | o = { | ||
__source = { | __source = { | ||
settings={ | settings = {} | ||
}, | |||
__settings={ | |||
size = size, | |||
sheetsize = 1, | |||
image = image, | |||
sheetWidth = size, | |||
tiles = 1, | |||
name = name | |||
} | } | ||
} | } | ||
setmetatable(o, {__index = self}) | setmetatable(o, {__index = self}) | ||
o | setmetatable(o.__settings, {__index=defaultSettings}) | ||
return o | return o | ||
end | end | ||
Line 84: | Line 105: | ||
autoScale = settings.autoscale, | autoScale = settings.autoscale, | ||
image = (settings.image and getImage(settings.image)) | image = (settings.image and getImage(settings.image)) | ||
or settings.spriteSheet | or (settings.spriteSheet and getSpriteSheet(settings.spriteSheet)) | ||
} | } | ||
Line 128: | Line 149: | ||
function append(key, value) if value ~= nil then styles[#styles+1]=key .. ": " .. value end end | function append(key, value) if value ~= nil then styles[#styles+1]=key .. ": " .. value end end | ||
local settings = self.__settings | local settings = self.__settings | ||
-- has to be done first, otherwise the possition is overriden in chrome | |||
if settings.image then | |||
append("background", settings.image.url) | |||
end | |||
append ("background-size", settings.sheetWidth * settings.scale .. 'px auto') | append ("background-size", settings.sheetWidth * settings.scale .. 'px auto') | ||
Line 141: | Line 167: | ||
local top = math.floor( pos / settings.tiles ) * settings.size * settings.scale | local top = math.floor( pos / settings.tiles ) * settings.size * settings.scale | ||
append("background-position", '-' .. left .. 'px -' .. top .. 'px') | append("background-position", '-' .. left .. 'px -' .. top .. 'px') | ||
return table.concat( styles, "; " ) | return table.concat( styles, "; " ) |
edits