Модуль:Prototypes/Машина/Станок
Материал из Space Station 14 Вики
Версия от 01:32, 28 января 2025; Pok (обсуждение | вклад) (Новая страница: «local p = {} -- Функция для загрузки данных станков local function loadLatheData() return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/lathe.json"):getContent()) end -- Функция для загрузки данных рецептов local function loadRecipeData() return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/lathe/recipes.json"):getContent()) end -- Функция дл...»)
Для документации этого модуля может быть создана страница Модуль:Prototypes/Машина/Станок/doc
local p = {}
-- Функция для загрузки данных станков
local function loadLatheData()
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/lathe.json"):getContent())
end
-- Функция для загрузки данных рецептов
local function loadRecipeData()
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/lathe/recipes.json"):getContent())
end
-- Функция для загрузки данных исследований
local function loadResearchData()
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/research.json"):getContent())
end
function p.getLatheRecipes(frame)
local latheId = frame.args[1] or ""
if latheId == "" then
return '<div style="color:red;">Не указан ID станка.</div>'
end
local latheData = loadLatheData()
local recipeData = loadRecipeData()
local researchData = loadResearchData()
local lathe = nil
for _, data in ipairs(latheData) do
if data.id == latheId then
lathe = data
break
end
end
if not lathe then
return '<div style="color:red;">Станок с ID "' .. latheId .. '" не найден.</div>'
end
local output = '<h3>Рецепты станка: ' .. latheId .. '</h3>'
output = output .. '<ul>'
local function getRecipeDetails(recipeId)
for _, recipe in ipairs(recipeData) do
if recipe.id == recipeId then
return recipe.latheRecipe
end
end
return nil
end
local function findInResearch(recipeId)
for _, research in ipairs(researchData) do
if research.technology and research.technology.recipeUnlocks then
for _, unlock in ipairs(research.technology.recipeUnlocks) do
if unlock == recipeId then
return {
name = research.technology.name,
tier = research.technology.tier
}
end
end
end
end
return nil
end
-- Обработка staticRecipes
if lathe.Lathe.staticRecipes then
output = output .. '<li><strong>Static Recipes:</strong></li>'
for _, recipeId in ipairs(lathe.Lathe.staticRecipes) do
local recipe = getRecipeDetails(recipeId)
if recipe then
output = output .. '<li>' .. recipe.result
output = output .. ' (Время изготовления: ' .. recipe.completetime .. ')'
output = output .. '<ul>'
for material, amount in pairs(recipe.materials) do
output = output .. '<li>' .. material .. ': ' .. amount .. '</li>'
end
output = output .. '</ul>'
output = output .. '</li>'
end
end
end
-- Обработка dynamicRecipes
if lathe.Lathe.dynamicRecipes then
output = output .. '<li><strong>Dynamic Recipes:</strong></li>'
for _, recipeId in ipairs(lathe.Lathe.dynamicRecipes) do
local recipe = getRecipeDetails(recipeId)
if recipe then
output = output .. '<li>' .. recipe.result
output = output .. ' (Время изготовления: ' .. recipe.completetime .. ')'
output = output .. '<ul>'
for material, amount in pairs(recipe.materials) do
output = output .. '<li>' .. material .. ': ' .. amount .. '</li>'
end
output = output .. '</ul>'
-- Проверяем, есть ли рецепт в исследованиях
local researchInfo = findInResearch(recipeId)
if researchInfo then
output = output .. '<div>Исследование: ' .. researchInfo.name
output = output .. ' (Уровень: ' .. researchInfo.tier .. ')</div>'
end
output = output .. '</li>'
end
end
end
output = output .. '</ul>'
return output
end
return p