Модуль:Местонахождение: различия между версиями

мНет описания правки
м Замена текста — «IanComradeBot/prototypes/сargo.json/data» на «IanComradeBot/prototypes/cargo.json/data»
 
(не показаны 4 промежуточные версии этого же участника)
Строка 15: Строка 15:
local itemBorgData        = mw.loadData("Модуль:IanComradeBot/prototypes/ItemBorgModule.json/data")
local itemBorgData        = mw.loadData("Модуль:IanComradeBot/prototypes/ItemBorgModule.json/data")


local cargoData            = mw.loadData("Модуль:IanComradeBot/prototypes/сargo.json/base")
local cargoData            = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data")


local latheData            = mw.loadData("Модуль:IanComradeBot/prototypes/lathe.json/data")
local latheData            = mw.loadData("Модуль:IanComradeBot/prototypes/lathe.json/data")
Строка 74: Строка 74:
-- Формирование ссылки для роли/джоба (reverseEquipment)
-- Формирование ссылки для роли/джоба (reverseEquipment)
local function createJobLink(jobId)
local function createJobLink(jobId)
     local translation = "{{#invoke:Ftl|main|translation|" .. jobId .. "}}"
     local translation = "{{#invoke:Ftl|main|translation|Job" .. jobId .. "}}"
     return "[[" .. translation .. "|{{ucfirst:" .. translation .. "}}]]"
     return "[[" .. translation .. "|{{ucfirst:" .. translation .. "}}]]"
end
end
Строка 187: Строка 187:
     end
     end


     local results = {}
     local resultsMap = {}


     -- Обработка startingGear (gearData)
     -- Обработка startingGear (gearData)
     for _, gear in pairs(gearData) do
     for _, gear in pairs(gearData) do
        local currentGearId = gear.id or "Unknown"
         if gear.equipment then
         if gear.equipment then
             for slot, equipId in pairs(gear.equipment) do
             for slot, equipId in pairs(gear.equipment) do
                 if equipId == targetId and (not slotFilter or slot == slotFilter) then
                 if equipId == targetId and (not slotFilter or slot == slotFilter) then
                     local foundJob = nil
                     local gearId = gear.id
                     for jobId, job in pairs(jobData) do
                     if gearId then
                        if job.startingGear == currentGearId then
                        for _, job in ipairs(jobData) do
                            foundJob = jobId
                            if job.startingGear == gearId then
                             break
                                resultsMap[job.id] = true
                             end
                         end
                         end
                    end
                    if foundJob then
                        table.insert(results, createJobLink(foundJob))
                     end
                     end
                 end
                 end
Строка 209: Строка 206:
         end
         end
     end
     end
 
     -- loadout + loadoutGroup + roleLoadout
     -- Обработка loadout (loadoutData)
     for _, loadout in pairs(loadoutData) do
     for _, loadout in pairs(loadoutData) do
         if loadout.equipment then
         if loadout.equipment then
             for slot, equipId in pairs(loadout.equipment) do
             for slot, equipId in pairs(loadout.equipment) do
                 if equipId == targetId and (not slotFilter or slot == slotFilter) then
                 if equipId == targetId and (not slotFilter or slot == slotFilter) then
                    local foundGroupId = nil
                     for _, group in pairs(loadoutGroupData) do
                     for _, group in pairs(loadoutGroupData) do
                         if group.loadouts and type(group.loadouts) == "table" then
                         if group.loadouts and type(group.loadouts) == "table" then
                             for _, lId in ipairs(group.loadouts) do
                             for _, lId in ipairs(group.loadouts) do
                                 if lId == loadout.id then
                                 if lId == loadout.id then
                                     foundGroupId = group.id
                                     for _, role in pairs(gearRoleLoadout) do
                                    break
                                        if role.groups and type(role.groups) == "table" then
                                end
                                            for _, g in ipairs(role.groups) do
                            end
                                                if g == group.id then
                        end
                                                    local moduleKey = role.id:gsub("^Job", "")
                        if foundGroupId then break end
                                                    resultsMap[moduleKey] = true
                    end
                                                end
                    local foundJob = nil
                                            end
                    if foundGroupId then
                                         end
                        for _, role in pairs(gearRoleLoadout) do
                            if role.groups then
                                for _, g in ipairs(role.groups) do
                                    if g == foundGroupId then
                                        foundJob = role.id
                                         break
                                     end
                                     end
                                 end
                                 end
                             end
                             end
                            if foundJob then break end
                         end
                         end
                    end
                    if foundJob then
                        table.insert(results, createJobLink(foundJob))
                     end
                     end
                 end
                 end
             end
             end
         end
         end
    end
    -- Собираем результаты, убираем дубликаты
    local results = {}
    for jobId in pairs(resultsMap) do
        table.insert(results, createJobLink(jobId))
     end
     end


Строка 272: Строка 264:


     if #directCargo > 0 then
     if #directCargo > 0 then
local links = {}
        local links = {}
for _, storage in ipairs(directCargo) do
        for _, storage in ipairs(directCargo) do
table.insert(links, createCargoLink(storage))
            table.insert(links, createCargoLink(storage))
end
        end
return table.concat(links, ", ")
        return table.concat(links, ", ")
     end
     end