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

Нет описания правки
мНет описания правки
Строка 12: Строка 12:
     end
     end
     return mw.text.jsonDecode(content)
     return mw.text.jsonDecode(content)
end
-- Проверка равенства двух таблиц
local function deepEqual(t1, t2)
    if t1 == t2 then return true end
    if type(t1) ~= "table" or type(t2) ~= "table" then return false end
    for k, v in pairs(t1) do
        if not deepEqual(v, t2[k]) then return false end
    end
    for k, v in pairs(t2) do
        if not deepEqual(v, t1[k]) then return false end
    end
    return true
end
end


Строка 18: Строка 34:
     local spriteGroups = {}
     local spriteGroups = {}


     -- Группировка спрайтов по пути
     -- Группировка спрайтов по параметрам
     for _, entry in ipairs(data) do
     for _, entry in ipairs(data) do
         if entry.Sprite and entry.Sprite.sprite then
         if entry.Sprite and entry.EntityStorageVisuals then
             local spritePath = entry.Sprite.sprite
             local key = mw.text.jsonEncode({ Sprite = entry.Sprite, EntityStorageVisuals = entry.EntityStorageVisuals })
             spriteGroups[spritePath] = spriteGroups[spritePath] or {}
             spriteGroups[key] = spriteGroups[key] or {}
             table.insert(spriteGroups[spritePath], entry.id)
             table.insert(spriteGroups[key], entry.id)
         end
         end
     end
     end
Строка 29: Строка 45:
     -- Формирование шаблона
     -- Формирование шаблона
     local result = {}
     local result = {}
     for spritePath, ids in pairs(spriteGroups) do
     for _, ids in pairs(spriteGroups) do
         if #ids > 1 then -- Только если есть повторяющиеся спрайты
         if #ids > 1 then -- Только если есть повторяющиеся спрайты
             local idLinks = {}
             local idLinks = {}