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

мНет описания правки
мНет описания правки
 
(не показано 86 промежуточных версий этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}


local eventData = mw.loadData("Модуль:IanComradeBot/prototypes/StationEvent.json/data")
-- Загрузка данных
local chemData = mw.loadData("Модуль:IanComradeBot/chem prototypes.json/data")
local seedsData = mw.loadData("Модуль:IanComradeBot/prototypes/seeds.json/data")


function p.eventStation(frame)
local function kelvinToCelsius(k)
     local args = frame.args
    return k - 273.15
     local idsStr = args.id or ""
end
     local name = args.name or ""
 
     local image = args.image or "test.png"
local function findSeedById(id, data)
     local description = args.description or "Нет описания"
    for _, seed in ipairs(data) do
     local out = ""
        if seed.id == id then
     local ids = {}
            return seed
     for id in string.gmatch(idsStr, '([^,]+)') do
        end
        table.insert(ids, mw.text.trim(id))
     end
    return nil
end
 
local function formatCharacteristics(seed)
     local parts = {
        ("[[Гидропоника#Потенция|Потенция]]: %s"):format(seed.potency or 1),
        ("[[Гидропоника#Урожайность|Урожайность]]: %s"):format(seed.yield),
        ("[[Гидропоника#Срок жизни|Срок жизни]]: %s"):format(seed.lifespan),
        ("[[Гидропоника#Созревание|Созревание]]: %s"):format(seed.maturation),
        ("[[Гидропоника#Производство|Производство]]: %s"):format(seed.production),
        ("[[Гидропоника#Стадии роста|Стадии роста]]: %s"):format(seed.growthStages or 6),
    }
     return table.concat(parts, '<br>')
end
 
local function formatConditions(seed)
    local parts = {
        ("[[Гидропоника#Потребление воды|Вода]]: %s"):format(seed.waterConsumption or 0.5),
        ("[[Гидропоника#Потребление нутриентов|Удобрение]]: %s"):format(seed.nutrientConsumption or 0.75),
        ("[[Гидропоника#Оптимальная температура|Темп.]]: %.2f°C"):format(kelvinToCelsius(seed.idealHeat or 293)),
     }
    return table.concat(parts, '<br>')
end
 
local function formatHarvestType(seed)
    return seed.harvestRepeat and "[[Гидропоника#Тип урожая|" .. tostring(seed.harvestRepeat) .. "]]" or "-"
end
local function formatHarvestType(seed)
     local harvestRepeat = seed.harvestRepeat
    if harvestRepeat == "Repeat" then
        return "[[Гидропоника#Тип урожая|Многолетнее]]"
    elseif harvestRepeat == "SelfHarvest" then
        return "[[Гидропоника#Тип урожая|Самосбор]]"
    else
        return "[[Гидропоника#Тип урожая|Однолетнее]]"
     end
end
 
local function formatChemicals(seed)
    if not seed.chemicals then return "-" end
     local list = {}
     for chemId, vals in pairs(seed.chemicals) do
        local entry = chemData[chemId]
        local chemName = entry and entry.name or chemId
        table.insert(list, string.format(
            "<li>[[Химия#chem_%s|%s]] (мин: %s, макс: %s, дел: %s)</li>",
            chemId, chemName, vals.Min or 0, vals.Max or 0, vals.PotencyDivisor or 1
        ))
     end
     end
    return "<ul>" .. table.concat(list) .. "</ul>"
end


    for _, searchId in ipairs(ids) do
local function formatMutations(seed, data)
        for _, event in ipairs(eventData) do
    if not seed.mutationPrototypes then return "-" end
            if event.id == searchId then
    local list = {}
                local cellEvent = '<div style="text-align:center;">'
    for _, mu in ipairs(seed.mutationPrototypes) do
                cellEvent = cellEvent .. "'''" .. name .. "'''<br>"
        local target = findSeedById(mu, data)
                cellEvent = cellEvent .. "<span style='color:#adadad'>'''" .. event.id .. "'''</span><br>"
        if target and target.productPrototypes then
                cellEvent = cellEvent .. '[[File:' .. image .. '|64px]]'
            for _, prod in ipairs(target.productPrototypes) do
                cellEvent = cellEvent .. '</div>'
                table.insert(list, ("<li>{{Предмет|%s|link=Гидропоника#{{#invoke:Entity Lookup|getname|%s}}}}</li>"):format(prod, prod))
                local advert = (event.StationEvent and event.StationEvent.startAnnouncement) or "Нет оповещения"
                local characteristicsList = ""
                local stationEvent = event.StationEvent or {}
                local characteristics = {
                    {"Вес", "Вес события в системе случайных событий (чем выше, тем чаще случается)", stationEvent.weight},
                    {"Мин. игроков", "Минимальное количество игроков для начала события", stationEvent.minimumPlayers},
                    {"Время старта", "Время с которого событие может начаться", (stationEvent.earliestStart and stationEvent.earliestStart .. " сек.")},
                    {"Длительность", "Длительность события в секундах", (stationEvent.duration and stationEvent.duration .. " сек.")}
                }
                for _, char in ipairs(characteristics) do
                    local charValue = char[3] or "Нет"
                    characteristicsList = characteristicsList .. "- " .. frame:expandTemplate{
                        title = "AltTooltip",
                        args = { char[1], char[2] }
                    } .. ": " .. charValue .. "<br>"
                end
                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
         end
     end
     end
    return "<ul>" .. table.concat(list) .. "</ul>"
