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

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


local function getSpriteStates(entry)
local function getSpriteStates(entry)
     local spriteBlock = getInsensitiveKey(entry, "Sprite")
    local result = {}
     local spriteBlock = findFieldInsensitive(entry, "Sprite")
     if spriteBlock and spriteBlock.layers then
     if spriteBlock and spriteBlock.layers then
        local states = {}
         for _, layer in ipairs(spriteBlock.layers) do
         for _, layer in ipairs(spriteBlock.layers) do
             if not(layer.visible == false) and layer.state then
             if layer.visible == false then
                 table.insert(states, layer.state)
            elseif layer.state and layer.sprite then
                table.insert(result, { state = layer.state, sprite = layer.sprite })
            elseif layer.state then
                 table.insert(result, { state = layer.state, sprite = getSpritePath(entry) })
             end
             end
         end
         end
        if #states > 0 then
            return states
        end
     end
     end
     local iconBlock = getInsensitiveKey(entry, "Icon")
    if #result > 0 then
        return result
    end
 
     local iconBlock = findFieldInsensitive(entry, "Icon")
     if iconBlock and iconBlock.state then
     if iconBlock and iconBlock.state then
         return { iconBlock.state }
         return { { state = iconBlock.state, sprite = getSpritePath(entry) } }
     end
     end
     if spriteBlock and spriteBlock.state then
     if spriteBlock and spriteBlock.state then
         return { spriteBlock.state }
         return { { state = spriteBlock.state, sprite = getSpritePath(entry) } }
     end
     end
     return nil
     return nil
end
end