Bearbeiten von „Modul:CraftingParser“
Aus Eco - Deutsches Wiki
Deine Änderungen werden angezeigt, sobald ein dazu berechtigter Benutzer sie akzeptiert hat. (Hilfe)
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 1: | Zeile 1: | ||
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) | ||
if a.affSkill1[1] < b.affSkill1[1] then return true | |||
elseif a.affSkill1[1] > b.affSkill1[1] then return false | |||
elseif a.skillNeed[1] < b.skillNeed[1] then return true | |||
elseif a.skillNeed[1] > b.skillNeed[1] then return false | |||
elseif not a.skillNeed[3] and b.skillNeed[3] then return true | |||
elseif a.skillNeed[3] and not b.skillNeed[3] then return false | |||
elseif a.skillNeed[3] and a.skillNeed[3] < b.skillNeed[3] then return true | |||
elseif a.skillNeed[3] and a.skillNeed[3] > b.skillNeed[3] then return false | |||
elseif a.item1[1] < b.item1[1] then return true | |||
elseif a.item1[1] > b.item1[1] then return false | |||
else return a.mater1[1] <= b.mater1[1] | |||
elseif a. | |||
elseif a. | |||
end | end | ||
end | end | ||
Zeile 60: | Zeile 56: | ||
['mater3'] = {args['material'..i..'.3'], args['materialImg'..i..'.3'], args['materialNum'..i..'.3']}, | ['mater3'] = {args['material'..i..'.3'], args['materialImg'..i..'.3'], args['materialNum'..i..'.3']}, | ||
['mater4'] = {args['material'..i..'.4'], args['materialImg'..i..'.4'], args['materialNum'..i..'.4']}, | ['mater4'] = {args['material'..i..'.4'], args['materialImg'..i..'.4'], args['materialNum'..i..'.4']}, | ||
[' | ['ctime'] = args['craftTime'..i], | ||
['affSkill1'] = {args['affectSkill'..i..'.1'], args['affectSkillImg'..i..'.1']}, | ['affSkill1'] = {args['affectSkill'..i..'.1'], args['affectSkillImg'..i..'.1']}, | ||
['affSkill2'] = {args['affectSkill'..i..'.2'], args['affectSkillImg'..i..'.2']}, | ['affSkill2'] = {args['affectSkill'..i..'.2'], args['affectSkillImg'..i..'.2']}, | ||
}) | }) | ||
end | end | ||
Zeile 73: | Zeile 68: | ||
-- Formats and sorts recipes | -- Formats and sorts recipes | ||
function formatRecipes( recipes ) | function formatRecipes( recipes ) | ||
-- Iterate over every recipe | |||
for k, v in ipairs( recipes ) do | |||
if recipes[k].item1[3] == '1' then recipes[k].item1[3] = nil end | |||
if recipes[k].item2[3] == '1' then recipes[k].item2[3] = nil end | |||
if recipes[k].mater1[3] == '1' then recipes[k].mater1[3] = nil end | |||
if recipes[k].mater2[3] == '1' then recipes[k].mater2[3] = nil end | |||
if recipes[k].mater3[3] == '1' then recipes[k].mater3[3] = nil end | |||
if recipes[k].mater4[3] == '1' then recipes[k].mater4[3] = nil end | |||
if not recipes[k].skillNeed[1] then | |||
recipes[k].skillNeed[1] = '' | |||
recipes[k].skillNeed[3] = '' | |||
end | |||
end | |||
-- Sort recipes | |||
table.sort( recipes, function( a, b ) return recipeCompare( a, b ) end ) | |||
return recipes | |||
end | end | ||
-- Seperates a list of recipes into two tables | |||
function seperate( recipes, item ) | |||
local sepRecipes = { {}, {} } | |||
for i = 1, #recipes do | |||
if recipes[i].item1[1] == item then | |||
table.insert( sepRecipes[1], recipes[i] ) | |||
elseif recipes[i].item2[1] ~= nil and recipes[i].item2[1] == item then | |||
table.insert( sepRecipes[1], recipes[i] ) | |||
elseif recipes[i].mater1[1] == item then | |||
table.insert( sepRecipes[2], recipes[i] ) | |||
elseif recipes[i].mater2[1] ~= nil and recipes[i].mater2[1] == item then | |||
table.insert( sepRecipes[2], recipes[i] ) | |||
elseif recipes[i].mater3[1] ~= nil and recipes[i].mater3[1] == item then | |||
table.insert( sepRecipes[2], recipes[i] ) | |||
elseif recipes[i].mater4[1] ~= nil and recipes[i].mater4[1] == item then | |||
table.insert( sepRecipes[2], recipes[i] ) | |||
end | |||
end | |||
return sepRecipes | |||
end | |||
-- Called from Template:RecipeTable | -- Called from Template:RecipeTable | ||
Zeile 84: | Zeile 116: | ||
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 | ||
Zeile 96: | Zeile 128: | ||
-- Called from Module:GetRecipes | -- Called from Module:GetRecipes | ||
-- Calls Module: | -- Calls Module:RecipTable | ||
-- Returns the wikitext returned by Module:RecipeTable | -- Returns the wikitext returned by Module:RecipeTable | ||
function p.formattedItem( | function p.formattedItem( recipes, item ) | ||
-- Seperate recipes into crafting recipes and used in recipes | |||
local sepRecipes = seperate( recipes, 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 recipeTable = require( "Module:RecipeTable" ) | ||
local returnVal = '=== | local returnVal = '=== Crafting Recipes ===\n\n' | ||
if #sepRecipes[1] == 0 then | |||
if | returnVal = returnVal .. "''None''\n\n=== Used in Recipes ===\n\n" | ||
returnVal = returnVal .. | |||
else | else | ||
returnVal = returnVal .. | returnVal = returnVal .. recipeTable.main( formatRecipes( sepRecipes[1] ) ) .. '\n\n=== Used in Recipes ===\n\n' | ||
end | end | ||
if #sepRecipes[2] == 0 then | |||
if | returnVal = returnVal .. "''None''\n" | ||
returnVal = returnVal .. | |||
else | else | ||
returnVal = returnVal .. | returnVal = returnVal .. recipeTable.main( formatRecipes( sepRecipes[2] ) ) | ||
end | end | ||
Zeile 125: | Zeile 158: | ||
-- 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 ) ) | ||
Zeile 142: | Zeile 175: | ||
-- 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 ) ) |