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

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


---------------------------------------------------------------------
-- Загрузка данных
-- Загрузка данных  
local chemData = mw.loadData("Модуль:IanComradeBot/chem prototypes.json/data")
---------------------------------------------------------------------
local seedsData = mw.loadData("Модуль:IanComradeBot/prototypes/seeds.json/data")
local itemData          = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data")
local tableData          = mw.loadData("Модуль:IanComradeBot/prototypes/table.json/data")
local gearData          = mw.loadData("Модуль:IanComradeBot/startingGear.json/data")
local jobData            = mw.loadData("Модуль:IanComradeBot/job.json/data")
local gearRoleLoadout    = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data")
local loadoutData        = mw.loadData("Модуль:IanComradeBot/loadout.json/data")
local loadoutGroupData  = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data")
local cargoData          = mw.loadData("Модуль:IanComradeBot/prototypes/сargo.json/base")
local latheData          = mw.loadData("Модуль:IanComradeBot/prototypes/lathe.json/data")
local recipeData        = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipes.json/data")
local researchData      = mw.loadData("Модуль:IanComradeBot/prototypes/research.json/data")
local materialData      = mw.loadData("Модуль:IanComradeBot/prototypes/materials.json/data")
local chemDataLathe      = mw.loadData("Модуль:IanComradeBot/chem prototypes.json/data")
local vendingMachinesData = mw.loadData("Модуль:IanComradeBot/prototypes/vending machines.json/data")
local inventoriesData    = mw.loadData("Модуль:IanComradeBot/prototypes/vending machines/inventories.json/data")


---------------------------------------------------------------------
local function kelvinToCelsius(k)
-- Функции для обратного поиска
    return k - 273.15
---------------------------------------------------------------------
end


local function searchItemInStructure(struct, targetId)
local function findSeedById(id, data)
    if type(struct) ~= "table" then
     for _, seed in ipairs(data) do
        return false
         if seed.id == id then
    end
             return seed
    if struct.id and struct.id == targetId then
        return true
    end
     for _, v in pairs(struct) do
         if type(v) == "table" then
             if searchItemInStructure(v, targetId) then
                return true
            end
         end
         end
     end
     end
     return false
     return nil
end
end


---------------------------------------------------------------------
local function formatCharacteristics(seed)
 
     local parts = {
local function findRelatedTables(initialList)
        ("[[Гидропоника#Потенция|Потенция]]: %s"):format(seed.potency or 1),
     local results = {}
         ("[[Гидропоника#Урожайность|Урожайность]]: %s"):format(seed.yield),
    local function recursiveSearch(tblId)
         ("[[Гидропоника#Срок жизни|Срок жизни]]: %s"):format(seed.lifespan),
         if results[tblId] then
        ("[[Гидропоника#Созревание|Созревание]]: %s"):format(seed.maturation),
            return
        ("[[Гидропоника#Производство|Производство]]: %s"):format(seed.production),
         end
         ("[[Гидропоника#Стадии роста|Стадии роста]]: %s"):format(seed.growthStages or 6),
        results[tblId] = true
     }
        for id, entry in pairs(tableData) do
     return table.concat(parts, '<br>')
            if type(entry) == "table" then
                for _, value in pairs(entry) do
                    if type(value) == "table" and value.tableId and value.tableId == tblId then
                        recursiveSearch(id)
                    end
                end
            end
         end
    end
    for _, tblId in ipairs(initialList) do
        recursiveSearch(tblId)
     end
    local res = {}
     for id in pairs(results) do
        table.insert(res, id)
    end
    return res
end
end


local function searchTableIdInStructure(struct, tableIds)
local function formatConditions(seed)
     if type(struct) ~= "table" then
     local parts = {
        return false
        ("[[Гидропоника#Потребление воды|Вода]]: %s"):format(seed.waterConsumption or 0.5),
    end
         ("[[Гидропоника#Потребление нутриентов|Удобрение]]: %s"):format(seed.nutrientConsumption or 0.75),
    if struct.tableId then
         ("[[Гидропоника#Оптимальная температура|Темп.]]: %.2f°C"):format(kelvinToCelsius(seed.idealHeat or 293)),
         for _, tid in ipairs(tableIds) do
     }
            if struct.tableId == tid then
     return table.concat(parts, '<br>')
                return true
            end
        end
    end
    for _, v in pairs(struct) do
         if type(v) == "table" then
            if searchTableIdInStructure(v, tableIds) then
                return true
            end
        end
     end
     return false
