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

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


local function getInsensitiveKey(t, target)
local function findFieldInsensitive(tbl, fieldName)
    target = target:lower()
     for key, value in pairs(tbl) do
     for k, v in pairs(t) do
         if type(key) == "string" and mw.ustring.lower(key) == mw.ustring.lower(fieldName) then
         if type(k) == "string" and k:lower() == target then
             return value
             return v
         end
         end
     end
     end
Строка 50: Строка 49:


local function getSpritePath(entry)
local function getSpritePath(entry)
     local iconField = getInsensitiveKey(entry, "Icon")
     local iconField = findFieldInsensitive(entry, "Icon")
     local spriteField = getInsensitiveKey(entry, "Sprite")
     local spriteField = findFieldInsensitive(entry, "Sprite")
      
      
     if iconField and iconField.sprite then
     if iconField and iconField.sprite then
Строка 102: Строка 101:
         local found = false
         local found = false
         for _, group in pairs(spriteGroups) do
         for _, group in pairs(spriteGroups) do
             if deepEqual(getInsensitiveKey(entry, "Sprite"), getInsensitiveKey(group[1], "Sprite")) and
             if deepEqual(findFieldInsensitive(entry, "Sprite"), findFieldInsensitive(group[1], "Sprite")) and
               deepEqual(entry.EntityStorageVisuals, group[1].EntityStorageVisuals) and
               deepEqual(entry.EntityStorageVisuals, group[1].EntityStorageVisuals) and
               deepEqual(getInsensitiveKey(entry, "Icon"), getInsensitiveKey(group[1], "Icon")) then
               deepEqual(findFieldInsensitive(entry, "Icon"), findFieldInsensitive(group[1], "Icon")) then
                 table.insert(group, entry)
                 table.insert(group, entry)
                 found = true
                 found = true