Module:Sprite: Difference between revisions

Jump to navigation Jump to search
It would help if EffectSprite aliases were accessed
No edit summary
(It would help if EffectSprite aliases were accessed)
(47 intermediate revisions by 3 users not shown)
Line 2: Line 2:


local Sprite = {}
local Sprite = {}
local aliasData = {
vanillaAliases = [[Module:InventorySlot/Aliases]],
gm4Aliases = [[Module:Gm4Sprite/Aliases]],
effectAliases = [[Module:EffectSprite/Aliases]]
}
Sprite.aliasData = aliasData
local vanillaAliases = mw.loadData( aliasData.vanillaAliases )
local gm4Aliases = mw.loadData( aliasData.gm4Aliases )
local effectAliases = mw.loadData( aliasData.effectAliases )
local aliases


local types = {
local types = {
inventory = [[Module:InvSprite]],
inventory = [[Module:InvSprite]],
gm4 = [[Module:Gm4Sprite]]
gm4 = [[Module:Gm4Sprite]],
effect = [[Module:EffectSprite]]
}
}


Line 56: Line 69:
error("Unknown type: " .. tostring(type))
error("Unknown type: " .. tostring(type))
end
end
o = {
o = {
__source = require(source),
__source = require(source),
Line 78: Line 92:


o = {
o = {
__source = {
settings = {}
},
__settings={
__settings={
size = size,
size = size,
Line 83: Line 100:
image = image,
image = image,
sheetWidth = size,
sheetWidth = size,
tiles = 1
tiles = 1,
name = name,
title = title,
lore = lore
}
}
}
}
Line 106: Line 126:
end
end


function Sprite:setItem(item)
function Sprite:setItem(item, type)
self.__settings.name = item;
    -- set aliases
if self.__source.ids[item] then
    if type == "gm4" then
self:setPosition(self.__source.ids[item].pos)
        aliases = gm4Aliases
else
elseif type == "effect" then
self:setPosition(nil) --will use default
aliases = effectAliases
    else
        aliases = vanillaAliases
    end
-- js-less plaintext title
self.__settings.name = item
 
-- js-modified color title with lore
    if aliases[item] then
if aliases[item].text then
self.__settings.lore = aliases[item].text
 
end
 
if aliases[item].title then
if #aliases[item].title == 2 then
        self.__settings.title= aliases[item].title .. aliases[item].name
else
self.__settings.title = aliases[item].title
end
elseif aliases[item].name then
self.__settings.title = aliases[item].name
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
self.__settings.image = getSpriteSheet(self.__source.ids[itemName].spriteSheet)
end
end
    else
        self.__settings.title = item;
 
if 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
end
return self
return self
end
end


function Sprite:Item(item)
function Sprite:Item(item, type)
local sprite = {}
local sprite = {}
setmetatable(sprite, {__index = self})
setmetatable(sprite, {__index = self})
Line 122: Line 184:
setmetatable(settings, {__index = self.__settings})
setmetatable(settings, {__index = self.__settings})
sprite.__settings = settings
sprite.__settings = settings
return sprite:setItem(item)
return sprite:setItem(item, type)
end
end


Line 137: Line 199:
function Sprite:SetSize(size)
function Sprite:SetSize(size)
self.__settings.scale = size / self.__settings.size
self.__settings.scale = size / self.__settings.size
return self
end
function Sprite:SetTitle(name)
self.__settings.title = name
return self
end
function Sprite:SetLore(text)
self.__settings.lore = text
return self
end
function Sprite:HideTooltip()
self.__settings.hideTooltip = true
return self
return self
end
end
Line 180: Line 257:


sprite:addClass("sprite")
sprite:addClass("sprite")
sprite:addClass("masterTooltip")
 
if self.__settings.hideTooltip ~= true then
sprite:addClass("masterTooltip")
end


local source = self.__source
local source = self.__source
sprite:addClass(source.settings.classname)
sprite:addClass(source.settings.classname)
sprite:attr( "title", self.__settings.name )
 
if self.__settings.hideTooltip ~= true then
sprite:attr( "title", self.__settings.name )
end
 
sprite:attr( "data-title", self.__settings.title )
if self.__settings.lore then
sprite:attr( "data-lore", self.__settings.lore )
end


local styles =  self:calculateStyles()
local styles =  self:calculateStyles()
Bureaucrats, Check users, emailconfirmed, Interface administrators, staff, Administrators, translation-admin, Widget editors
1,633

edits

Navigation menu