end
end


---------------------------------------------------------------------
local function formatHarvestType(seed)
-- Общая логика поиска хранилищ, содержащих указанный targetId
     return seed.harvestRepeat and "[[Гидропоника#Тип урожая|" .. tostring(seed.harvestRepeat) .. "]]" or "-"
---------------------------------------------------------------------
local function findMatchingStorages(targetId)
     local initialTables = {}
    for key, tblEntry in pairs(tableData) do
        if type(tblEntry) == "table" then
            if searchItemInStructure(tblEntry, targetId) then
                local tableId = tblEntry.id or key
                table.insert(initialTables, tableId)
            end
        end
    end
 
    local allRelatedTables = {}
    if #initialTables > 0 then
        allRelatedTables = findRelatedTables(initialTables)
    end
 
    local matchingStorages = {}
    for storageKey, storage in pairs(itemData) do
        if type(storage) == "table" then
            local found = false
 
            if storage.EntityTableContainerFill
              and storage.EntityTableContainerFill.containers then
                if searchTableIdInStructure(storage.EntityTableContainerFill.containers, allRelatedTables) then
                    found = true
                end
            end
 
            if searchItemInStructure(storage, targetId) then
                found = true
            end
 
            if found then
                local actualId = storage.id or storageKey
                table.insert(matchingStorages, actualId)
            end
        end
    end
 
    return matchingStorages
end
end
 
local function formatHarvestType(seed)
---------------------------------------------------------------------
     local harvestRepeat = seed.harvestRepeat
function p.reverseContained(frame)
     if harvestRepeat == "Repeat" then
     local targetId = frame.args[2]
         return "[[Гидропоника#Тип урожая|Многолетнее]]"
     if not targetId or targetId == "" then
     elseif harvestRepeat == "SelfHarvest" then
         return "Ошибка: не указан id предмета для обратного поиска."
         return "[[Гидропоника#Тип урожая|Самосбор]]"
     end
    else
 
         return "[[Гидропоника#Тип урожая|Однолетнее]]"
    local matchingStorages = findMatchingStorages(targetId)
    local filteredStorages = {}
    for _, sid in ipairs(matchingStorages) do
        local skip = false
        for _, cargo in pairs(cargoData) do
            if type(cargo) == "table" and cargo.product == sid then
                skip = true
                break
            end
         end
        if not skip then
            table.insert(filteredStorages, sid)
         end
     end
     end
    if #filteredStorages == 0 then
        return ""
    end
local filteredStoragesLinks = {}
for _, storage in ipairs(filteredStorages) do
    table.insert(filteredStoragesLinks, "[[{{#invoke:Entity Lookup|getname|" .. storage .. "}}|{{#invoke:Entity Lookup|getname|" .. storage .. "}}]]")
end
    return "Находится в хранилище: " .. table.concat(filteredStoragesLinks, ", ")
end
end


