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