Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 32: | Строка 32: | ||
return true | return true | ||
end | |||
-- Получение пути спрайта | |||
local function getSpritePath(entry) | |||
return entry.Sprite and entry.Sprite.sprite or (entry.Icon and entry.Icon.sprite) | |||
end | end | ||
| Строка 72: | Строка 77: | ||
-- Генерация текста для элемента JSON | -- Генерация текста для элемента JSON | ||
local function generateTemplate(entry, param, secondaryParam, data) | local function generateTemplate(entry, param, secondaryParam, data) | ||
local spritePath = | local spritePath = getSpritePath(entry) | ||
if not entry.id or not spritePath then | if not entry.id or not spritePath then | ||
return nil | return nil | ||
| Строка 89: | Строка 94: | ||
if secondaryParam then | if secondaryParam then | ||
for _, entry in ipairs(data) do | for _, entry in ipairs(data) do | ||
local spritePath = | local spritePath = getSpritePath(entry) | ||
if spritePath == secondaryParam then | if spritePath == secondaryParam then | ||
return entry.id | return entry.id | ||
| Строка 128: | Строка 133: | ||
local tags = params.Tags or "" | local tags = params.Tags or "" | ||
local spritePath = | local spritePath = getSpritePath(entry) | ||
if not spritePath then | if not spritePath then | ||
return "" | return "" | ||
| Строка 161: | Строка 166: | ||
end | end | ||
if param == "repeat" then | if param == "repeat" then | ||
return generateRepeatTemplate(data) | return generateRepeatTemplate(data) | ||
elseif param == "path" and secondaryParam then | |||
for _, entry in ipairs(data) do | |||
local template = generateTemplate(entry, param, secondaryParam, data) | |||
if template then | |||
return template | |||
end | |||
end | |||
return nil | |||
else | else | ||
local result = {} | local result = {} | ||
for _, entry in ipairs(data) do | for _, entry in ipairs(data) do | ||
local template = generateTemplate(entry, param, secondaryParam) | local template = generateTemplate(entry, param, secondaryParam, data) | ||
if template then | if template then | ||
table.insert(result, template) | table.insert(result, template) | ||