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

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


-- Функция получения пути спрайта
-- Общая функция нечувствительного к регистру поиска поля
local function getSpritePath(entry)
local function findFieldInsensitive(tbl, fieldName)
    local function findFieldInsensitive(tbl, fieldName)
    for key, value in pairs(tbl) do
        for key, value in pairs(tbl) do
        if type(key) == "string" and mw.ustring.lower(key) == mw.ustring.lower(fieldName) then
            if type(key) == "string" and mw.ustring.lower(key) == mw.ustring.lower(fieldName) then
            return value
                return value
            end
         end
         end
        return nil
     end
     end
    return nil
end


-- Функция получения пути спрайта
local function getSpritePath(entry)
     local spriteBlock = findFieldInsensitive(entry, "Sprite") or findFieldInsensitive(entry, "Icon")
     local spriteBlock = findFieldInsensitive(entry, "Sprite") or findFieldInsensitive(entry, "Icon")
     if spriteBlock then
     if spriteBlock then
Строка 37: Строка 38:
-- Функция получения state
-- Функция получения state
local function getSpriteState(entry)
local function getSpriteState(entry)
     if entry.Sprite and entry.Sprite.state then
     local spriteBlock = findFieldInsensitive(entry, "Sprite")
        return entry.Sprite.state
    if spriteBlock then
    elseif entry.Sprite and entry.Sprite.layers then
        if spriteBlock.state then
        for _, layer in pairs(entry.Sprite.layers) do
            return spriteBlock.state
            if layer.state then
        elseif spriteBlock.layers then
                return layer.state
            for _, layer in pairs(spriteBlock.layers) do
                if layer.state then
                    return layer.state
                end
             end
             end
         end
         end
     end
     end
    local iconBlock = findFieldInsensitive(entry, "Icon")
    if iconBlock and iconBlock.state then
        return iconBlock.state
    end
     return nil
     return nil
end
end