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

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


     for _, entry in ipairs(data) do
     for _, entry in ipairs(data) do
         if entry.Sprite and entry.EntityStorageVisuals then
         local found = false
            local key = mw.text.jsonEncode({ Sprite = entry.Sprite, EntityStorageVisuals = entry.EntityStorageVisuals })
        for key, group in pairs(spriteGroups) do
             spriteGroups[key] = spriteGroups[key] or {}
            if deepEqual(entry.Sprite, group[1].Sprite) and deepEqual(entry.EntityStorageVisuals, group[1].EntityStorageVisuals) then
             table.insert(spriteGroups[key], entry.id)
                table.insert(group, entry)
                found = true
                break
             end
        end
 
        if not found then
             table.insert(spriteGroups, {entry})
         end
         end
     end
     end


     local result = {}
     local result = {}
     for _, ids in pairs(spriteGroups) do
     for _, group in pairs(spriteGroups) do
         if #ids > 1 then
         if #group > 1 then
             local idLinks = {}
             local idLinks = {}
             for _, id in ipairs(ids) do
             for _, entry in ipairs(group) do
                 table.insert(idLinks, "[[:Файл:" .. id .. ".png]]")
                 table.insert(idLinks, "[[:Файл:" .. entry.id .. ".png]]")
             end
             end
             local firstId = ids[1]
             local firstId = group[1].id
             table.insert(result, mw.getCurrentFrame():preprocess("{{Entity Sprite/Repeat|" .. table.concat(idLinks, " ") .. "|" .. firstId .. "}}"))
             table.insert(result, mw.getCurrentFrame():preprocess("{{Entity Sprite/Repeat|" .. table.concat(idLinks, " ") .. "|" .. firstId .. "}}"))
         end
         end