---------------------------------------------------------------------
local function formatChemicals(seed)
function p.reverseEquipment(frame)
    if not seed.chemicals then return "-" end
     local targetId = frame.args[2]
     local list = {}
    local slotFilter = frame.args[3]
    for chemId, vals in pairs(seed.chemicals) do
    if not targetId or targetId == "" then
        local entry = chemData[chemId]
         return "Ошибка: не указан id оборудования для обратного поиска."
        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>"
     local results = {}
 
    -- Обработка startingGear (gearData)
    for _, gear in pairs(gearData) do
        local currentGearId = gear.id or "Unknown"
        if gear.equipment then
            for slot, equipId in pairs(gear.equipment) do
                if equipId == targetId and (not slotFilter or slot == slotFilter) then
                    local foundJob = nil
                    for jobId, job in pairs(jobData) do
                        if job.startingGear == currentGearId then
                            foundJob = jobId
                            break
                        end
                    end
                    if foundJob then
                        table.insert(results, "{{ucfirst:{{#invoke:Ftl|main|translation|" .. foundJob .. "}}}}")
                    end
                end
            end
        end
    end
 
    -- Обработка loadout (loadoutData)
    for _, loadout in pairs(loadoutData) do
        if loadout.equipment then
            for slot, equipId in pairs(loadout.equipment) do
                if equipId == targetId and (not slotFilter or slot == slotFilter) then
                    local foundGroupId = nil
                    -- Поиск группы в loadoutGroupData, в которой присутствует loadout.id
                    for _, group in pairs(loadoutGroupData) do
                        if group.loadouts and type(group.loadouts) == "table" then
                            for _, lId in ipairs(group.loadouts) do
                                if lId == loadout.id then
                                    foundGroupId = group.id
                                    break
                                end
                            end
                        end
                        if foundGroupId then break end
                    end
                    local foundJob = nil
                    -- Поиск роли в gearRoleLoadout, где группы содержат найденный id группы
                    if foundGroupId then
                        for _, role in pairs(gearRoleLoadout) do
                            if role.groups then
                                for _, g in ipairs(role.groups) do
                                    if g == foundGroupId then
                                        foundJob = role.id
                                        break
                                    end
                                end
                            end
                            if foundJob then break end
                        end
                    end
                    if foundJob then
                        table.insert(results, "{{ucfirst:{{#invoke:Ftl|main|translation|" .. foundJob .. "}}}}")
                    end
                end
            end
        end
    end
 
    if #results == 0 then
        return "Оборудование с id " .. targetId .. " не найдено в наборах экипировки."
    end
 
    return "Начальная экипировка роли: " .. table.concat(results, ", ")
end
end


---------------------------------------------------------------------
local function formatMutations(seed, data)
function p.reverseCargo(frame)
     if not seed.mutationPrototypes then return "-" end
    local searchValue = frame.args[2]
     local list = {}
     if not searchValue or searchValue == "" then
     for _, mu in ipairs(seed.mutationPrototypes) do
        return "Ошибка: не указано значение для поиска в режиме cargo."
         local target = findSeedById(mu, data)
    end
         if target and target.productPrototypes then
 
            for _, prod in ipairs(target.productPrototypes) do
    -- Сначала ищем прямые совпадения в cargoData по product
                table.insert(list, ("<li>{{Предмет|%s|link=Гидропоника#{{#invoke:Entity Lookup|getname|%s}}}}</li>"):format(prod, prod))
     local directCargo = {}
     for _, entry in ipairs(cargoData) do
         if entry.product == searchValue then
            table.insert(directCargo, entry.id)
         end
    end
 
    if #directCargo > 0 then
        return "Найденные записи cargo: " .. table.concat(directCargo, ", ")
    end
 
    -- Если не найдено прямых совпадений, выполняем обратный поиск как в reverseContained,
    -- но оставляем только те хранилища, которые присутствуют в cargoData (т.е. имеют product равный их id)
    local matchingStorages = findMatchingStorages(searchValue)
    local cargoStorages = {}
    for _, sid in ipairs(matchingStorages) do
        for _, cargo in pairs(cargoData) do
            if type(cargo) == "table" and cargo.product == sid then
                table.insert(cargoStorages, sid)
                break
             end
             end
         end
         end
     end
     end
 
     return "<ul>" .. table.concat(list) .. "</ul>"
     if #cargoStorages == 0 then
        return ""
    end
   
local cargoLinks = {}
for _, storage in ipairs(cargoStorages) do
    table.insert(cargoLinks, "[[Таблица грузов#{{#invoke:Entity Lookup|getname|" .. storage .. "}}|{{#invoke:Entity Lookup|getname|" .. storage .. "}}]]")
end
return "Заказ груза: " .. table.concat(cargoLinks, ", ")
end
end