end


     return frame:preprocess(out)
local function generateHeader()
     return [[
{| id="BOTANY" class="wikitable sortable mw-collapsible" style="width:100%;"
! rowspan="2" style="width:10%;" | Плод
! rowspan="2" class="unsortable" style="width:5%;" | Семена
! rowspan="2" class="unsortable" style="width:5%;" | Растение
! colspan="3" class="unsortable" style="width:30%;" id="no-highlight" | Характеристики
! rowspan="2" class="unsortable" style="width:30%;" | Содержит вещества
! rowspan="2" style="width:20%;" | Мутации
|-
! style="width:10%;" class="unsortable" | Рост
! style="width:10%;" class="unsortable" | Условия
! style="width:5%;" class="unsortable" | Тип сбора
]]
end
end


function p.eventCargo(frame)
local function generateFooter()
     local args = frame.args
     return "|}"
    local idsStr = args.id or ""
end
    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
function p.table(frame)
        table.insert(ids, mw.text.trim(id))
    local data = mw.loadData("Модуль:IanComradeBot/prototypes/seeds.json/data")
     end
     local rows = {}


     for _, searchId in ipairs(ids) do
     for _, seed in ipairs(data) do
         for _, event in ipairs(eventData) do
         local prodId = seed.productPrototypes[1]
            if event.id == searchId then
        local seedId = seed.packetPrototype
                local cellEvent = '<div style="text-align:center;">'
        local seedName = string.format('{{#invoke:Entity Lookup|getname|%s}}', seedId)
                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 anchor  = string.format('{{anchor|%s}}', seedName)
                local sender = cargo.sender or "Нет отправителя"
        local fruitImg = string.format(
                local cargoDescription = cargo.description or "Нет описания"
            '{{Предмет|%s|size=64px|vertical=1|imageTooltip=1|link=%s}}',
                local dest = cargo.dest or "Нет получателя"
            prodId, seedName
        )
        local seedImg  = string.format(
            '{{Предмет|%s|size=64px|vertical=1|imageTooltip=1|l=|link=%s}}',
            seedId, seedName
        )
        local plantImg = string.format(
            '{{Предмет|%s-harvest|size=64px|l=|link=%s}}',
            seedId, seedName
        )


                local advert = sender .. " " .. cargoDescription .. " " .. dest
        local colGrowth    = formatCharacteristics(seed)
        local colConditions = formatConditions(seed)
        local colHarvest    = formatHarvestType(seed)
        local colChemicals  = formatChemicals(seed)
        local colMutations  = formatMutations(seed, data)


                local giftsCell = ""
        local row = frame:preprocess(string.format(
                if cargo.gifts then
            [[|-
                    giftsCell = "<ul>"
            ! %s
                    for giftId, giftValue in pairs(cargo.gifts) do
            ! %s
                        giftsCell = giftsCell .. "<li>" .. giftId .. ": " .. giftValue .. "</li>"
            ! %s
                    end
            | %s
                    giftsCell = giftsCell .. "</ul>"
            | %s
                else
            | %s
                    giftsCell = "Нет подарков"
            | %s
                end
            | %s ]],
            fruitImg, seedImg, plantImg,
            colGrowth, colConditions, colHarvest,
            colChemicals, colMutations
        ))
        table.insert(rows, row)
    end


                local characteristicsList = ""
    return generateHeader() .. table.concat(rows, '\n') .. '\n' .. generateFooter()
end
 
function p.main(frame)
    local args = frame.args
    local id = args[1]
    local mode  = mw.text.trim(args[2] or ""):lower()
    local seed = findSeedById(id, seedsData)
    if not seed then return "" end


                out = out .. "|-\n"
    if mode  == "growth" then
                out = out .. "| " .. cellEvent .. "\n"
        return formatCharacteristics(seed)
                out = out .. "| {{#invoke:Ftl|main|translation|" .. advert .. "}}\n"
    elseif mode  == "conditions" then
                out = out .. "| " .. description .. "\n"
        return formatConditions(seed)
                out = out .. "| " .. characteristicsList .. "\n"
    elseif mode  == "harvest" then
                out = out .. "| " .. giftsCell .. "\n"
        return formatHarvestType(seed)
                break
    elseif mode  == "chemicals" then
            end
        return formatChemicals(seed)
         end
    elseif mode  == "mutations" then
        return formatMutations(seed, seedsData)
    else
         return ""
     end
     end
    return frame:preprocess(out)
end
end


return p
return p