Модуль:Entity Sprite: различия между версиями

мНет описания правки
мНет описания правки
 
Строка 19: Строка 19:
end
end


-- Функция получения пути спрайта (берёт основной sprite или первый найденный в layers)
-- Функция получения пути спрайта: сначала пытаем Icon.sprite, затем Sprite.sprite, затем первый layer.sprite
local function getSpritePath(entry)
local function getSpritePath(entry)
     local spriteBlock = findFieldInsensitive(entry, "Icon")
     local iconBlock = findFieldInsensitive(entry, "Icon")
                      or findFieldInsensitive(entry, "Sprite")
    if type(iconBlock) == "table" and iconBlock.sprite then
        return iconBlock.sprite
    end
 
    local spriteBlock = findFieldInsensitive(entry, "Sprite")
     if not spriteBlock then return nil end
     if not spriteBlock then return nil end


Строка 71: Строка 75:


     if iconBlock and iconBlock.state and isLayerVisibleAndShaded(iconBlock) then
     if iconBlock and iconBlock.state and isLayerVisibleAndShaded(iconBlock) then
         addState(iconBlock.state, spritePath)
        local s = (type(iconBlock) == "table" and iconBlock.sprite) or spritePath
         addState(iconBlock.state, s)
     else
     else
         local spriteBlock = findFieldInsensitive(entry, "Sprite")
         local spriteBlock = findFieldInsensitive(entry, "Sprite")
Строка 138: Строка 143:
                     local spritePath = item.sprite
                     local spritePath = item.sprite
                     local stateName = item.state
                     local stateName = item.state
                     local url = baseUrl .. spritePath .. "/" .. stateName .. ".png"
                     if spritePath then
                    table.insert(links, "[" .. url .. " " .. stateName .. "]")
                        local url = baseUrl .. spritePath .. "/" .. stateName .. ".png"
                        table.insert(links, "[" .. url .. " " .. stateName .. "]")
                    else
                        table.insert(links, stateName .. " Error: sprite not found")
                    end
                 end
                 end
                 return "(state: " .. table.concat(links, ", ") .. ")"
                 return "(state: " .. table.concat(links, ", ") .. ")"