Модуль:Песочница/Pok: различия между версиями

мНет описания правки
мНет описания правки
Строка 3: Строка 3:
local eventData = mw.loadData("Модуль:IanComradeBot/prototypes/StationEvent.json/data")
local eventData = mw.loadData("Модуль:IanComradeBot/prototypes/StationEvent.json/data")
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data")
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data")
local function splitIds(idsStr)
    local ids = {}
    for id in string.gmatch(idsStr, '([^,]+)') do
        table.insert(ids, mw.text.trim(id))
    end
    return ids
end


local function buildCellEvent(name, image)
local function buildCellEvent(name, image)
Строка 39: Строка 31:


function p.eventStation(frame)
function p.eventStation(frame)
local searchId = args.id or ""
     local args = frame.args
     local args = frame.args
    local idsStr = args.id or ""
     local name = args.name or ""
     local name = args.name or ""
     local image = args.image or "test.png"
     local image = args.image or "test.png"
     local description = args.description or "Нет описания"
     local description = args.description or "Нет описания"
     local out = ""
     local out = ""
    local ids = splitIds(idsStr)
      
      
    for _, searchId in ipairs(ids) do
for _, event in ipairs(eventData) do
        for _, event in ipairs(eventData) do
        if event.id == searchId then
            if event.id == searchId then
            local cellEvent = buildCellEvent(name, image)
                local cellEvent = buildCellEvent(name, image)
            local advert = (event.StationEvent and event.StationEvent.startAnnouncement) or "Нет оповещения"
                local advert = (event.StationEvent and event.StationEvent.startAnnouncement) or "Нет оповещения"
            local characteristicsList = buildCharacteristicsList(frame, event.StationEvent or {})
                local characteristicsList = buildCharacteristicsList(frame, event.StationEvent or {})
 
               
            out = out .. "|-\n"
                out = out .. "|-\n"
            out = out .. "! " .. cellEvent .. "\n"
                out = out .. "! " .. cellEvent .. "\n"
            out = out .. "| {{#invoke:Ftl|main|translation|" .. advert .. "}}\n"
                out = out .. "| {{#invoke:Ftl|main|translation|" .. advert .. "}}\n"
            out = out .. "| " .. description .. "\n"
                out = out .. "| " .. description .. "\n"
            out = out .. "| " .. characteristicsList .. "\n"
                out = out .. "| " .. characteristicsList .. "\n"
            break
                break
            end
         end
         end
     end
     end
Строка 76: Строка 65:
     local ids = splitIds(idsStr)
     local ids = splitIds(idsStr)
      
      
    for _, searchId in ipairs(ids) do
for _, event in ipairs(eventData) do
        for _, event in ipairs(eventData) do
        if event.id == searchId then
            if event.id == searchId then
            local cellEvent = buildCellEvent(name, image)
                local cellEvent = buildCellEvent(name, image)
            local cargo = event.CargoGiftsRule or {}
                local cargo = event.CargoGiftsRule or {}
            local sender = cargo.sender or "Нет отправителя"
                local sender = cargo.sender or "Нет отправителя"
            local cargoDescription = cargo.description or "Нет описания"
                local cargoDescription = cargo.description or "Нет описания"
            local dest = cargo.dest or "Нет получателя"
                local dest = cargo.dest or "Нет получателя"
            local advert = "Поздравляем! {{#invoke:Ftl|main|translation|" .. sender .. "}} решили отправить {{#invoke:Ftl|main|translation|" .. cargoDescription .. "}} {{#invoke:Ftl|main|translation|" .. dest .. "}} станции. Всё прибудет со следующей партией груза."
                local advert = "Поздравляем! {{#invoke:Ftl|main|translation|" .. sender .. "}} решили отправить {{#invoke:Ftl|main|translation|" .. cargoDescription .. "}} {{#invoke:Ftl|main|translation|" .. dest .. "}} станции. Всё прибудет со следующей партией груза."
 
               
            local giftsCell = ""
                local giftsCell = ""
            if cargo.gifts then
                if cargo.gifts then
                for giftId, giftValue in pairs(cargo.gifts) do
                    for giftId, giftValue in pairs(cargo.gifts) do
                    local productFound = nil
                        local productFound = nil
                    for _, cargoItem in ipairs(cargoData) do
                        for _, cargoItem in ipairs(cargoData) do
                        if cargoItem.id == giftId then
                            if cargoItem.id == giftId then
                            productFound = cargoItem.product
                                productFound = cargoItem.product
                            break
                                break
                            end
                        end
                        if productFound then
                            giftsCell = giftsCell .. "- {{#invoke:Entity Lookup|getname|" .. productFound .. "}} x" .. giftValue .. "<br>"
                        else
                            giftsCell = giftsCell .. "Ошибка: id продукта не найден."
                         end
                         end
                     end
                     end
                else
                    if productFound then
                    giftsCell = "Нет подарков"
                        giftsCell = giftsCell .. "- {{#invoke:Entity Lookup|getname|" .. productFound .. "}} x" .. giftValue .. "<br>"
                    else
                        giftsCell = giftsCell .. "Ошибка: id продукта не найден."
                    end
                 end
                 end
            else
                giftsCell = "Нет подарков"
            end


                local characteristicsList = buildCharacteristicsList(frame, event.StationEvent or {})
            local characteristicsList = buildCharacteristicsList(frame, event.StationEvent or {})
                out = out .. "|-\n"
            out = out .. "|-\n"
                out = out .. "! " .. cellEvent .. "\n"
            out = out .. "! " .. cellEvent .. "\n"
                out = out .. "| " .. advert .. "\n"
            out = out .. "| " .. advert .. "\n"
                out = out .. "| " .. description .. "\n"
            out = out .. "| " .. description .. "\n"
                out = out .. "| " .. characteristicsList .. "\n"
            out = out .. "| " .. characteristicsList .. "\n"
                out = out .. "| " .. giftsCell .. "\n"
            out = out .. "| " .. giftsCell .. "\n"
                break
            break
            end
         end
         end
     end
     end