Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 64: | Строка 64: | ||
return nil | return nil | ||
end | |||
-- Генерация шаблона по умолчанию | |||
local function generateDefaultTemplate(entry, params) | |||
local description = params.Description or "" | |||
local id = params.Id or entry.id | |||
local servers = params.Servers or "" | |||
local source = params.Source or "" | |||
local path = params.Path or entry.id | |||
local tags = params.Tags or "" | |||
local licensing = params.Licensing or "CC-BY-SA-3.0" | |||
-- Формируем шаблон | |||
return mw.getCurrentFrame():preprocess( | |||
"\n== Краткое описание ==\n" .. | |||
"{{Файл\n" .. | |||
"|Описание = " .. description .. "\n" .. | |||
"|Id = " .. id .. "\n" .. | |||
"|Сервера = " .. servers .. "\n" .. | |||
"|Источник = " .. source .. "\n" .. | |||
"|Путь = Resources/Textures/" .. path .. "\n" .. | |||
"|Теги = " .. tags .. "\n" .. | |||
"}}\n\n" .. | |||
"== Лицензирование ==\n" .. | |||
"{{" .. licensing .. "}}" | |||
) | |||
end | end | ||
| Строка 69: | Строка 95: | ||
function p.main(frame) | function p.main(frame) | ||
local param = frame.args[1] | local param = frame.args[1] | ||
local data = loadData('User:IanComradeBot/prototypes/entity sprite.json') | if not param then | ||
local data = loadData('User:IanComradeBot/prototypes/entity sprite.json') | |||
if not data or type(data) ~= 'table' then | |||
return 'Ошибка: Невозможно загрузить данные из JSON.' | |||
end | |||
local entry = data[1] | |||
if not entry then | |||
return 'Ошибка: Не найден элемент с таким ID.' | |||
end | |||
-- Генерация шаблона по умолчанию | |||
return generateDefaultTemplate(entry, frame.args) | |||
end | end | ||
-- Логика для других параметров, как "image", "license", "repeat" | |||
if param == "repeat" then | if param == "repeat" then | ||
local data = loadData('User:IanComradeBot/prototypes/entity sprite.json') | |||
if not data or type(data) ~= 'table' then | |||
return 'Ошибка: Невозможно загрузить данные из JSON.' | |||
end | |||
return generateRepeatTemplate(data) | return generateRepeatTemplate(data) | ||
else | else | ||
local data = loadData('User:IanComradeBot/prototypes/entity sprite.json') | |||
if not data or type(data) ~= 'table' then | |||
return 'Ошибка: Невозможно загрузить данные из JSON.' | |||
end | |||
local result = {} | local result = {} | ||
for _, entry in ipairs(data) do | for _, entry in ipairs(data) do | ||