Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) мНет описания правки Метка: ручная отмена |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 155: | Строка 155: | ||
"}}\n" | "}}\n" | ||
) | ) | ||
end | |||
-- Создание хэш-таблицы для пути | |||
local function createPathIndex(data) | |||
local pathIndex = {} | |||
for _, entry in ipairs(data) do | |||
-- Если есть несколько слоев | |||
if entry.Sprite.layers then | |||
for _, layer in ipairs(entry.Sprite.layers) do | |||
local spritePath = entry.Sprite.sprite | |||
local state = layer.state | |||
if spritePath then | |||
local path = spritePath .. "/" .. state | |||
pathIndex[path] = entry.id | |||
end | |||
end | |||
else | |||
-- Если есть только один путь | |||
local spritePath = entry.Sprite.sprite | |||
local state = entry.Sprite.state | |||
if spritePath and state then | |||
local path = spritePath .. "/" .. state | |||
pathIndex[path] = entry.id | |||
end | |||
end | |||
end | |||
return pathIndex | |||
end | end | ||
| Строка 166: | Строка 193: | ||
return 'Ошибка: Невозможно загрузить данные из JSON.' | return 'Ошибка: Невозможно загрузить данные из JSON.' | ||
end | end | ||
-- Индексация данных по пути | |||
local pathIndex = createPathIndex(data) | |||
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 | ||
-- Используем оптимизированный поиск по пути | |||
local id = pathIndex[secondaryParam] | |||
if id then | |||
return id | |||
else | |||
return "Не найдено" | |||
end | end | ||
elseif param == "image" or param == "path" then | elseif param == "image" or param == "path" then | ||
local result = {} | local result = {} | ||