Module:Sprite: Difference between revisions

Jump to navigation Jump to search
m
hm
m (It's far too late, I'm tired and really should stop making edits.)
m (hm)
 
(34 intermediate revisions by 3 users not shown)
Line 5: Line 5:
local aliasData = {
local aliasData = {
vanillaAliases = [[Module:InventorySlot/Aliases]],
vanillaAliases = [[Module:InventorySlot/Aliases]],
gm4Aliases = [[Module:Gm4Sprite/Aliases]]
gm4Aliases = [[Module:Gm4Sprite/Aliases]],
effectAliases = [[Module:EffectSprite/Aliases]],
trophyAliases = [[Module:TrophySprite/Aliases]]
}
}


Line 11: Line 13:
local vanillaAliases = mw.loadData( aliasData.vanillaAliases )
local vanillaAliases = mw.loadData( aliasData.vanillaAliases )
local gm4Aliases = mw.loadData( aliasData.gm4Aliases )
local gm4Aliases = mw.loadData( aliasData.gm4Aliases )
local effectAliases = mw.loadData( aliasData.effectAliases )
local trophyAliases = mw.loadData( aliasData.trophyAliases )
local aliases
local aliases


Line 16: Line 20:
inventory = [[Module:InvSprite]],
inventory = [[Module:InvSprite]],
gm4 = [[Module:Gm4Sprite]],
gm4 = [[Module:Gm4Sprite]],
effect = [[Module:EffectSprite]]
effect = [[Module:EffectSprite]],
trophy = [[Module:TrophySprite]],
gm4RP = [[Module:Gm4RPSprite]]
}
}


Line 101: Line 107:
name = name,
name = name,
title = title,
title = title,
lore = lore
lore = lore,
enchanted = enchanted,
link = link
}
}
}
}
Line 118: Line 126:
autoScale = settings.autoscale,
autoScale = settings.autoscale,
image = (settings.image and getImage(settings.image))
image = (settings.image and getImage(settings.image))
or (settings.spriteSheet and getSpriteSheet(settings.spriteSheet))
-- or (settings.spriteSheet and getSpriteSheet(settings.spriteSheet))
}
}


Line 126: Line 134:
function Sprite:setItem(item, type)
function Sprite:setItem(item, type)
     -- set aliases
     -- set aliases
     if type == "gm4" then
     if type == "gm4" or type == "gm4RP" then
         aliases = gm4Aliases
         aliases = gm4Aliases
elseif type == "effect" then
aliases = effectAliases
elseif type == "trophy" then
aliases = trophyAliases
     else
     else
         aliases = vanillaAliases
         aliases = vanillaAliases
Line 149: Line 161:
elseif aliases[item].name then
elseif aliases[item].name then
self.__settings.title = aliases[item].name
self.__settings.title = aliases[item].name
end
if aliases[item].enchanted then
self.__settings.enchanted = aliases[item].enchanted
end
if aliases[item].name ~= nil then
local itemName = aliases[item].name
self:setPosition(self.__source.ids[itemName].pos)
if self.__source.ids[itemName].spriteSheet then
                local newSettings = require(types[self.__source.ids[itemName].spriteSheet]).settings
                self.__settings.classname = newSettings.classname
                self.__settings.size = newSettings.size
                self.__settings.tiles = newSettings.sheetsize / newSettings.size
                self.__settings.scale = newSettings.scale
                self.__settings.autoScale = newSettings.autoscale
end
end
end
     else
     else
         self.__settings.title = item;
         self.__settings.title = item;
end
 
if self.__source.ids[item] then
if aliases[item].name ~= nil then
self:setPosition(self.__source.ids[item].pos)
local itemName = aliases[item].name
if self.__source.ids[item].spriteSheet then
self:setPosition(self.__source.ids[itemName].pos)
              local newSettings = require(types[self.__source.ids[item].spriteSheet]).settings
if self.__source.ids[itemName].spriteSheet then
              self.__settings.classname = newSettings.classname
self.__settings.image = getSpriteSheet(self.__source.ids[itemName].spriteSheet)
              self.__settings.size = newSettings.size
              self.__settings.tiles = newSettings.sheetsize / newSettings.size
              self.__settings.scale = newSettings.scale
              self.__settings.autoScale = newSettings.autoscale
        end
else
self:setPosition(nil) --will use default
end
end
elseif self.__source.ids[item] then
self:setPosition(self.__source.ids[item].pos)
        if self.__source.ids[item].spriteSheet then
            self.__settings.image = getSpriteSheet(self.__source.ids[item].spriteSheet)
        end
else
self:setPosition(nil) --will use default
end
end
return self
return self
end
end
Line 218: Line 247:
if settings.image then
if settings.image then
append("background", settings.image.url)
append("background", settings.image.url)
append("mask-image", settings.image.url)
append("-webkit-mask-image", settings.image.url)
end
end


append ("background-size", settings.sheetWidth * settings.scale .. 'px auto')
append ("background-size", settings.sheetWidth * settings.scale .. 'px auto')
append ("mask-size", settings.sheetWidth * settings.scale .. 'px auto')
append ("-webkit-mask-size", settings.sheetWidth * settings.scale .. 'px auto')


local t = settings.size * settings.scale .. 'px'
local t = settings.size * settings.scale .. 'px'
Line 232: Line 265:
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')
 
append("mask-position", '-' .. left .. 'px -' .. top .. 'px')
append("-webkit-mask-position", '-' .. left .. 'px -' .. top .. 'px')


return table.concat( styles, "; " )
return table.concat( styles, "; " )
Line 256: Line 290:


local source = self.__source
local source = self.__source
sprite:addClass(source.settings.classname)
sprite:addClass(self.__settings.classname or source.settings.classname)


if self.__settings.hideTooltip ~= true then
if self.__settings.hideTooltip ~= true then
Line 266: Line 300:
if self.__settings.lore then
if self.__settings.lore then
sprite:attr( "data-lore", self.__settings.lore )
sprite:attr( "data-lore", self.__settings.lore )
end
if self.__settings.enchanted == "true" then
sprite:addClass("enchanted")
end
end


local styles =  self:calculateStyles()
local styles =  self:calculateStyles()
sprite:cssText( styles )
sprite:cssText( styles )
sprite:attr("data-styles", styles)
 
if self.__settings.link then
sprite = html:tag("span")
local link = self.__settings.link
if link:sub ( 1,1 ) == '[' then
local parentDiv = mw.html.create("a"):attr("href",link:sub ( 2,#link-1 ))
elseif link:sub ( 1,1 ) == '#' then
local section_id = self.__source.ids[itemName].section
for index, tab in pairs(self.__source.sections) do
if tab.id == section_id then
local parentDiv = mw.html.create("a"):attr("href","/" .. tab.name .. "/" .. link:sub ( 2,#link ))
end
end
elseif string.match(link, "%#") then
local parentDiv = mw.html.create("a"):attr("href","/" .. link)
else
local parentDiv = mw.html.create("a"):attr("href","/#" .. link)
end
parentDiv:node(sprite)
return parentDiv
end


return sprite
return sprite
Bureaucrats, Check users, emailconfirmed, Interface administrators, staff, Administrators, translation-admin, Widget editors
1,655

edits

Navigation menu