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

мНет описания правки
мНет описания правки
Строка 3: Строка 3:
local eventData = mw.loadData("Модуль:IanComradeBot/prototypes/StationEvent.json/data")
local eventData = mw.loadData("Модуль:IanComradeBot/prototypes/StationEvent.json/data")


function p.stationEvent(frame)
function p.eventStation(frame)
     local args = frame.args
     local args = frame.args
     local idsStr = args.id or ""
     local idsStr = args.id or ""
Строка 44: Строка 44:
                 out = out .. "| " .. description .. "\n"
                 out = out .. "| " .. description .. "\n"
                 out = out .. "| " .. characteristicsList .. "\n"
                 out = out .. "| " .. characteristicsList .. "\n"
                break
            end
        end
    end
    return frame:preprocess(out)
end
function p.eventCargo(frame)
    local args = frame.args
    local idsStr = args.id or ""
    local name = args.name or ""
    local image = args.image or "test.png"
    local description = args.description or "Нет описания"
    local out = ""
    local ids = {}
    for id in string.gmatch(idsStr, '([^,]+)') do
        table.insert(ids, mw.text.trim(id))
    end
    for _, searchId in ipairs(ids) do
        for _, event in ipairs(eventData) do
            if event.id == searchId then
                local cellEvent = '<div style="text-align:center;">'
                cellEvent = cellEvent .. "'''" .. name .. "'''<br>"
                cellEvent = cellEvent .. "<span style='color:#adadad'>'''" .. event.id .. "'''</span><br>"
                cellEvent = cellEvent .. '[[File:' .. image .. '|64px]]'
                cellEvent = cellEvent .. '</div>'
                local cargo = event.CargoGiftsRule or {}
                local sender = cargo.sender or "Нет отправителя"
                local cargoDescription = cargo.description or "Нет описания"
                local dest = cargo.dest or "Нет получателя"
                local advert = sender .. " " .. cargoDescription .. " " .. dest
                local giftsCell = ""
                if cargo.gifts then
                    giftsCell = "<ul>"
                    for giftId, giftValue in pairs(cargo.gifts) do
                        giftsCell = giftsCell .. "<li>" .. giftId .. ": " .. giftValue .. "</li>"
                    end
                    giftsCell = giftsCell .. "</ul>"
                else
                    giftsCell = "Нет подарков"
                end
                local characteristicsList = ""
                out = out .. "|-\n"
                out = out .. "| " .. cellEvent .. "\n"
                out = out .. "| {{#invoke:Ftl|main|translation|" .. advert .. "}}\n"
                out = out .. "| " .. description .. "\n"
                out = out .. "| " .. characteristicsList .. "\n"
                out = out .. "| " .. giftsCell .. "\n"
                 break
                 break
             end
             end