Модуль:Prototypes/Механика/Растение: различия между версиями
Pok (обсуждение | вклад) мНет описания правки Метки: с мобильного устройства из мобильной версии через расширенный мобильный режим |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 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) | ||
| Строка 23: | Строка 27: | ||
("[[Гидропоника#Стадии роста|Стадии роста]]: %s"):format(seed.growthStages or 0), | ("[[Гидропоника#Стадии роста|Стадии роста]]: %s"):format(seed.growthStages or 0), | ||
} | } | ||
return table.concat(parts, | return table.concat(parts, '<br>') | ||
end | end | ||
| Строка 34: | Строка 38: | ||
("[[Гидропоника#|Освещения]]: %s"):format(seed.idealLight or "-"), | ("[[Гидропоника#|Освещения]]: %s"):format(seed.idealLight or "-"), | ||
} | } | ||
return table.concat(parts, | 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: | Строка 58: | ||
if not seed.chemicals then return "-" end | if not seed.chemicals then return "-" end | ||
local list = {} | local list = {} | ||
for | for chemId, vals in pairs(seed.chemicals) do | ||
table.insert(list, (" | 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 table.concat(list | return table.concat(list) | ||
end | end | ||
| Строка 59: | Строка 76: | ||
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, (" | 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 | return table.concat(list) | ||
end | end | ||
| Строка 91: | Строка 108: | ||
for _, seed in ipairs(data) do | for _, seed in ipairs(data) do | ||
local | local prodId = seed.productPrototypes[1] | ||
local prodName = string.format('{{#invoke:Entity Lookup|getname|%s}}', prodId) | |||
local | local seedName = seed.packetPrototype | ||
local | |||
local colGrowth | local anchor = string.format('{{anchor|%s}}', prodName) | ||
local colConditions | local fruitImg = string.format( | ||
local colHarvest | '{{Предмет|%s|size=64px|vertical=1|imageTooltip=1|link=%s}}', | ||
local colChemicals | prodId, prodName | ||
local colMutations | ) | ||
local seedImg = string.format( | |||
'{{Предмет|%s|size=64px|vertical=1|imageTooltip=1|l=|link=%s}}', | |||
seedName, prodName | |||
) | |||
local plantImg = string.format( | |||
'{{Предмет|%s-harvest|size=64px|l=|link=%s}}', | |||
seedName, prodName | |||
) | |||
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 ]], | |||
fruitImg, seedImg, plantImg, | fruitImg, seedImg, plantImg, | ||
colGrowth, colConditions, colHarvest, | colGrowth, colConditions, colHarvest, | ||
| Строка 128: | Строка 156: | ||
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 seed = findSeedById(id, seedsData) | |||
local seed = findSeedById(id, | |||
if not seed then return "" end | if not seed then return "" end | ||
| Строка 141: | Строка 168: | ||
return formatChemicals(seed) | return formatChemicals(seed) | ||
elseif mode == "mutations" then | elseif mode == "mutations" then | ||
return formatMutations(seed, | return formatMutations(seed, seedsData) | ||
else | else | ||
return "" | return "" | ||