Модуль:Prototypes/Машина/Станок: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| (не показана 1 промежуточная версия этого же участника) | |||
| Строка 80: | Строка 80: | ||
end | end | ||
-- Вспомогательная функция для обработки одного рецепта | |||
local function processRecipe(recipeId, defaultDiscipline, isEmag) | |||
local recipe = getRecipeDetails(recipeId) | |||
if recipe then | |||
if recipe.result then | |||
local info = { | |||
id = recipe.id, | |||
result = recipe.result, | |||
completetime = recipe.completetime, | |||
materials = recipe.materials, | |||
discipline = defaultDiscipline, | |||
tier = 0, | |||
isEmag = isEmag or false | |||
} | |||
if defaultDiscipline ~= "Static" then | |||
local researchInfo = findInResearch(recipeId) | |||
if researchInfo then | |||
info.discipline = researchInfo.discipline | |||
info.tier = researchInfo.tier | |||
info.researchName = researchInfo.name | |||
end | |||
end | |||
table.insert(recipes, info) | |||
elseif recipe.resultReagents then | |||
for reagent, amount in pairs(recipe.resultReagents) do | |||
local reagentName = chemMapping[reagent] or reagent | |||
table.insert(recipes, { | |||
id = recipe.id, | |||
result = reagentName .. "|amount=" .. amount .. "ед.|mode-chem=1", | |||
completetime = recipe.completetime, | |||
materials = recipe.materials, | |||
discipline = defaultDiscipline, | |||
tier = 0, | |||
isEmag = isEmag or false | |||
}) | |||
break | |||
end | |||
end | |||
end | |||
end | |||
-- Обработка рецептов для lathe.Lathe (старый и новый формат) | -- Обработка рецептов для lathe.Lathe (старый и новый формат) | ||
| Строка 222: | Строка 222: | ||
local function formatRecipe(recipe, timeMultiplier, materialUseMultiplier) | local function formatRecipe(recipe, timeMultiplier, materialUseMultiplier) | ||
local out = "" | local out = "" | ||
local | local ct = recipe.completetime or 0 | ||
out = out .. '{{Шаблон:Prototypes/Машина/Станок|product=' .. recipe.result | local scaledTime = ct * timeMultiplier | ||
out = out .. '{{Шаблон:Prototypes/Машина/Станок/base|product=' .. recipe.result | |||
out = out .. '|complete-time={{#invoke:Code/Формат/Время|main|seconds|' .. scaledTime .. '}}|materials=' | out = out .. '|complete-time={{#invoke:Code/Формат/Время|main|seconds|' .. scaledTime .. '}}|materials=' | ||
| Строка 362: | Строка 363: | ||
local out = '<div class="grid-item-compressed">' .. recipesOutput .. '</div>' | local out = '<div class="grid-item-compressed">' .. recipesOutput .. '</div>' | ||
return mw.getCurrentFrame():preprocess(out) | return mw.getCurrentFrame():preprocess(out) | ||
end | |||
----------------------------------------------------------- | |||
-- Функция для универсального вызова из шаблона | |||
----------------------------------------------------------- | |||
function p.main(frame) | |||
local arguments = require("Модуль:Arguments").getArgs(frame, { unwrap = true }) | |||
local mode = arguments[1] or "" | |||
local id = arguments[2] or "" | |||
-- Для обеспечения работы mw.getCurrentFrame(), переиспользуем исходный frame | |||
local newFrame = { | |||
args = { id }, | |||
getCurrentFrame = frame.getCurrentFrame or function() return frame end | |||
} | |||
if mode == "lathe" then | |||
return p.lathe(newFrame) | |||
elseif mode == "item" then | |||
return p.item(newFrame) | |||
elseif mode == "material" then | |||
return p.material(newFrame) | |||
else | |||
return '<div style="color:red;">Неверный режим вызова: "' .. mode .. '". Используйте "lathe", "item" или "material".</div>' | |||
end | |||
end | end | ||
return p | return p | ||