Модуль:Entity Sprite
Материал из Space Station 14 Вики
local p = {}
-- Функция загрузки данных из JSON-страницы
local function loadData(filePath)
local page = mw.title.new(filePath)
if not page then
return nil
end
local content = page:getContent()
if not content then
return nil
end
return mw.text.jsonDecode(content)
end
-- Функция генерации текста для одного элемента JSON с HTML-разметкой
local function generateTemplate(entry)
if not entry.id or not entry.Sprite or not entry.Sprite.sprite then
return nil
end
-- Сначала создаем таблицу для частей HTML
local templateParts = {}
-- Добавляем каждый элемент в таблицу
table.insert(templateParts, "== Краткое описание ==")
table.insert(templateParts, "{{Файл")
table.insert(templateParts, "|Описание = ")
table.insert(templateParts, "|Id = " .. entry.id)
table.insert(templateParts, "|Сервера = {{abb|SS14}}")
table.insert(templateParts, "|Источник = ")
table.insert(templateParts, "|Путь = Resources/Textures/" .. entry.Sprite.sprite)
table.insert(templateParts, "|Теги = ")
table.insert(templateParts, "}}")
table.insert(templateParts, "== Лицензирование ==")
table.insert(templateParts, "{{CC-BY-SA-3.0}}")
-- Теперь соединяем все части в одну строку
return table.concat(templateParts, "\n")
end
-- Основная функция, формирующая результат для всех записей
function p.main(frame)
local filePath = frame.args[1] -- Путь к JSON
if not filePath then
return "Ошибка: Укажите путь к JSON-файлу."
end
local data = loadData(filePath)
if not data or type(data) ~= "table" then
return "Ошибка: Невозможно загрузить данные из JSON."
end
local result = {}
for _, entry in ipairs(data) do
local template = generateTemplate(entry)
if template then
table.insert(result, template)
end
end
-- Возвращаем все сгенерированные шаблоны
return table.concat(result, "\n")
end
return p