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

мНет описания правки
мНет описания правки
 
(не показаны 93 промежуточные версии этого же участника)
Строка 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.generateTable(frame)
local function kelvinToCelsius(k)
     local out = '{| id="highlighted-header-CM" class="wikitable sortable mw-collapsible" margin:0;"\n'
     return k - 273.15
    out = out .. '! Событие !! Оповещение !! Описание !! Характеристики\n'
end


     for _, event in ipairs(eventData) do
local function findSeedById(id, data)
         local eventName = event.name or event.id or "Неизвестно"
     for _, seed in ipairs(data) do
         local IIevent = '<div style="text-align:center;">'
         if seed.id == id then
         IIevent = IIevent .. "'''" .. eventName .. "'''<br>"
            return seed
         IIevent = IIevent .. "<span style='color:#adadad'>'''" .. (event.id or "Нет ID") .. "'''</span><br>"
         end
         IIevent = IIevent .. '[[File:test.png|64px]]'
    end
        IIevent = IIevent .. '</div>'
    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 advert = (event.StationEvent and event.StationEvent.startAnnouncement) or "Нет оповещения"
local function formatHarvestType(seed)
         local description = "Нет описания"
    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 characteristicsList = ""
local function formatChemicals(seed)
        local stationEvent = event.StationEvent or {}
    if not seed.chemicals then return "-" end
         local characteristics = {
    local list = {}
            {"Вес", "Вес события в системе случайных событий (чем выше, тем чаще случается)", stationEvent.weight},
    for chemId, vals in pairs(seed.chemicals) do
             {"Мин. игроков", "Минимальное количество игроков для начала события", stationEvent.minimumPlayers},
        local entry = chemData[chemId]
             {"Время старта", "Время с которого событие может начаться", (stationEvent.earliestStart and stationEvent.earliestStart .. " сек.")},
         local chemName = entry and entry.name or chemId
            {"Длительность", "Длительность события в секундах", (stationEvent.duration and stationEvent.duration .. " сек.")}
        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
    return "<ul>" .. table.concat(list) .. "</ul>"
end


        for _, char in ipairs(characteristics) do
local function formatMutations(seed, data)
            local charValue = char[3] or "N/A"
    if not seed.mutationPrototypes then return "-" end
             characteristicsList = characteristicsList .. "- " .. frame:expandTemplate{
    local list = {}
                title = "AltTooltip",
    for _, mu in ipairs(seed.mutationPrototypes) do
                args = { char[1], char[2] }
        local target = findSeedById(mu, data)
            } .. ": " .. charValue .. "<br>"
        if target and target.productPrototypes then
             for _, prod in ipairs(target.productPrototypes) do
                table.insert(list, ("<li>{{Предмет|%s|link=Гидропоника#{{#invoke:Entity Lookup|getname|%s}}}}</li>"):format(prod, prod))
            end
         end
         end
    end
    return "<ul>" .. table.concat(list) .. "</ul>"
end
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
local function generateFooter()
    return "|}"
end
function p.table(frame)
    local data = mw.loadData("Модуль:IanComradeBot/prototypes/seeds.json/data")
    local rows = {}
    for _, seed in ipairs(data) do
        local prodId = seed.productPrototypes[1]
        local seedId = seed.packetPrototype
        local seedName = string.format('{{#invoke:Entity Lookup|getname|%s}}', seedId)
        local anchor  = string.format('{{anchor|%s}}', seedName)
        local fruitImg = string.format(
            '{{Предмет|%s|size=64px|vertical=1|imageTooltip=1|link=%s}}',
            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 colGrowth    = formatCharacteristics(seed)
        local colConditions = formatConditions(seed)
        local colHarvest    = formatHarvestType(seed)
        local colChemicals  = formatChemicals(seed)
        local colMutations  = formatMutations(seed, data)


         out = out .. "|-\n"
         local row = frame:preprocess(string.format(
        out = out .. "| " .. IIevent .. "\n"
            [[|-
        out = out .. "| " .. advert .. "\n"
            ! %s
         out = out .. "| " .. description .. "\n"
            ! %s
         out = out .. "| " .. characteristicsList .. "\n"
            ! %s
            | %s
            | %s
            | %s
            | %s
            | %s ]],
            fruitImg, seedImg, plantImg,
            colGrowth, colConditions, colHarvest,
            colChemicals, colMutations
         ))
         table.insert(rows, row)
     end
     end


     out = out .. "|}"
     return generateHeader() .. table.concat(rows, '\n') .. '\n' .. generateFooter()
     return out
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
 
    if mode  == "growth" then
        return formatCharacteristics(seed)
    elseif mode  == "conditions" then
        return formatConditions(seed)
    elseif mode  == "harvest" then
        return formatHarvestType(seed)
    elseif mode  == "chemicals" then
        return formatChemicals(seed)
    elseif mode  == "mutations" then
        return formatMutations(seed, seedsData)
    else
        return ""
    end
end
end


return p
return p