Модуль:Prototypes/Машина/Станок: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 301: | Строка 301: | ||
end | end | ||
local out = '{| class="wikitable"' .. "\n! | local out = '{| class="wikitable"' .. "\n!Рецепт\n !Станок\n" | ||
local foundAny = false | local foundAny = false | ||
| Строка 313: | Строка 313: | ||
foundAny = true | foundAny = true | ||
out = out .. '|-' .. "\n" | out = out .. '|-' .. "\n" | ||
out = out .. '| ' .. formatRecipe(recipe, timeMultiplier, materialUseMultiplier, true) .. "\n" | |||
out = out .. '| [[File:' .. lathe.id .. '.png|32x32px|link=]] [[{{#invoke:Entity Lookup|getname|' .. lathe.id .. '}}|{{#invoke:Entity Lookup|getname|' .. lathe.id .. '}}]]' .. "\n" | out = out .. '| [[File:' .. lathe.id .. '.png|32x32px|link=]] [[{{#invoke:Entity Lookup|getname|' .. lathe.id .. '}}|{{#invoke:Entity Lookup|getname|' .. lathe.id .. '}}]]' .. "\n" | ||
end | end | ||
end | end | ||
| Строка 321: | Строка 321: | ||
if not foundAny then | if not foundAny then | ||
return '<div style="color:red;">Рецепт для предмета с ID "' .. itemId .. '" не найден во всех станках.</div>' | return '<div style="color:red;">Рецепт для предмета с ID "' .. itemId .. '" не найден во всех станках.</div>' | ||
end | |||
out = out .. '|}' | |||
return mw.getCurrentFrame():preprocess(out) | |||
end | |||
----------------------------------------------------------- | |||
-- Функция для поиска и вывода рецептов по ID материала | |||
----------------------------------------------------------- | |||
function p.material(frame) | |||
local materialId = frame.args[1] or "" | |||
if materialId == "" then | |||
return '<div style="color:red;">Не указан ID материала.</div>' | |||
end | |||
local out = '{| class="wikitable"' .. "\n!Рецепт\n !Станок\n" | |||
local foundAny = false | |||
for _, lathe in ipairs(latheData) do | |||
local recipes = getLatheRecipes(lathe) | |||
local materialUseMultiplier = (lathe.Lathe and lathe.Lathe.materialUseMultiplier) or 1 | |||
local timeMultiplier = (lathe.Lathe and lathe.Lathe.timeMultiplier) or 1 | |||
local matchingRecipes = {} | |||
for _, recipe in ipairs(recipes) do | |||
if recipe.materials then | |||
for matId, _ in pairs(recipe.materials) do | |||
if matId == materialId then | |||
table.insert(matchingRecipes, recipe) | |||
break | |||
end | |||
end | |||
end | |||
end | |||
if #matchingRecipes > 0 then | |||
foundAny = true | |||
local rowspan = #matchingRecipes | |||
for i, recipe in ipairs(matchingRecipes) do | |||
out = out .. '|-\n' | |||
out = out .. '| ' .. formatRecipe(recipe, timeMultiplier, materialUseMultiplier, false) .. "\n" | |||
if i == 1 then | |||
out = out .. string.format('| rowspan="%d"|[[File:%s.png|32x32px|link=]] [[{{#invoke:Entity Lookup|getname|%s}}|{{#invoke:Entity Lookup|getname|%s}}]]\n', rowspan, lathe.id, lathe.id, lathe.id) | |||
end | |||
end | |||
end | |||
end | |||
if not foundAny then | |||
return '<div style="color:red;">Для материала с ID "' .. materialId .. '" рецептов не найдено во всех станках.</div>' | |||
end | end | ||