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

мНет описания правки
мНет описания правки
Строка 12: Строка 12:
function p.main(frame)
function p.main(frame)
     local args = frame.args
     local args = frame.args
     local mode = args[1] or "radio"
     local itemId = args[1]
    local itemId = args[2]
      
      
     if not itemId or itemId == "" then
     if not itemId or itemId == "" then
Строка 20: Строка 19:


     local keySlots = {}
     local keySlots = {}
    local itemFound = nil
    for _, data in pairs(fillsData) do
        if data.id == itemId then
            itemFound = data
            break
        end
    end


     if mode == "radio" then
     if itemFound then
         local item
         if itemFound.ContainerFill
        for _, data in pairs(fillsData) do
          and itemFound.ContainerFill.containers
            if data.id == itemId then
          and itemFound.ContainerFill.containers.key_slots then
                item = data
            keySlots = itemFound.ContainerFill.containers.key_slots
                break
        else
             end
             keySlots = { itemId }
         end
         end
        if not item then
     else
            return ""
        end
        if not (item.ContainerFill and item.ContainerFill.containers and item.ContainerFill.containers.key_slots) then
            return ""
        end
        for _, key in ipairs(item.ContainerFill.containers.key_slots) do
            if key ~= "EncryptionKeyCommon" then
                table.insert(keySlots, key)
            end
        end
     elseif mode == "key" then
         keySlots = { itemId }
         keySlots = { itemId }
    else
        return "Ошибка: неизвестный режим '" .. mode .. "'."
     end
     end


Строка 65: Строка 58:


     local resultSpans = {}
     local resultSpans = {}
    local seenKeycodes = {}
     for _, channelName in ipairs(channels) do
     for _, channelName in ipairs(channels) do
         local radioRecord
         local radioRecord
Строка 76: Строка 70:
             local keycode = trimQuotes(radioRecord.keycode) or ""
             local keycode = trimQuotes(radioRecord.keycode) or ""
             local color  = trimQuotes(radioRecord.color)  or ""
             local color  = trimQuotes(radioRecord.color)  or ""
             local span = string.format('<span style="color: %s">%s</span>', color, keycode)
             if not seenKeycodes[keycode] then
            table.insert(resultSpans, span)
                seenKeycodes[keycode] = true
                local span = string.format('<span style="color: %s">%s</span>', color, keycode)
                table.insert(resultSpans, span)
            end
         else
         else
             return "Предупреждение: для канала '" .. channelName .. "' не найдены данные в radioData."
             return "Предупреждение: для канала '" .. channelName .. "' не найдены данные в radioData."