Модуль:Entity Sprite: различия между версиями

мНет описания правки
мНет описания правки
Строка 4: Строка 4:
local function loadData(filePath)
local function loadData(filePath)
     local page = mw.title.new(filePath)
     local page = mw.title.new(filePath)
     if not page then
     if not page then return nil end
        return nil
    end
     local content = page:getContent()
     local content = page:getContent()
     if not content then
     if not content then return nil end
        return nil
    end
     return mw.text.jsonDecode(content)
     return mw.text.jsonDecode(content)
end
end
Строка 20: Строка 16:
     end
     end
      
      
    -- Используем preprocess, чтобы активировать шаблон для имени
     local nameTemplate = frame:preprocess(string.format("{{#invoke:Entity Lookup|getname|%s}}", entry.id))
     local nameTemplate = frame:preprocess(string.format("{{#invoke:Entity Lookup|getname|%s}}", entry.id))
      
      
    -- Генерируем строку шаблона с минимизированными тегами
     return string.format(
     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>
<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,
         nameTemplate, entry.id, entry.Sprite.sprite
        entry.id,
        entry.Sprite.sprite
     )
     )
end
end
Строка 40: Строка 36:
     end
     end
      
      
     local result = {}
    -- Используем конкатенацию без временного хранения всех данных в массиве
     local result = ""
    local append = function(s) result = result .. s end


     -- Проходим по всем элементам и генерируем шаблон
     -- Проходим по всем элементам и генерируем строки
     for _, entry in ipairs(data) do
     for _, entry in ipairs(data) do
         local template = generateTemplate(entry, frame)
         local template = generateTemplate(entry, frame)
         if template then
         if template then
             table.insert(result, template)
             append(template) -- Генерируем и добавляем строку
         end
         end
     end
     end
      
      
     return table.concat(result, "\n")
     return result -- Возвращаем сгенерированный результат
end
end


return p
return p