Модуль:Prototypes/Механика/Растение: различия между версиями

Материал из Space Station 14 Вики
мНет описания правки
Метки: с мобильного устройства из мобильной версии через расширенный мобильный режим
Нет описания правки
 
(не показано 12 промежуточных версий этого же участника)
Строка 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 function kelvinToCelsius(k)
local function kelvinToCelsius(k)
Строка 16: Строка 20:
local function formatCharacteristics(seed)
local function formatCharacteristics(seed)
     local parts = {
     local parts = {
         ("[[Гидропоника#Потенция|Потенция]]: %s"):format(seed.potency or 0),
         ("[[Гидропоника#Потенция|Потенция]]: %s"):format(seed.potency or 1),
         ("[[Гидропоника#Урожайность|Урожайность]]: %s"):format(seed.yield or 0),
         ("[[Гидропоника#Урожайность|Урожайность]]: %s"):format(seed.yield),
         ("[[Гидропоника#Продолжительность жизни|Время жизни]]: %s"):format(seed.lifespan or 0),
         ("[[Гидропоника#Срок жизни|Срок жизни]]: %s"):format(seed.lifespan),
         ("[[Гидропоника#Скорость созревани|Созревания]]: %s"):format(seed.maturation or 0),
         ("[[Гидропоника#Созревание|Созревание]]: %s"):format(seed.maturation),
         ("[[Гидропоника#Продуктивность|Продуктивность]]: %s"):format(seed.production or 0),
         ("[[Гидропоника#Производство|Производство]]: %s"):format(seed.production),
         ("[[Гидропоника#Стадии роста|Стадии роста]]: %s"):format(seed.growthStages or 0),
         ("[[Гидропоника#Стадии роста|Стадии роста]]: %s"):format(seed.growthStages or 6),
     }
     }
     return table.concat(parts, " <br> ")
     return table.concat(parts, '<br>')
end
end


local function formatConditions(seed)
local function formatConditions(seed)
    local tempC = kelvinToCelsius(seed.idealHeat or 273.15)
     local parts = {
     local parts = {
         ("[[Гидропоника#|Вода]]: %s"):format(seed.waterConsumption or "-"),
         ("[[Гидропоника#Потребление воды|Вода]]: %s"):format(seed.waterConsumption or 0.5),
         ("[[Гидропоника#|Удобрения]]: %s"):format(seed.nutrientConsumption or "-"),
         ("[[Гидропоника#Потребление нутриентов|Удобрение]]: %s"):format(seed.nutrientConsumption or 0.75),
         ("[[Гидропоника#|Температура]]: %.2f°C"):format(tempC),
         ("[[Гидропоника#Оптимальная температура|Темп.]]: %.2f°C"):format(kelvinToCelsius(seed.idealHeat or 293)),
        ("[[Гидропоника#|Освещения]]: %s"):format(seed.idealLight or "-"),
     }
     }
     return table.concat(parts, " <br> ")
     return table.concat(parts, '<br>')
end
end


local function formatHarvestType(seed)
local function formatHarvestType(seed)
     return seed.harvestRepeat and "[[Гидропоника#Сбор урожая|" .. tostring(seed.harvestRepeat) .. "]]" or "-"
     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
end


Строка 44: Строка 56:
     if not seed.chemicals then return "-" end
     if not seed.chemicals then return "-" end
     local list = {}
     local list = {}
     for chem, vals in pairs(seed.chemicals) do
     for chemId, vals in pairs(seed.chemicals) do
         table.insert(list, ("* %s (Min: %s, Max: %s, Divisor: %s)"):format(
        local entry = chemData[chemId]
             chem, vals.Min or 0, vals.Max or 0, vals.PotencyDivisor or 1
        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 table.concat(list, '<br>')
     return "<ul>" .. table.concat(list) .. "</ul>"
end
end


Строка 59: Строка 74:
         if target and target.productPrototypes then
         if target and target.productPrototypes then
             for _, prod in ipairs(target.productPrototypes) do
             for _, prod in ipairs(target.productPrototypes) do
                 table.insert(list, ("* {{Предмет|%s|link=}}"):format(prod))
                 table.insert(list, ("<li>{{Предмет|%s|link=Гидропоника#{{#invoke:Entity Lookup|getname|%s}}}}</li>"):format(prod, prod))
             end
             end
         end
         end
     end
     end
     return table.concat(list, '<br>')
     return "<ul>" .. table.concat(list) .. "</ul>"
end
end


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


     for _, seed in ipairs(data) do
     for _, seed in ipairs(data) do
         local fruitImg = ("{{Предмет|%s|size=64px|vertical=1|imageTooltip=1|link={{#invoke:Entity Lookup|getname|%s}}}}")
         local prodId = seed.productPrototypes[1]
            :format(seed.productPrototypes[1], seed.packetPrototype)
         local seedId = seed.packetPrototype
         local seedImg  = ("{{Предмет|%s|size=64px|vertical=1|imageTooltip=1|l=|link={{#invoke:Entity Lookup|getname|%s}}}}")
         local seedName = string.format('{{#invoke:Entity Lookup|getname|%s}}', seedId)
            :format(seed.packetPrototype, seed.packetPrototype)
         local plantImg = ("{{Предмет|%s-harvest|size=64px|l=|link={{#invoke:Entity Lookup|getname|%s}}}}")
            :format(seed.packetPrototype, seed.packetPrototype)


         local colGrowth       = formatCharacteristics(seed)
        local anchor  = string.format('{{anchor|%s}}', seedName)
         local colConditions   = formatConditions(seed)
        local fruitImg = string.format(
         local colHarvest     = formatHarvestType(seed)
            '{{Предмет|%s|size=64px|vertical=1|imageTooltip=1|link=%s}}',
         local colChemicals   = formatChemicals(seed)
            prodId, seedName
         local colMutations   = formatMutations(seed, data)
        )
        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(
         local row = frame:preprocess(string.format(
             [[|-
             [[|-
! %s  
            ! %s  
! %s  
            ! %s  
! %s  
            ! %s  
| %s  
            | %s  
| %s  
            | %s  
| %s  
            | %s  
| %s  
            | %s  
| %s ]],
            | %s ]],
             fruitImg, seedImg, plantImg,
             fruitImg, seedImg, plantImg,
             colGrowth, colConditions, colHarvest,
             colGrowth, colConditions, colHarvest,
Строка 128: Строка 154:
     local id = args[1]
     local id = args[1]
     local mode  = mw.text.trim(args[2] or ""):lower()
     local mode  = mw.text.trim(args[2] or ""):lower()
    local data = mw.loadData("Модуль:IanComradeBot/prototypes/seeds.json/data")
     local seed = findSeedById(id, seedsData)
     local seed = findSeedById(id, data)
     if not seed then return "" end
     if not seed then return "" end


Строка 141: Строка 166:
         return formatChemicals(seed)
         return formatChemicals(seed)
     elseif mode  == "mutations" then
     elseif mode  == "mutations" then
         return formatMutations(seed, data)
         return formatMutations(seed, seedsData)
     else
     else
         return ""
         return ""

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

Для документации этого модуля может быть создана страница Модуль:Prototypes/Механика/Растение/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