Module:Item Usage: Difference between revisions

No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 127: Line 127:
end
end


-- Multiple kitchenware, in case you later use:
-- Multiple kitchenware:
-- |kitchenware_1 =
-- |kitchenware_1 =
-- |kitchenware_2 =
-- |kitchenware_2 =
Line 267: Line 267:


return nil
return nil
end
local function renderCookingIngredients(recipe)
local ingredients = {}
local maxIndex = getMaxCookingItemIndex(recipe)
for index = 1, maxIndex do
local rendered = renderCookingIngredient(recipe, index)
if isNotEmpty(rendered) then
table.insert(ingredients, rendered)
end
end
return ingredients
end
end


Line 284: Line 299:
end
end


if #kitchenware == 0 then
return kitchenware
return nil
end
 
return '<b>Kitchenware:</b> ' .. table.concat(kitchenware, ' / ')
end
end


local function renderCookingIngredients(recipe)
local function renderRecipeIngredients(recipe)
local ingredients = {}
if isCookingRecipe(recipe) then
local maxIndex = getMaxCookingItemIndex(recipe)
return renderCookingIngredients(recipe)
 
for index = 1, maxIndex do
local rendered = renderCookingIngredient(recipe, index)
 
if isNotEmpty(rendered) then
table.insert(ingredients, rendered)
end
end
end


local kitchenware = renderCookingKitchenware(recipe)
return renderStandardIngredients(recipe)
 
if isNotEmpty(kitchenware) then
table.insert(ingredients, kitchenware)
end
 
return ingredients
end
end


local function renderRecipeIngredients(recipe)
local function hasCookingRecipes(valids)
if isCookingRecipe(recipe) then
for _, recipes in pairs(valids) do
return renderCookingIngredients(recipe)
for _, recipe in pairs(recipes) do
if isCookingRecipe(recipe) then
return true
end
end
end
end


return renderStandardIngredients(recipe)
return false
end
end


Line 398: Line 400:
function p._main(valids, craftType)
function p._main(valids, craftType)
local _table = mw.html.create('table'):addClass('wikitable article-table sortable')
local _table = mw.html.create('table'):addClass('wikitable article-table sortable')
local showKitchenware = hasCookingRecipes(valids)


-- Header row
-- Header row
Line 403: Line 406:
tr:tag('th'):wikitext('Item')
tr:tag('th'):wikitext('Item')
tr:tag('th'):wikitext('Craft Type')
tr:tag('th'):wikitext('Craft Type')
if showKitchenware then
tr:tag('th'):wikitext('Kitchenware')
end
tr:tag('th'):wikitext(craftType == 'Furnishing Set' and 'Components' or 'Recipe')
tr:tag('th'):wikitext(craftType == 'Furnishing Set' and 'Components' or 'Recipe')


Line 443: Line 451:
:css{['text-align'] = 'center'}
:css{['text-align'] = 'center'}
:wikitext('[[', recipe[Rlib.sTypeArg], ']]')
:wikitext('[[', recipe[Rlib.sTypeArg], ']]')
if showKitchenware then
if isCookingRecipe(recipe) then
local kitchenware = renderCookingKitchenware(recipe)
tr:tag('td'):wikitext(table.concat(kitchenware, '<br>'))
else
tr:tag('td'):wikitext('—')
end
end


local ingredients = renderRecipeIngredients(recipe)
local ingredients = renderRecipeIngredients(recipe)