Модуль:Prototypes/Роль/Лодаут: различия между версиями

мНет описания правки
мНет описания правки
Строка 15: Строка 15:
     local results = {}
     local results = {}
     local role = nil
     local role = nil
     for _, r in ipairs(gearRoleLoadout) do
     for _, r in ipairs(gearRoleLoadout) do
         if r.id == roleId then
         if r.id == roleId then
Строка 21: Строка 22:
         end
         end
     end
     end
     if not role then
     if not role then
         return 'Роль с id "' .. roleId .. '" не найдена'
         return 'Роль с id "' .. roleId .. '" не найдена'
     end
     end
     for _, groupId in ipairs(role.groups or {}) do
     for _, groupId in ipairs(role.groups or {}) do
         local group = nil
         local group = nil
Строка 33: Строка 36:
         end
         end
         if group then
         if group then
            if type(group.loadouts) == "string" then
                local success, decoded = pcall(mw.text.jsonDecode, group.loadouts)
                if success and type(decoded) == "table" then
                    group.loadouts = decoded
                else
                    group.loadouts = {}
                end
            end
             for _, loadoutId in ipairs(group.loadouts or {}) do
             for _, loadoutId in ipairs(group.loadouts or {}) do
                 local loadout = nil
                 local loadout = nil
Строка 59: Строка 71:
                                                                 extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|department-" .. req.department .. "}}}}</b>: " .. req.time .. "<br>"
                                                                 extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|department-" .. req.department .. "}}}}</b>: " .. req.time .. "<br>"
                                                             elseif req["!type"] == "RoleTimeRequirement" and req.role and req.time then
                                                             elseif req["!type"] == "RoleTimeRequirement" and req.role and req.time then
                                                                 extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|".. req.role .. "}}}}</b>: " .. req.time .. "<br>"
                                                                 extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|" .. req.role .. "}}}}</b>: " .. req.time .. "<br>"
                                                             end
                                                             end
                                                         end
                                                         end
Строка 72: Строка 84:
                         end
                         end
                         local infoOutput = ""
                         local infoOutput = ""
if extraInfo ~= "" then
                        if extraInfo ~= "" then
    infoOutput = '<div class="роль-лодаут__time">{{AltTooltip|[[Файл:Small_watch.png|link=]]|' .. extraInfo .. '}}</div>'
                            infoOutput = '<div class="роль-лодаут__time">{{AltTooltip|[[Файл:Small_watch.png|link=]]|' .. extraInfo .. '}}</div>'
end
                        end
table.insert(results, infoOutput .. '{{#invoke:Prototypes/Предмет/Содержание|image|' .. eqValue .. '}} [[File:Slot.png|64px|link=]]')
                        table.insert(results, infoOutput .. '{{#invoke:Prototypes/Предмет/Содержание|image|' .. eqValue .. '}} [[File:Slot.png|64px|link=]]')
                     end
                     end
                 end
                 end
Строка 81: Строка 93:
         end
         end
     end
     end
     local output = {}
     local output = {}
     for _, eq in ipairs(results) do
     for _, eq in ipairs(results) do
         table.insert(output, '<div class="роль-лодаут__item">' .. eq .. '</div>')
         table.insert(output, '<div class="роль-лодаут__item">' .. eq .. '</div>')
     end
     end
     return frame:preprocess(table.concat(output))
     return frame:preprocess(table.concat(output))
end
end


return p
return p