Редактирование: Модуль:CraftingParser
Материал из Eco - Русская Wiki
Сделанные вами изменения будут показаны читателям после того, как их утвердит уполномоченный участник (подробнее).
Стабильная версия была проверена 15 февраля 2021. 1 изменение ожидает проверки.
Внимание: некоторые из ожидающих проверки изменений относятся к редактируемой вами части страницы. (показать эти изменения)
Правка может быть отменена. Пожалуйста, просмотрите сравнение версий ниже, чтобы убедиться, что это нужная вам правка, и запишите страницу ниже, чтобы отменить правку.
Текущая версия | Ваш текст | ||
Строка 2: | Строка 2: | ||
local p = {} | local p = {} | ||
-- Grabs args from the parent frame | |||
local | -- Trims and parses the args into a table, then returns the table | ||
function norm( origArgs ) | |||
origArgs = mw.getCurrentFrame():getParent().args | |||
local args = {} | |||
for k, v in pairs( origArgs ) do | |||
v = mw.text.trim( tostring( v ) ) | |||
if v ~= '' then | |||
args[k] = v | |||
end | |||
end | |||
return args | |||
end | |||
-- Compares two recipes ( a < b ? true : false ) | -- Compares two recipes ( a < b ? true : false ) | ||
function recipeCompare(a, b) | function recipeCompare(a, b) | ||
--not in v0.9 | --not in v0.9 | ||
--if not a.efficiencySkills[1] and not b.efficiencySkills[1] then return false | --if not a.efficiencySkills[1] and not b.efficiencySkills[1] then return false | ||
Строка 15: | Строка 29: | ||
--elseif a.efficiencySkills[1] > b.efficiencySkills[1] then return false | --elseif a.efficiencySkills[1] > b.efficiencySkills[1] then return false | ||
if (a.skillNeeds[1] ~= nil and b.skillNeeds[1] ~= nil) then | |||
if a.skillNeeds[1][1] < b.skillNeeds[1][1] then return true | |||
elseif a.skillNeeds[1][1] > b.skillNeeds[1][1] then return false | |||
elseif not a.skillNeeds[1][2] and b.skillNeeds[1][2] then return true | |||
elseif a.skillNeeds[1][2] and not b.skillNeeds[1][2] then return false | |||
elseif a.skillNeeds[1][2] and a.skillNeeds[1][2] < b.skillNeeds[1][2] then return true | |||
elseif a.skillNeeds[1][2] and a.skillNeeds[1][2] > b.skillNeeds[1][2] then return false | |||
end | |||
elseif a.defaultVariant < b.defaultVariant then return true | |||
elseif a.defaultVariant > b.defaultVariant then return false | |||
else return a.defaultVariant <= b.defaultVariant | |||
elseif a.defaultVariant < b.defaultVariant then | |||
elseif a.defaultVariant > b.defaultVariant then | |||
end | end | ||
end | end | ||
Строка 74: | Строка 80: | ||
function formatRecipes( recipes ) | function formatRecipes( recipes ) | ||
-- Sort recipes | -- Sort recipes | ||
table.sort( recipes, recipeCompare ) | table.sort( recipes, function( a, b ) return recipeCompare( a, b ) end ) | ||
return recipes | return recipes | ||
Строка 84: | Строка 90: | ||
function p.raw( f ) | function p.raw( f ) | ||
-- get args from the Template, parse them into recipes | -- get args from the Template, parse them into recipes | ||
local recipes = frameParse( | local recipes = frameParse( norm( f ) ) | ||
-- Format the recipes | -- Format the recipes | ||
Строка 100: | Строка 106: | ||
function p.formattedItem( products, ingredients, item ) | function p.formattedItem( products, ingredients, item ) | ||
-- Format the recipes, and call RecipeTable on each table | -- Format the recipes, and call RecipeTable on each table | ||
local recipeTable = require( "Module:RecipeTable" ) | |||
local returnVal = '=== | local returnVal = '=== Crafting Recipes ===\n\n' | ||
if (products ~= nil and #products ~= 0) then | if (products ~= nil and #products ~= 0) then | ||
returnVal = returnVal .. recipeTable.main( formatRecipes(products) ) .. '\n\n=== Used in Recipes ===\n\n' | |||
else | else | ||
returnVal = returnVal .. "' | returnVal = returnVal .. "''None''\n\n=== Used in Recipes ===\n\n " | ||
end | end | ||
if (ingredients ~= nil and #ingredients ~= 0) then | if (ingredients ~= nil and #ingredients ~= 0) then | ||
returnVal = returnVal .. recipeTable.main( formatRecipes(ingredients) ) | returnVal = returnVal .. recipeTable.main( formatRecipes(ingredients) ) | ||
else | else | ||
returnVal = returnVal .. "''None''\n" | |||
end | end | ||
Строка 125: | Строка 131: | ||
-- Format the recipes, and call RecipeTable | -- Format the recipes, and call RecipeTable | ||
local recipeTable = require( "Module:RecipeTable" ) | local recipeTable = require( "Module:RecipeTable" ) | ||
local returnVal = '=== ' .. | local returnVal = '=== Recipes at ' .. table .. ' ===\n\n' | ||
if #recipes == 0 then | if #recipes == 0 then | ||
returnVal = returnVal .. "' | returnVal = returnVal .. "''None''\n" | ||
else | else | ||
returnVal = returnVal .. recipeTable.main( formatRecipes( recipes ) ) | returnVal = returnVal .. recipeTable.main( formatRecipes( recipes ) ) | ||
Строка 142: | Строка 148: | ||
-- Format the recipes, and call RecipeTable | -- Format the recipes, and call RecipeTable | ||
local recipeTable = require( "Module:RecipeTable" ) | local recipeTable = require( "Module:RecipeTable" ) | ||
local returnVal = '=== ' .. | local returnVal = '=== ' .. group .. ' Recipes ===\n\n' | ||
if #recipes == 0 then | if #recipes == 0 then | ||
returnVal = returnVal .. "' | returnVal = returnVal .. "''None''\n" | ||
else | else | ||
returnVal = returnVal .. recipeTable.main( formatRecipes( recipes ) ) | returnVal = returnVal .. recipeTable.main( formatRecipes( recipes ) ) |