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

Материал из Space Station 14 Вики
мНет описания правки
Метка: ручная отмена
Нет описания правки
 
(не показано 105 промежуточных версий этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs


local eventData = mw.loadData("Модуль:IanComradeBot/prototypes/StationEvent.json/data")
function p.main(frame)
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data")
    local args = getArgs(frame, { removeBlanks = false })
    local name = args[1] or ""
    local attributes = args[2] or ""
    if name == "" then
        return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
    end
    local ext = (args["ext"] or "png"):gsub("^%.", "")
    local namespace = args["namespace"] or "Файл"
    local max = tonumber(args["max"]) or 50
    local include_base = (args["base"] ~= "no")


local function buildCellEvent(name, image, id)
     local found = {}
     local cell = '<div style="text-align:center;">'
    cell = cell .. name .. "<br>"
    cell = cell .. "<span style='color:#adadad'>" .. id .. "</span><br>"
    cell = cell .. '[[File:' .. image .. '|64px]]'
    cell = cell .. '</div>'
    return cell
end


local function buildCharacteristicsList(frame, stationEvent)
     if include_base then
     return frame:expandTemplate{
         local t = mw.title.new("Файл:" .. name .. "." .. ext)
         title = "Prototypes/Механика/Случайный события",
        if t and t.exists then
        args = {
             table.insert(found, "")
            weight = stationEvent.weight or "",
         end
            minimumPlayers = stationEvent.minimumPlayers or "",
     end
            earliestStart = stationEvent.earliestStart and (stationEvent.earliestStart) or "",
             duration = stationEvent.duration and (stationEvent.duration) or ""
         }
     }
end


function p.eventStation(frame)
     for i = 1, max do
     local args = frame.args
         local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
    local searchId = args.id or ""
        if t and t.exists then
    local name = args.name or ""
             table.insert(found, "-" .. i)
    local image = args.image or ""
    local description = args.description or "Нет описания"
    local out = ""
   
    for _, event in ipairs(eventData) do
         if event.id == searchId then
            local cellEvent = buildCellEvent(name, image, searchId)
            local advert = (event.StationEvent and event.StationEvent.startAnnouncement) or ""
            local characteristicsList = buildCharacteristicsList(frame, event.StationEvent or {})
 
            out = out .. "|-\n"
            out = out .. "! " .. cellEvent .. "\n"
            if advert ~= "" then
                out = out .. "| {{#invoke:Ftl|main|translation|" .. advert .. "}}\n"
            else
                out = out .. "| Происходит без объявления\n"
             end
            out = out .. "| " .. description .. "\n"
            out = out .. "| " .. characteristicsList
            break
         end
         end
     end
     end


     return frame:preprocess(out)
     if #found == 0 then
end
        return ""
    end


function p.eventCargo(frame)
     local before = "[[" .. namespace .. ":" .. name
    local args = frame.args
    local after = "." .. ext .. "|" .. attributes .. "]]"
     local searchId = args.id or ""
    local name = args.name or ""
    local image = args.image or ""
    local out = ""
   
    for _, event in ipairs(eventData) do
        if event.id == searchId then
            local cellEvent = buildCellEvent(name, image, searchId)
            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 = ""
    local parts = {}
            if cargo.gifts then
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
                for giftId, giftValue in pairs(cargo.gifts) do
    for _, suf in ipairs(found) do
                    local productFound = nil
        table.insert(parts, "<option>" .. suf .. "</option>")
                    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 .. "}}|{{#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 .. "| " .. giftsCell .. "\n"
            out = out .. "| " .. characteristicsList
            break
        end
     end
     end
    table.insert(parts, "</choose>")


     return frame:preprocess(out)
     return frame:preprocess(table.concat(parts, "\n"))
end
end


return p
return p

Текущая версия от 02:52, 17 марта 2026

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

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.main(frame)
    local args = getArgs(frame, { removeBlanks = false })
    local name = args[1] or ""
    local attributes = args[2] or ""
    if name == "" then
        return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
    end
    local ext = (args["ext"] or "png"):gsub("^%.", "") 
    local namespace = args["namespace"] or "Файл"
    local max = tonumber(args["max"]) or 50
    local include_base = (args["base"] ~= "no")

    local found = {}

    if include_base then
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
        if t and t.exists then
            table.insert(found, "")
        end
    end

    for i = 1, max do
        local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
        if t and t.exists then
            table.insert(found, "-" .. i)
        end
    end

    if #found == 0 then
        return ""
    end

    local before = "[[" .. namespace .. ":" .. name
    local after = "." .. ext .. "|" .. attributes .. "]]"

    local parts = {}
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
    for _, suf in ipairs(found) do
        table.insert(parts, "<option>" .. suf .. "</option>")
    end
    table.insert(parts, "</choose>")

    return frame:preprocess(table.concat(parts, "\n"))
end

return p