Модуль:Prototypes/Машина/Станок: различия между версиями
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 -- Функция дл...» |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 8: | Строка 8: | ||
-- Функция для загрузки данных рецептов | -- Функция для загрузки данных рецептов | ||
local function loadRecipeData() | local function loadRecipeData() | ||
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes | return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/recipes.json"):getContent()) | ||
end | end | ||
| Строка 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 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 | end | ||
| Строка 64: | Строка 83: | ||
end | end | ||
return nil | return nil | ||
end | |||
-- Функция для отображения рецепта | |||
local function renderRecipe(recipe) | |||
local recipeOutput = '<li>' .. recipe.result | |||
recipeOutput = recipeOutput .. ' (Время изготовления: ' .. format_seconds_to_short_string(recipe.completetime) .. ')' | |||
recipeOutput = recipeOutput .. '<ul>' | |||
for material, amount in pairs(recipe.materials) do | |||
recipeOutput = recipeOutput .. '<li>' .. material .. ': ' .. amount .. '</li>' | |||
end | |||
recipeOutput = recipeOutput .. '</ul>' | |||
recipeOutput = recipeOutput .. '</li>' | |||
return recipeOutput | |||
end | end | ||
| Строка 72: | Строка 104: | ||
local recipe = getRecipeDetails(recipeId) | local recipe = getRecipeDetails(recipeId) | ||
if recipe then | if recipe then | ||
output = output .. | output = output .. renderRecipe(recipe) | ||
end | end | ||
end | end | ||
| Строка 90: | Строка 115: | ||
local recipe = getRecipeDetails(recipeId) | local recipe = getRecipeDetails(recipeId) | ||
if recipe then | if recipe then | ||
local researchInfo = findInResearch(recipeId) | local researchInfo = findInResearch(recipeId) | ||
if researchInfo then | if researchInfo then | ||
output = output .. '<li>' .. recipe.result | |||
output = output .. ' (Время изготовления: ' .. format_seconds_to_short_string(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 .. '<div>Исследование: ' .. researchInfo.name | output = output .. '<div>Исследование: ' .. researchInfo.name | ||
output = output .. ' (Уровень: ' .. researchInfo.tier .. ')</div>' | output = output .. ' (Уровень: ' .. researchInfo.tier .. ')</div>' | ||
output = output .. '</li>' | |||
else | |||
output = output .. renderRecipe(recipe) | |||
end | end | ||
end | end | ||
end | end | ||