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

мНет описания правки
мНет описания правки
Строка 111: Строка 111:
local function generateDefaultTemplate(data, params)
local function generateDefaultTemplate(data, params)
     local id = params.Id
     local id = params.Id
     if not id or id == "" then
     local description = params.Description or ""
        return "Ошибка: Не указан ID."
    local servers = params.Servers or ""
     end
    local source = params.Source or ""
    local tags = params.Tags or ""
 
    local spritePath = nil
    local path = params.Path
     local spritePath = nil


     -- Поиск записи с указанным ID
     -- Поиск записи с указанным ID
     local entry = nil
     local entry = nil
     for _, item in ipairs(data) do
     if id and id ~= "" then
        if tostring(item.id) == tostring(id) then
        for _, item in ipairs(data) do
            entry = item
            if tostring(item.id) == tostring(id) then
             break
                entry = item
                break
             end
         end
         end
     end
     end


     if not entry then
    -- Если запись не найдена, ничего не выводим
         return ""
     if entry then
         spritePath = getSpritePath(entry)
        if not spritePath then
            return ""
        end
     end
     end
 
      
     local description = params.Description or ""
     -- Если Path не указан, подставляем путь из User:IanComradeBot/prototypes/entity sprite.json
     local servers = params.Servers or ""
    local source = params.Source or ""
    local tags = params.Tags or ""
 
    local spritePath = getSpritePath(entry)
    if not spritePath then
        return ""
    end
 
    local path = params.Path
     if not path or path == "" then
     if not path or path == "" then
         path = "Resources/Textures/" .. spritePath
         path = "Resources/Textures/" .. (spritePath or "")
     end
     end