Модуль:Entity Sprite
Материал из Space Station 14 Вики
local p = {}
-- Загрузка данных
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
local function generateTemplate(entry, frame)
if not entry.id or not entry.Sprite or not entry.Sprite.sprite then
return nil
end
-- Используем preprocess, чтобы активировать шаблон для имени
local nameTemplate = frame:preprocess(string.format("{{#invoke:Entity Lookup|getname|%s}}", entry.id))
-- Генерируем строку шаблона с минимизированными тегами
return string.format(
[[
<div class="e-s_i">%s</div><div class="e-s_s">Id = %s<br>Путь = Resources/Textures/%s<br></div><div class="copy-icon">📋</div><br>
]],
nameTemplate, entry.id, entry.Sprite.sprite
)
end
-- Основная функция модуля
function p.main(frame)
-- Загрузка данных из JSON-файла
local data = loadData('User:IanComradeBot/prototypes/entity sprite.json')
if not data or type(data) ~= 'table' then
return 'Ошибка: Невозможно загрузить данные из JSON.'
end
-- Используем конкатенацию без временного хранения всех данных в массиве
local result = ""
local append = function(s) result = result .. s end
-- Проходим по всем элементам и генерируем строки
for _, entry in ipairs(data) do
local template = generateTemplate(entry, frame)
if template then
append(template) -- Генерируем и добавляем строку
end
end
return result -- Возвращаем сгенерированный результат
end
return p