Модуль:Prototypes/Машина/Станок: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 14: | Строка 14: | ||
local function loadResearchData() | local function loadResearchData() | ||
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/research.json"):getContent()) | return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/research.json"):getContent()) | ||
end | |||
-- Функция для загрузки данных материалов | |||
local function loadMaterialData() | |||
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/materials.json"):getContent()) | |||
end | end | ||
| Строка 38: | Строка 43: | ||
local function sortRecipesByPriority(recipes) | local function sortRecipesByPriority(recipes) | ||
table.sort(recipes, function(a, b) | table.sort(recipes, function(a, b) | ||
local priority = { Static = 1, Unknown = 2, EMAG = 4 } | local priority = { Static = 1, Unknown = 2, EMAG = 4 } | ||
local aPriority = priority[a.discipline] or 3 | local aPriority = priority[a.discipline] or 3 | ||
local bPriority = priority[b.discipline] or 3 | local bPriority = priority[b.discipline] or 3 | ||
if a.isEmag ~= b.isEmag then | if a.isEmag ~= b.isEmag then | ||
return not a.isEmag | return not a.isEmag | ||
end | end | ||
if aPriority == bPriority then | if aPriority == bPriority then | ||
if a.tier == b.tier then | if a.tier == b.tier then | ||
return a.discipline < b.discipline | return a.discipline < b.discipline | ||
end | end | ||
| Строка 58: | Строка 58: | ||
end | end | ||
return aPriority < bPriority | return aPriority < bPriority | ||
end) | end) | ||
| Строка 72: | Строка 71: | ||
local recipeData = loadRecipeData() | local recipeData = loadRecipeData() | ||
local researchData = loadResearchData() | local researchData = loadResearchData() | ||
local materialData = loadMaterialData() | |||
local lathe = nil | local lathe = nil | ||
| Строка 83: | Строка 83: | ||
if not lathe then | if not lathe then | ||
return '<div style="color:red;">Станок с ID "' .. latheId .. '" не найден.</div>' | return '<div style="color:red;">Станок с ID "' .. latheId .. '" не найден.</div>' | ||
end | |||
local materialMapping = {} | |||
for _, material in ipairs(materialData) do | |||
materialMapping[material.material.id] = material.material.stackEntity | |||
end | end | ||
local output = '' | local output = '' | ||
local recipes = {} | local recipes = {} | ||
| Строка 158: | Строка 162: | ||
end | end | ||
end | end | ||
-- Обработка emagStaticRecipes | -- Обработка emagStaticRecipes | ||
if lathe.EmagLatheRecipes and lathe.EmagLatheRecipes.emagStaticRecipes then | if lathe.EmagLatheRecipes and lathe.EmagLatheRecipes.emagStaticRecipes then | ||
| Строка 175: | Строка 180: | ||
end | end | ||
end | end | ||
-- Обработка emagDynamicRecipes | -- Обработка emagDynamicRecipes | ||
if lathe.EmagLatheRecipes and lathe.EmagLatheRecipes.emagDynamicRecipes then | if lathe.EmagLatheRecipes and lathe.EmagLatheRecipes.emagDynamicRecipes then | ||
| Строка 206: | Строка 211: | ||
end | end | ||
sortRecipesByPriority(recipes) | sortRecipesByPriority(recipes) | ||
for _, recipe in ipairs(recipes) do | for _, recipe in ipairs(recipes) do | ||
output = output .. '{{Шаблон:Prototypes/Машина/Станок|product=' .. recipe.result | output = output .. '{{Шаблон:Prototypes/Машина/Станок|product=' .. recipe.result | ||
| Строка 217: | Строка 220: | ||
if next(recipe.materials) then | if next(recipe.materials) then | ||
for material, amount in pairs(recipe.materials) do | for material, amount in pairs(recipe.materials) do | ||
output = output .. '<b>[[File:' .. | local stackEntity = materialMapping[material] or material | ||
local scaledAmount = amount / 100 | |||
output = output .. '<b>[[File:' .. stackEntity .. '.png]] ' .. scaledAmount .. ' ' .. stackEntity .. '</b>' | |||
end | end | ||
else | else | ||
output = output .. 'Нет данных о материалах' | output = output .. 'Нет данных о материалах' | ||
end | end | ||
-- Информация об исследовании | -- Информация об исследовании | ||
if recipe.discipline ~= "Static" and recipe.discipline ~= "Unknown" then | if recipe.discipline ~= "Static" and recipe.discipline ~= "Unknown" then | ||
output = output .. '|info=[[File:' .. recipe.discipline .. '.png]] {{#invoke:Ftl|main|translation|' .. recipe.researchName | output = output .. '|info=[[File:' .. recipe.discipline .. '.png|16x16px|link=]] [[Руководство по исследованию и разработке|{{#invoke:Ftl|main|translation|' .. recipe.researchName | ||
output = output .. '}} (Уровень: ' .. recipe.tier .. ')' | output = output .. '}}]] (Уровень: ' .. recipe.tier .. ')' | ||
end | end | ||
-- | -- При взломе EMAG | ||
if recipe.isEmag then | if recipe.isEmag then | ||
output = output .. '<div>Пометка: EMAG</div>' | output = output .. '<div>Пометка: EMAG</div>' | ||
Версия от 07:03, 28 января 2025
Для документации этого модуля может быть создана страница Модуль: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
-- Функция для загрузки данных материалов
local function loadMaterialData()
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/materials.json"):getContent())
end
-- Функция для форматирования времени
local function format_seconds_to_short_string(input_seconds)
local minutes = math.floor(input_seconds / 60)
local seconds = input_seconds % 60
local minutes_part = minutes > 0 and (minutes .. " мин.") or nil
local seconds_part = seconds > 0 and (seconds .. " сек.") or nil
if minutes_part and seconds_part then
return minutes_part .. " " .. seconds_part
elseif seconds_part then
return seconds_part
elseif minutes_part then
return minutes_part
else
return ''
end
end
-- Функция для сортировки рецептов
local function sortRecipesByPriority(recipes)
table.sort(recipes, function(a, b)
local priority = { Static = 1, Unknown = 2, EMAG = 4 }
local aPriority = priority[a.discipline] or 3
local bPriority = priority[b.discipline] or 3
if a.isEmag ~= b.isEmag then
return not a.isEmag
end
if aPriority == bPriority then
if a.tier == b.tier then
return a.discipline < b.discipline
end
return a.tier < b.tier
end
return aPriority < bPriority
end)
end
function p.main(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 materialData = loadMaterialData()
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 materialMapping = {}
for _, material in ipairs(materialData) do
materialMapping[material.material.id] = material.material.stackEntity
end
local output = ''
local recipes = {}
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,
discipline = research.technology.discipline
}
end
end
end
end
return nil
end
-- Обработка staticRecipes
if lathe.Lathe.staticRecipes then
for _, recipeId in ipairs(lathe.Lathe.staticRecipes) do
local recipe = getRecipeDetails(recipeId)
if recipe then
table.insert(recipes, {
result = recipe.result,
completetime = recipe.completetime,
materials = recipe.materials,
discipline = "Static",
tier = 0
})
end
end
end
-- Обработка dynamicRecipes
if lathe.Lathe.dynamicRecipes then
for _, recipeId in ipairs(lathe.Lathe.dynamicRecipes) do
local recipe = getRecipeDetails(recipeId)
if recipe then
local researchInfo = findInResearch(recipeId)
if researchInfo then
table.insert(recipes, {
result = recipe.result,
completetime = recipe.completetime,
materials = recipe.materials,
discipline = researchInfo.discipline,
tier = researchInfo.tier,
researchName = researchInfo.name
})
else
table.insert(recipes, {
result = recipe.result,
completetime = recipe.completetime,
materials = recipe.materials,
discipline = "Unknown",
tier = 0
})
end
end
end
end
-- Обработка emagStaticRecipes
if lathe.EmagLatheRecipes and lathe.EmagLatheRecipes.emagStaticRecipes then
for _, recipeId in ipairs(lathe.EmagLatheRecipes.emagStaticRecipes) do
local recipe = getRecipeDetails(recipeId)
if recipe then
table.insert(recipes, {
result = recipe.result,
completetime = recipe.completetime,
materials = recipe.materials,
discipline = "Static",
tier = 0,
isEmag = true
})
end
end
end
-- Обработка emagDynamicRecipes
if lathe.EmagLatheRecipes and lathe.EmagLatheRecipes.emagDynamicRecipes then
for _, recipeId in ipairs(lathe.EmagLatheRecipes.emagDynamicRecipes) do
local recipe = getRecipeDetails(recipeId)
if recipe then
local researchInfo = findInResearch(recipeId)
if researchInfo then
table.insert(recipes, {
result = recipe.result,
completetime = recipe.completetime,
materials = recipe.materials,
discipline = researchInfo.discipline,
tier = researchInfo.tier,
researchName = researchInfo.name,
isEmag = true
})
else
table.insert(recipes, {
result = recipe.result,
completetime = recipe.completetime,
materials = recipe.materials,
discipline = "Unknown",
tier = 0,
isEmag = true
})
end
end
end
end
sortRecipesByPriority(recipes)
for _, recipe in ipairs(recipes) do
output = output .. '{{Шаблон:Prototypes/Машина/Станок|product=' .. recipe.result
output = output .. '|complete-time=' .. format_seconds_to_short_string(recipe.completetime)
output = output .. '|materials='
if next(recipe.materials) then
for material, amount in pairs(recipe.materials) do
local stackEntity = materialMapping[material] or material
local scaledAmount = amount / 100
output = output .. '<b>[[File:' .. stackEntity .. '.png]] ' .. scaledAmount .. ' ' .. stackEntity .. '</b>'
end
else
output = output .. 'Нет данных о материалах'
end
-- Информация об исследовании
if recipe.discipline ~= "Static" and recipe.discipline ~= "Unknown" then
output = output .. '|info=[[File:' .. recipe.discipline .. '.png|16x16px|link=]] [[Руководство по исследованию и разработке|{{#invoke:Ftl|main|translation|' .. recipe.researchName
output = output .. '}}]] (Уровень: ' .. recipe.tier .. ')'
end
-- При взломе EMAG
if recipe.isEmag then
output = output .. '<div>Пометка: EMAG</div>'
end
output = output .. '}}'
end
return mw.getCurrentFrame():preprocess(output)
end
return p