Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки Метка: ручная отмена |
||
| Строка 2: | Строка 2: | ||
-- Загрузка данных | -- Загрузка данных | ||
local function loadData(filePath) | local function loadData(filePath) | ||
local page = mw.title.new(filePath) | |||
local content = page and page:getContent() | |||
return content and mw.text.jsonDecode(content) or nil | |||
end | end | ||
| Строка 75: | Строка 70: | ||
end | end | ||
return nil | return nil | ||
end | end | ||
| Строка 112: | Строка 101: | ||
end | end | ||
local firstId = group[1].id | local firstId = group[1].id | ||
table.insert(result, "{{Entity Sprite/ | table.insert(result, mw.getCurrentFrame():preprocess("{{Entity Sprite/Repeat|" .. table.concat(idLinks, " ") .. "|" .. firstId .. "}}")) | ||
end | end | ||
end | end | ||
return | return table.concat(result, "\n") | ||
end | end | ||
-- Создаём индекс для путей | -- Создаём индекс для путей | ||
local function createSpritePathIndex(data) | 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 | ||
end | end | ||
return | return index | ||
end | end | ||
| Строка 240: | Строка 222: | ||
end | end | ||
return nil | 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, data, spritePathIndex) | local template = generateTemplate(entry, param, secondaryParam, data, spritePathIndex) | ||
if template then | if template then | ||
table.insert(result, template) | table.insert(result, template) | ||