Modul:RecipeTable: Unterschied zwischen den Versionen
Aus Eco - Deutsches Wiki
[unmarkierte Version] | [unmarkierte Version] |
Match EN Version |
Keine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
-- | -- Modul:CraftingParser (https://wiki.play.eco/en/Modul:CraftingParser) | ||
local p = {} | local p = {} | ||
local Utils = require( | local Utils = require('Modul:Utils') | ||
local L = require( | local L = require('Modul:Localization') | ||
-- | -- Compares two recipes ( a < b ? true : false ) | ||
function | function recipeCompare(a, b) | ||
-- | --not in v0.9 | ||
if | --if not a.efficiencySkills[1] and not b.efficiencySkills[1] then return false | ||
--elseif a.efficiencySkills[1] and not b.efficiencySkills[1] then return false | |||
--elseif not a.efficiencySkills[1] and b.efficiencySkills[1] then return true | |||
--elseif a.efficiencySkills[1] < b.efficiencySkills[1] then return true | |||
--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 | |||
end | end | ||
end | end | ||
local | -- Parses arguments into a table of recipes | ||
function frameParse( args ) | |||
local parsedRecipes = {} | |||
-- Set variables | |||
local dispCraftStn = tonumber( args.displayCraftStation ) | |||
local checkImage = tonumber( args.checkForImage ) | |||
-- Iterate over every recipe passed in | |||
for i = 1, args.numRecipes do | |||
table.insert( parsedRecipes, i, { | |||
['dispCraftStn'] = dispCraftStn, | |||
['checkImage'] = checkImage, | |||
['craftStn'] = {args['craftStation'..i], args['craftStationImg'..i]}, | |||
['item1'] = {args['item'..i..'.1'], args['itemImg'..i..'.1'], args['itemNum'..i..'.1']}, | |||
['item2'] = {args['item'..i..'.2'], args['itemImg'..i..'.2'], args['itemNum'..i..'.2']}, | |||
['skillNeed'] = {args['skillNeed'..i], args['skillNeedImg'..i], args['skillLvlNeed'..i]}, | |||
['mater1'] = {args['material'..i..'.1'], args['materialImg'..i..'.1'], args['materialNum'..i..'.1']}, | |||
['mater2'] = {args['material'..i..'.2'], args['materialImg'..i..'.2'], args['materialNum'..i..'.2']}, | |||
['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']}, | |||
['cTime'] = args['craftTime'..i], | |||
['affSkill1'] = {args['affectSkill'..i..'.1'], args['affectSkillImg'..i..'.1']}, | |||
['affSkill2'] = {args['affectSkill'..i..'.2'], args['affectSkillImg'..i..'.2']}, | |||
--TODO - construct new parts of the table here | |||
}) | |||
end | end | ||
return | return parsedRecipes | ||
end | end | ||
function | |||
-- Formats and sorts recipes | |||
function formatRecipes( recipes ) | |||
-- Sort recipes | |||
table.sort( recipes, recipeCompare ) | |||
return recipes | |||
end | end | ||
function | -- Called from Template:RecipeTable | ||
local | -- Calls Modul:RecipeTable | ||
-- Returns the wikitext returned by Modul:RecipeTable | |||
function p.raw( f ) | |||
return | -- get args from the Template, parse them into recipes | ||
local recipes = frameParse( Utils.normaliseArgs(f) ) | |||
-- Format the recipes | |||
recipes = formatRecipes( recipes ) | |||
-- Call RecipeTable | |||
local recipeTable = require( "Modul:RecipeTable" ) | |||
return recipeTable.main( recipes ) | |||
end | end | ||
function | |||
local | -- Called from Modul:GetRecipes | ||
-- Calls Modul:RecipeTable | |||
if | -- Returns the wikitext returned by Modul:RecipeTable | ||
function p.formattedItem( products, ingredients, item ) | |||
-- Format the recipes, and call RecipeTable on each table | |||
local recipeTable = require( "Modul:RecipeTable" ) | |||
local returnVal = '=== '..L.t('Crafting Recipes')..' ===\n\n' | |||
if (products ~= nil and #products ~= 0) then | |||
returnVal = returnVal .. recipeTable.main( formatRecipes(products) ) .. '\n\n=== '..L.t('Used in Recipes')..' ===\n\n' | |||
else | |||
returnVal = returnVal .. "''"..L.t('None').."''\n\n=== "..L.t('Used in Recipes').." ===\n\n " | |||
end | end | ||
if | |||
if (ingredients ~= nil and #ingredients ~= 0) then | |||
returnVal = returnVal .. recipeTable.main( formatRecipes(ingredients) ) | |||
else | else | ||
returnVal = returnVal .. "''"..L.t('None').."''\n" | |||
end | end | ||
return returnVal | |||
return | |||
end | end | ||
-- | -- Called from Modul:GetRecipes | ||
--function | -- Calls Modul:RecipeTable | ||
-- | -- Returns formatted wikitext, including wikitext returned from Modul:RecipeTable | ||
function p.formattedTable( recipes, table ) | |||
-- Format the recipes, and call RecipeTable | |||
local recipeTable = require( "Modul:RecipeTable" ) | |||
local returnVal = '=== ' .. L.t('Recipes at %s'):format(table) .. ' ===\n\n' | |||
if #recipes == 0 then | |||
returnVal = returnVal .. "''"..L.t('None').."''\n" | |||
else | |||
returnVal = returnVal .. recipeTable.main( formatRecipes( recipes ) ) | |||
end | |||
return returnVal | |||
end | |||
-- Called from Modul:GetRecipes | |||
-- Calls Modul:RecipeTable | |||
-- Returns formatted wikitext, including wikitext returned from Modul:RecipeTable | |||
function p.formattedGroup( recipes, group ) | |||
-- Format the recipes, and call RecipeTable | |||
local recipeTable = require( "Modul:RecipeTable" ) | |||
local returnVal = '=== ' .. L.t('%s Recipes'):format(group) .. ' ===\n\n' | |||
if #recipes == 0 then | |||
returnVal = returnVal .. "''"..L.t('None').."''\n" | |||
else | |||
returnVal = returnVal .. recipeTable.main( formatRecipes( recipes ) ) | |||
end | end | ||
return returnVal | |||
return | |||
end | end | ||
return p | return p |
Version vom 23. August 2021, 06:01 Uhr
Documentation
This module is a part of the Vorlage:GetRecipes, and is used to generate a wikitable of recipes. It returns a wikitable as a string. The wikitable contains all of the recipes that were passed into the module.
If the template is passed, this module is used with the following Modules:
-- Modul:CraftingParser (https://wiki.play.eco/en/Modul:CraftingParser)
local p = {}
local Utils = require('Modul:Utils')
local L = require('Modul:Localization')
-- Compares two recipes ( a < b ? true : false )
function recipeCompare(a, b)
--not in v0.9
--if not a.efficiencySkills[1] and not b.efficiencySkills[1] then return false
--elseif a.efficiencySkills[1] and not b.efficiencySkills[1] then return false
--elseif not a.efficiencySkills[1] and b.efficiencySkills[1] then return true
--elseif a.efficiencySkills[1] < b.efficiencySkills[1] then return true
--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
end
end
-- Parses arguments into a table of recipes
function frameParse( args )
local parsedRecipes = {}
-- Set variables
local dispCraftStn = tonumber( args.displayCraftStation )
local checkImage = tonumber( args.checkForImage )
-- Iterate over every recipe passed in
for i = 1, args.numRecipes do
table.insert( parsedRecipes, i, {
['dispCraftStn'] = dispCraftStn,
['checkImage'] = checkImage,
['craftStn'] = {args['craftStation'..i], args['craftStationImg'..i]},
['item1'] = {args['item'..i..'.1'], args['itemImg'..i..'.1'], args['itemNum'..i..'.1']},
['item2'] = {args['item'..i..'.2'], args['itemImg'..i..'.2'], args['itemNum'..i..'.2']},
['skillNeed'] = {args['skillNeed'..i], args['skillNeedImg'..i], args['skillLvlNeed'..i]},
['mater1'] = {args['material'..i..'.1'], args['materialImg'..i..'.1'], args['materialNum'..i..'.1']},
['mater2'] = {args['material'..i..'.2'], args['materialImg'..i..'.2'], args['materialNum'..i..'.2']},
['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']},
['cTime'] = args['craftTime'..i],
['affSkill1'] = {args['affectSkill'..i..'.1'], args['affectSkillImg'..i..'.1']},
['affSkill2'] = {args['affectSkill'..i..'.2'], args['affectSkillImg'..i..'.2']},
--TODO - construct new parts of the table here
})
end
return parsedRecipes
end
-- Formats and sorts recipes
function formatRecipes( recipes )
-- Sort recipes
table.sort( recipes, recipeCompare )
return recipes
end
-- Called from Template:RecipeTable
-- Calls Modul:RecipeTable
-- Returns the wikitext returned by Modul:RecipeTable
function p.raw( f )
-- get args from the Template, parse them into recipes
local recipes = frameParse( Utils.normaliseArgs(f) )
-- Format the recipes
recipes = formatRecipes( recipes )
-- Call RecipeTable
local recipeTable = require( "Modul:RecipeTable" )
return recipeTable.main( recipes )
end
-- Called from Modul:GetRecipes
-- Calls Modul:RecipeTable
-- Returns the wikitext returned by Modul:RecipeTable
function p.formattedItem( products, ingredients, item )
-- Format the recipes, and call RecipeTable on each table
local recipeTable = require( "Modul:RecipeTable" )
local returnVal = '=== '..L.t('Crafting Recipes')..' ===\n\n'
if (products ~= nil and #products ~= 0) then
returnVal = returnVal .. recipeTable.main( formatRecipes(products) ) .. '\n\n=== '..L.t('Used in Recipes')..' ===\n\n'
else
returnVal = returnVal .. "''"..L.t('None').."''\n\n=== "..L.t('Used in Recipes').." ===\n\n "
end
if (ingredients ~= nil and #ingredients ~= 0) then
returnVal = returnVal .. recipeTable.main( formatRecipes(ingredients) )
else
returnVal = returnVal .. "''"..L.t('None').."''\n"
end
return returnVal
end
-- Called from Modul:GetRecipes
-- Calls Modul:RecipeTable
-- Returns formatted wikitext, including wikitext returned from Modul:RecipeTable
function p.formattedTable( recipes, table )
-- Format the recipes, and call RecipeTable
local recipeTable = require( "Modul:RecipeTable" )
local returnVal = '=== ' .. L.t('Recipes at %s'):format(table) .. ' ===\n\n'
if #recipes == 0 then
returnVal = returnVal .. "''"..L.t('None').."''\n"
else
returnVal = returnVal .. recipeTable.main( formatRecipes( recipes ) )
end
return returnVal
end
-- Called from Modul:GetRecipes
-- Calls Modul:RecipeTable
-- Returns formatted wikitext, including wikitext returned from Modul:RecipeTable
function p.formattedGroup( recipes, group )
-- Format the recipes, and call RecipeTable
local recipeTable = require( "Modul:RecipeTable" )
local returnVal = '=== ' .. L.t('%s Recipes'):format(group) .. ' ===\n\n'
if #recipes == 0 then
returnVal = returnVal .. "''"..L.t('None').."''\n"
else
returnVal = returnVal .. recipeTable.main( formatRecipes( recipes ) )
end
return returnVal
end
return p