Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 9: | Строка 9: | ||
end | end | ||
-- | -- Общая функция нечувствительного к регистру поиска поля | ||
local function findFieldInsensitive(tbl, fieldName) | |||
for key, value in pairs(tbl) do | |||
if type(key) == "string" and mw.ustring.lower(key) == mw.ustring.lower(fieldName) then | |||
return value | |||
end | end | ||
end | end | ||
return nil | |||
end | |||
-- Функция получения пути спрайта | |||
local function getSpritePath(entry) | |||
local spriteBlock = findFieldInsensitive(entry, "Sprite") or findFieldInsensitive(entry, "Icon") | local spriteBlock = findFieldInsensitive(entry, "Sprite") or findFieldInsensitive(entry, "Icon") | ||
if spriteBlock then | if spriteBlock then | ||
| Строка 37: | Строка 38: | ||
-- Функция получения state | -- Функция получения state | ||
local function getSpriteState(entry) | local function getSpriteState(entry) | ||
local spriteBlock = findFieldInsensitive(entry, "Sprite") | |||
if spriteBlock then | |||
if spriteBlock.state then | |||
return spriteBlock.state | |||
elseif spriteBlock.layers then | |||
for _, layer in pairs(spriteBlock.layers) do | |||
if layer.state then | |||
return layer.state | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
local iconBlock = findFieldInsensitive(entry, "Icon") | |||
if iconBlock and iconBlock.state then | |||
return iconBlock.state | |||
end | |||
return nil | return nil | ||
end | end | ||