Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 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. | if entry.Sprite and entry.EntityStorageVisuals then | ||
local | local key = mw.text.jsonEncode({ Sprite = entry.Sprite, EntityStorageVisuals = entry.EntityStorageVisuals }) | ||
spriteGroups[ | spriteGroups[key] = spriteGroups[key] or {} | ||
table.insert(spriteGroups[ | table.insert(spriteGroups[key], entry.id) | ||
end | end | ||
end | end | ||
| Строка 29: | Строка 45: | ||
-- Формирование шаблона | -- Формирование шаблона | ||
local result = {} | local result = {} | ||
for | for _, ids in pairs(spriteGroups) do | ||
if #ids > 1 then -- Только если есть повторяющиеся спрайты | if #ids > 1 then -- Только если есть повторяющиеся спрайты | ||
local idLinks = {} | local idLinks = {} | ||