Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) Отмена правки 61825, сделанной Pok (обсуждение) Метка: отмена |
Pok (обсуждение | вклад) Нет описания правки Метка: ручная отмена |
||
| Строка 75: | Строка 75: | ||
end | end | ||
-- | -- Генерация текста для элемента JSON | ||
local function generateTemplate(entry, param, secondaryParam, data) | |||
local function generateTemplate(entry, param, secondaryParam, data | |||
local spritePath = getSpritePath(entry) | local spritePath = getSpritePath(entry) | ||
if not entry.id or not spritePath then | if not entry.id or not spritePath then | ||
| Строка 105: | Строка 93: | ||
elseif param == "path" then | elseif param == "path" then | ||
if secondaryParam then | if secondaryParam then | ||
for _, entry in ipairs(data) do | |||
local spritePath = getSpritePath(entry) | |||
if spritePath == secondaryParam then | |||
return entry.id | |||
end | |||
end | end | ||
return nil | return nil | ||
| Строка 168: | Строка 157: | ||
end | end | ||
-- | -- Основная функция модуля | ||
function p.main(frame) | function p.main(frame) | ||
local param = frame.args[1] | local param = frame.args[1] | ||
| Строка 177: | Строка 166: | ||
return 'Ошибка: Невозможно загрузить данные из JSON.' | return 'Ошибка: Невозможно загрузить данные из JSON.' | ||
end | end | ||
if param == "repeat" then | if param == "repeat" then | ||
return generateRepeatTemplate(data) | return generateRepeatTemplate(data) | ||
elseif param == "path" and secondaryParam then | 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 | ||
end | end | ||
| Строка 198: | Строка 180: | ||
local result = {} | local result = {} | ||
for _, entry in ipairs(data) do | for _, entry in ipairs(data) do | ||
local template = generateTemplate(entry, param, secondaryParam, data | local template = generateTemplate(entry, param, secondaryParam, data) | ||
if template then | if template then | ||
table.insert(result, template) | table.insert(result, template) | ||