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

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


     return table.concat(result, "\n")
     return table.concat(result, "\n")
end
-- Создаём индекс для путей
local function createSpritePathIndex(data)
    local index = {}
    for _, entry in ipairs(data) do
        local spritePath = getSpritePath(entry)
        if spritePath then
            index[spritePath] = entry.id
        end
    end
    return index
end
end


Строка 168: Строка 156:
end
end


-- Обновляем основную функцию для использования индекса
local function createPathIndex(data)
    local pathIndex = {}
    for _, entry in ipairs(data) do
        local spritePath = getSpritePath(entry)
        if spritePath then
            pathIndex[spritePath] = entry.id
        end
    end
    return pathIndex
end
 
function p.main(frame)
function p.main(frame)
     local param = frame.args[1]
     local param = frame.args[1]
Строка 178: Строка 176:
     end
     end


     -- Создаём индекс путей для быстрого поиска
     -- Создаём индекс путей
     local spritePathIndex = createSpritePathIndex(data)
     local pathIndex = createPathIndex(data)


     if param == "repeat" then
     if param == "repeat" then
Строка 185: Строка 183:
     elseif param == "path" and secondaryParam then
     elseif param == "path" and secondaryParam then
         -- Используем индекс для быстрого поиска
         -- Используем индекс для быстрого поиска
         local entryId = spritePathIndex[secondaryParam]
         local id = pathIndex[secondaryParam]
         if entryId then
         if id then
             -- Находим соответствующий шаблон
             return id
            for _, entry in ipairs(data) do
        else
                if entry.id == entryId then
             return nil
                    return generateTemplate(entry, param, secondaryParam, data, spritePathIndex)
                end
             end
         end
         end
        return nil
     elseif param == "image" or param == "path" then
     elseif param == "image" or param == "path" then
         local result = {}
         local result = {}
         for _, entry in ipairs(data) do
         for _, entry in ipairs(data) do
             local template = generateTemplate(entry, param, secondaryParam, data, spritePathIndex)
             local template = generateTemplate(entry, param, secondaryParam, data, pathIndex)
             if template then
             if template then
                 table.insert(result, template)
                 table.insert(result, template)