Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Отмена правки 61825, сделанной Pok (обсуждение) Метка: отмена |
||
| Строка 73: | Строка 73: | ||
return table.concat(result, "\n") | return table.concat(result, "\n") | ||
end | |||
-- Создаём индекс для путей | |||
local function createSpritePathIndex(data) | |||
local index = {} | |||
for _, entry in ipairs(data) do | |||
local spritePath = getSpritePath(entry) | |||
if spritePath then | |||
index[spritePath] = entry.id | |||
end | |||
end | |||
return index | |||
end | end | ||
| Строка 156: | Строка 168: | ||
end | end | ||
-- Обновляем основную функцию для использования индекса | |||
function p.main(frame) | function p.main(frame) | ||
local param = frame.args[1] | local param = frame.args[1] | ||
| Строка 176: | Строка 178: | ||
end | end | ||
-- Создаём индекс путей | -- Создаём индекс путей для быстрого поиска | ||
local | local spritePathIndex = createSpritePathIndex(data) | ||
if param == "repeat" then | if param == "repeat" then | ||
| Строка 183: | Строка 185: | ||
elseif param == "path" and secondaryParam then | elseif param == "path" and secondaryParam then | ||
-- Используем индекс для быстрого поиска | -- Используем индекс для быстрого поиска | ||
local | local entryId = spritePathIndex[secondaryParam] | ||
if id then | if entryId then | ||
-- Находим соответствующий шаблон | |||
for _, entry in ipairs(data) do | |||
if entry.id == entryId then | |||
return generateTemplate(entry, param, secondaryParam, data, spritePathIndex) | |||
end | |||
end | |||
end | end | ||
return nil | |||
elseif param == "image" or param == "path" then | elseif param == "image" or param == "path" then | ||
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, spritePathIndex) | ||
if template then | if template then | ||
table.insert(result, template) | table.insert(result, template) | ||