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

Материал из Space Station 14 Вики
мНет описания правки
Метка: ручная отмена
мНет описания правки
Строка 4: Строка 4:
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data")
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data")


local function buildCellEvent(name, image, id)
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 cell = '<div style="text-align:center;">'
     local cell = '<div style="text-align:center;">'
     cell = cell .. name .. "<br>"
     cell = cell .. "" .. name .. "<br>"
    cell = cell .. "<span style='color:#adadad'>" .. id .. "</span><br>"
     cell = cell .. '[[File:' .. image .. '|64px]]'
     cell = cell .. '[[File:' .. image .. '|64px]]'
     cell = cell .. '</div>'
     cell = cell .. '</div>'
Строка 14: Строка 21:


local function buildCharacteristicsList(frame, stationEvent)
local function buildCharacteristicsList(frame, stationEvent)
     return frame:expandTemplate{
     local list = ""
         title = "Prototypes/Механика/Случайный события",
    local characteristics = {
         args = {
         {"Вес", "Вес события в системе случайных событий (чем выше, тем чаще случается)", stationEvent.weight},
            weight = stationEvent.weight or "",
         {"Мин. игроков", "Минимальное количество игроков для начала события", stationEvent.minimumPlayers},
            minimumPlayers = stationEvent.minimumPlayers or "",
        {"Время старта", "Время с которого событие может начаться", (stationEvent.earliestStart and stationEvent.earliestStart .. " сек.")},
            earliestStart = stationEvent.earliestStart and (stationEvent.earliestStart) or "",
        {"Длительность", "Длительность события в секундах", (stationEvent.duration and stationEvent.duration .. " сек.")}
            duration = stationEvent.duration and (stationEvent.duration) or ""
        }
     }
     }
    for _, char in ipairs(characteristics) do
        local value = char[3] or "Нет"
        list = list .. "- " .. frame:expandTemplate{
            title = "AltTooltip",
            args = { char[1], char[2] }
        } .. ": " .. value .. "<br>"
    end
    return list
end
end


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

Версия от 23:47, 29 марта 2025

Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc

local p = {}

local eventData = mw.loadData("Модуль:IanComradeBot/prototypes/StationEvent.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 cell = '<div style="text-align:center;">'
    cell = cell .. "" .. name .. "<br>"
    cell = cell .. '[[File:' .. image .. '|64px]]'
    cell = cell .. '</div>'
    return cell
end

local function buildCharacteristicsList(frame, stationEvent)
    local list = ""
    local characteristics = {
        {"Вес", "Вес события в системе случайных событий (чем выше, тем чаще случается)", stationEvent.weight},
        {"Мин. игроков", "Минимальное количество игроков для начала события", stationEvent.minimumPlayers},
        {"Время старта", "Время с которого событие может начаться", (stationEvent.earliestStart and stationEvent.earliestStart .. " сек.")},
        {"Длительность", "Длительность события в секундах", (stationEvent.duration and stationEvent.duration .. " сек.")}
    }
    for _, char in ipairs(characteristics) do
        local value = char[3] or "Нет"
        list = list .. "- " .. frame:expandTemplate{
            title = "AltTooltip",
            args = { char[1], char[2] }
        } .. ": " .. value .. "<br>"
    end
    return list
end

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

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

    return frame:preprocess(out)
end

return p