Модуль:Prototypes/Машина/Станок: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
Строка 33: | Строка 33: | ||
return '' | return '' | ||
end | end | ||
end | |||
-- Функция для сортировки исследований по дисциплинам и тирам | |||
local function sortResearch(researchData) | |||
local sorted = {} | |||
-- Группировка по дисциплинам | |||
for _, research in ipairs(researchData) do | |||
local discipline = research.technology.discipline | |||
if not sorted[discipline] then | |||
sorted[discipline] = {} | |||
end | |||
table.insert(sorted[discipline], research) | |||
end | |||
-- Сортировка внутри каждой дисциплины по тирам | |||
for discipline, researches in pairs(sorted) do | |||
table.sort(researches, function(a, b) | |||
return a.technology.tier < b.technology.tier | |||
end) | |||
end | |||
return sorted | |||
end | end | ||
Строка 86: | Строка 109: | ||
end | end | ||
-- | -- Сортировка исследований | ||
local | local sortedResearch = sortResearch(researchData) | ||
for discipline, researches in pairs(sortedResearch) do | |||
output = output .. '<li><strong>' .. discipline .. ':</strong></li>' | |||
output = output .. '<ul>' | |||
for _, research in ipairs(researches) do | |||
output = output .. '<li>' .. research.technology.name .. ' (Уровень: ' .. research.technology.tier .. ')</li>' | |||
for _, | |||
end | end | ||
output = output .. '</ul>' | |||
output = output .. ' | |||
end | end | ||
Версия от 02:59, 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 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 sortResearch(researchData) local sorted = {} -- Группировка по дисциплинам for _, research in ipairs(researchData) do local discipline = research.technology.discipline if not sorted[discipline] then sorted[discipline] = {} end table.insert(sorted[discipline], research) end -- Сортировка внутри каждой дисциплины по тирам for discipline, researches in pairs(sorted) do table.sort(researches, function(a, b) return a.technology.tier < b.technology.tier end) end return sorted 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 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, discipline = research.technology.discipline } end end end end return nil end -- Сортировка исследований local sortedResearch = sortResearch(researchData) for discipline, researches in pairs(sortedResearch) do output = output .. '<li><strong>' .. discipline .. ':</strong></li>' output = output .. '<ul>' for _, research in ipairs(researches) do output = output .. '<li>' .. research.technology.name .. ' (Уровень: ' .. research.technology.tier .. ')</li>' end output = output .. '</ul>' end output = output .. '</ul>' return output end return p