---------------------------------------------------------------------
local function generateHeader()
local function getRecipeById(recipeId)
     return [[
     for _, recipe in ipairs(recipeData) do
{| id="BOTANY" class="wikitable sortable mw-collapsible" style="width:100%;"
        if recipe.id == recipeId then
! rowspan="2" style="width:10%;" | Плод
            return recipe
! rowspan="2" class="unsortable" style="width:5%;" | Семена
        end
! rowspan="2" class="unsortable" style="width:5%;" | Растение
    end
! colspan="3" class="unsortable" style="width:30%;" id="no-highlight" | Характеристики
    return nil
! 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.reverseLathe(frame)
local function generateFooter()
    local targetResult = frame.args[2]
     return "|}"
    if not targetResult or targetResult == "" then
        return "Ошибка: не указан результат рецепта для обратного поиска."
    end
 
    local matchingLathes = {}
    local function checkRecipes(recipeIds)
        for _, recipeId in ipairs(recipeIds or {}) do
            local recipe = getRecipeById(recipeId)
            if recipe and recipe.result == targetResult then
                return true
            end
        end
        return false
    end
 
    for _, lathe in ipairs(latheData) do
        local found = false
        if lathe.Lathe then
            if checkRecipes(lathe.Lathe.staticRecipes) or checkRecipes(lathe.Lathe.dynamicRecipes) then
                found = true
            end
        end
        if not found and lathe.EmagLatheRecipes then
            if checkRecipes(lathe.EmagLatheRecipes.emagStaticRecipes) or checkRecipes(lathe.EmagLatheRecipes.emagDynamicRecipes) then
                found = true
            end
        end
        if found and lathe.id then
            table.insert(matchingLathes, lathe.id)
        end
    end
 
     if #matchingLathes == 0 then
        return ""
    end
 
local matchingLathesLinks = {}
for _, storage in ipairs(matchingLathes) do
    table.insert(matchingLathesLinks, "[[{{#invoke:Entity Lookup|getname|" .. storage .. "}}|{{#invoke:Entity Lookup|getname|" .. storage .. "}}]]")
end
 
    return "Может быть напечатано на станке: " .. table.concat(matchingLathesLinks, ", ")
end
end


---------------------------------------------------------------------
function p.table(frame)
function p.reverseVending(frame)
     local data = mw.loadData("Модуль:IanComradeBot/prototypes/seeds.json/data")
     local invMode = frame.args[2] or ""  -- режим поиска: "inventory", "contraband", "emag" или пустая строка для всех
     local rows = {}
     local targetId = frame.args[3]
    if not targetId or targetId == "" then
        return "Ошибка: не указан id предмета для обратного поиска в торговых автоматах."
    end


    local matchingInventoryIds = {}
     for _, seed in ipairs(data) do
    -- Перебираем все инвентарные записи
         local prodId = seed.productPrototypes[1]
     for _, inventory in pairs(inventoriesData) do
        local seedId = seed.packetPrototype
         if inventory.id then
        local seedName = string.format('{{#invoke:Entity Lookup|getname|%s}}', seedId)
            local found = false
            if (invMode == "inventory" or invMode == "" or not invMode) and inventory.startingInventory and type(inventory.startingInventory) == "table" then
                if inventory.startingInventory[targetId] then
                    found = true
                end
            end
            if (invMode == "contraband" or invMode == "" or not invMode) and inventory.contrabandInventory and type(inventory.contrabandInventory) == "table" then
                if inventory.contrabandInventory[targetId] then
                    found = true
                end
            end
            if (invMode == "emag" or invMode == "" or not invMode) and inventory.emaggedInventory and type(inventory.emaggedInventory) == "table" then
                if inventory.emaggedInventory[targetId] then
                    found = true
                end
            end
            if found then
                table.insert(matchingInventoryIds, inventory.id)
            end
        end
    end


    if #matchingInventoryIds == 0 then
        local anchor  = string.format('{{anchor|%s}}', seedName)
         return ""
        local fruitImg = string.format(
    end
            '{{Предмет|%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 matchingVendingMachines = {}
        local colGrowth     = formatCharacteristics(seed)
    for _, vm in pairs(vendingMachinesData) do
        local colConditions = formatConditions(seed)
         if vm.VendingMachine and vm.VendingMachine.pack then
        local colHarvest    = formatHarvestType(seed)
            local packId = vm.VendingMachine.pack
         local colChemicals  = formatChemicals(seed)
            for _, invId in ipairs(matchingInventoryIds) do
        local colMutations  = formatMutations(seed, data)
                if packId == invId then
                    if vm.id then
                        table.insert(matchingVendingMachines, vm.id)
                    end
                    break
                end
            end
        end
    end


    if #matchingVendingMachines == 0 then
        local row = frame:preprocess(string.format(
         return ""
            [[|-
            ! %s
            ! %s
            ! %s
            | %s
            | %s
            | %s
            | %s
            | %s ]],
            fruitImg, seedImg, plantImg,
            colGrowth, colConditions, colHarvest,
            colChemicals, colMutations
        ))
         table.insert(rows, row)
     end
     end
   
    local matchingVendingMachinesLinks = {}
for _, storage in ipairs(matchingVendingMachines) do
    table.insert(matchingVendingMachinesLinks, "[[{#invoke:Entity Lookup|getname|" .. storage .. "}}|{{#invoke:Entity Lookup|getname|" .. storage .. "}}]]")
end


     return "Содержится в торгомате: " .. table.concat(matchingVendingMachinesLinks, ", ")
     return generateHeader() .. table.concat(rows, '\n') .. '\n' .. generateFooter()
end
end


---------------------------------------------------------------------
-- Основная функция модуля
---------------------------------------------------------------------
function p.main(frame)
function p.main(frame)
     local mode = frame.args[1]
     local args = frame.args
     if not mode or mode == "" then
    local id = args[1]
        return "Ошибка: не указан режим обратного поиска. Доступные режимы: reverseContained, reverseEquipment, reverseCargo, reverseLathe, reverseVending."
     local mode = mw.text.trim(args[2] or ""):lower()
    end
    local seed = findSeedById(id, seedsData)
    if not seed then return "" end


     if mode == "reverseContained" then
     if mode == "growth" then
         return mw.getCurrentFrame():preprocess(p.reverseContained(frame))
         return formatCharacteristics(seed)
     elseif mode == "reverseEquipment" then
     elseif mode == "conditions" then
         return mw.getCurrentFrame():preprocess(p.reverseEquipment(frame))
         return formatConditions(seed)
     elseif mode == "reverseCargo" then
     elseif mode == "harvest" then
         return mw.getCurrentFrame():preprocess(p.reverseCargo(frame))
         return formatHarvestType(seed)
     elseif mode == "reverseLathe" then
     elseif mode == "chemicals" then
         return mw.getCurrentFrame():preprocess(p.reverseLathe(frame))
         return formatChemicals(seed)
     elseif mode == "reverseVending" then
     elseif mode == "mutations" then
         return mw.getCurrentFrame():preprocess(p.reverseVending(frame))
         return formatMutations(seed, seedsData)
     else
     else
         return "Неизвестный режим: " .. mode .. ". Доступные режимы: reverseContained, reverseEquipment, reverseCargo, reverseLathe, reverseVending."
         return ""
     end
     end
end
end


return p
return p

Текущая версия от 23:43, 26 ноября 2025

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

local p = {}

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

local function kelvinToCelsius(k)
    return k - 273.15
end

local function findSeedById(id, data)
    for _, seed in ipairs(data) do
        if seed.id == id then
            return seed
        end
    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
    return "<ul>" .. table.concat(list) .. "</ul>"
end

local function formatMutations(seed, data)
    if not seed.mutationPrototypes then return "-" end
    local list = {}
    for _, mu in ipairs(seed.mutationPrototypes) do
        local target = findSeedById(mu, data)
        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
    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)

        local row = frame:preprocess(string.format(
            [[|-
            ! %s 
            ! %s 
            ! %s 
            | %s 
            | %s 
            | %s 
            | %s 
            | %s ]],
            fruitImg, seedImg, plantImg,
            colGrowth, colConditions, colHarvest,
            colChemicals, colMutations
        ))
        table.insert(rows, row)
    end

    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

    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

return p