Модуль:Entity Sprite/all: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 39: | Строка 39: | ||
end | end | ||
local function | local function getInsensitiveKey(t, target) | ||
for | target = target:lower() | ||
if type( | for k, v in pairs(t) do | ||
return | if type(k) == "string" and k:lower() == target then | ||
return v | |||
end | end | ||
end | end | ||
| Строка 49: | Строка 50: | ||
local function getSpritePath(entry) | local function getSpritePath(entry) | ||
local iconField = | local iconField = getInsensitiveKey(entry, "Icon") | ||
local spriteField = | local spriteField = getInsensitiveKey(entry, "Sprite") | ||
if iconField and iconField.sprite then | if iconField and iconField.sprite then | ||
| Строка 67: | Строка 68: | ||
local function getSpriteStates(entry) | local function getSpriteStates(entry) | ||
local spriteBlock = getInsensitiveKey(entry, "Sprite") | |||
local spriteBlock = | |||
if spriteBlock and spriteBlock.layers then | if spriteBlock and spriteBlock.layers then | ||
local states = {} | |||
for _, layer in ipairs(spriteBlock.layers) do | for _, layer in ipairs(spriteBlock.layers) do | ||
if layer.visible == false then | if layer.visible == false then | ||
elseif layer.state then | elseif layer.state then | ||
table.insert( | table.insert(states, layer.state) | ||
end | end | ||
end | |||
if #states > 0 then | |||
return states | |||
end | end | ||
end | end | ||
local iconBlock = getInsensitiveKey(entry, "Icon") | |||
local iconBlock = | |||
if iconBlock and iconBlock.state then | if iconBlock and iconBlock.state then | ||
return { | return { iconBlock.state } | ||
end | end | ||
if spriteBlock and spriteBlock.state then | if spriteBlock and spriteBlock.state then | ||
return { | return { spriteBlock.state } | ||
end | end | ||
return nil | return nil | ||
end | end | ||
| Строка 101: | Строка 97: | ||
local found = false | local found = false | ||
for _, group in pairs(spriteGroups) do | for _, group in pairs(spriteGroups) do | ||
if deepEqual( | if deepEqual(getInsensitiveKey(entry, "Sprite"), getInsensitiveKey(group[1], "Sprite")) and | ||
deepEqual(entry.EntityStorageVisuals, group[1].EntityStorageVisuals) and | deepEqual(entry.EntityStorageVisuals, group[1].EntityStorageVisuals) and | ||
deepEqual( | deepEqual(getInsensitiveKey(entry, "Icon"), getInsensitiveKey(group[1], "Icon")) then | ||
table.insert(group, entry) | table.insert(group, entry) | ||
found = true | found = true | ||