Модуль:Prototypes/Машина/Станок: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| (не показаны 4 промежуточные версии этого же участника) | |||
| Строка 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 (старый и новый формат) | ||
| Строка 220: | Строка 220: | ||
-- Функция для формирования строки рецепта | -- Функция для формирования строки рецепта | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
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=' | ||
| Строка 301: | Строка 299: | ||
end | end | ||
local | local recipesOutput = "" | ||
local foundAny = false | local foundAny = false | ||
| Строка 308: | Строка 306: | ||
local materialUseMultiplier = (lathe.Lathe and lathe.Lathe.materialUseMultiplier) or 1 | local materialUseMultiplier = (lathe.Lathe and lathe.Lathe.materialUseMultiplier) or 1 | ||
local timeMultiplier = (lathe.Lathe and lathe.Lathe.timeMultiplier) or 1 | local timeMultiplier = (lathe.Lathe and lathe.Lathe.timeMultiplier) or 1 | ||
for _, recipe in ipairs(recipes) do | for _, recipe in ipairs(recipes) do | ||
if recipe.id == itemId or recipe.result == itemId then | if recipe.id == itemId or recipe.result == itemId then | ||
foundAny = true | |||
local recipeStr = formatRecipe(recipe, timeMultiplier, materialUseMultiplier) | |||
local recipeStr = formatRecipe(recipe, timeMultiplier, materialUseMultiplier | |||
recipeStr = recipeStr:gsub("}}$", "|method-container=" .. lathe.id .. "}}") | recipeStr = recipeStr:gsub("}}$", "|method-container=" .. lathe.id .. "}}") | ||
recipesOutput = recipesOutput .. recipeStr | |||
end | end | ||
end | end | ||
end | end | ||
| Строка 334: | Строка 321: | ||
end | end | ||
local out = '<div class="grid-item-compressed">' .. recipesOutput .. '</div>' | |||
return mw.getCurrentFrame():preprocess(out) | return mw.getCurrentFrame():preprocess(out) | ||
end | end | ||
| Строка 346: | Строка 334: | ||
end | end | ||
local | local recipesOutput = "" | ||
local foundAny = false | local foundAny = false | ||
| Строка 353: | Строка 341: | ||
local materialUseMultiplier = (lathe.Lathe and lathe.Lathe.materialUseMultiplier) or 1 | local materialUseMultiplier = (lathe.Lathe and lathe.Lathe.materialUseMultiplier) or 1 | ||
local timeMultiplier = (lathe.Lathe and lathe.Lathe.timeMultiplier) or 1 | local timeMultiplier = (lathe.Lathe and lathe.Lathe.timeMultiplier) or 1 | ||
for _, recipe in ipairs(recipes) do | for _, recipe in ipairs(recipes) do | ||
| Строка 359: | Строка 346: | ||
for matId, _ in pairs(recipe.materials) do | for matId, _ in pairs(recipe.materials) do | ||
if matId == materialId then | if matId == materialId then | ||
foundAny = true | |||
local recipeStr = formatRecipe(recipe, timeMultiplier, materialUseMultiplier) | |||
recipeStr = recipeStr:gsub("}}$", "|method-container=" .. lathe.id .. "}}") | |||
recipesOutput = recipesOutput .. recipeStr | |||
break | break | ||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
| Строка 382: | Строка 361: | ||
end | end | ||
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 | ||