Editing Module:Recipe
Appearance
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 6: | Line 6: | ||
local param = { | local param = { | ||
sCharArg = 'character', | sCharArg = 'character', | ||
sTypeArg = 'type', | sTypeArg = 'type', | ||
sSortArg = 'sort', | sSortArg = 'sort', | ||
| Line 43: | Line 42: | ||
end | end | ||
local function addUseCategory(category, name | local function addUseCategory(category, name, sort) | ||
if not name or tostring(name) == '' then | |||
return | |||
end | |||
if sort then | |||
category:wikitext('[[Category:Uses ', name, '|', sort, ']]') | |||
else | |||
category:wikitext('[[Category:Uses ', name, ']]') | |||
end | |||
end | end | ||
local function getCurrentPageName(args) | local function getCurrentPageName(args) | ||
return args[param.sPage] or args.page or mw.title.getCurrentTitle().text | return args[param.sPage] or args.page or mw.title.getCurrentTitle().text | ||
end | end | ||
| Line 85: | Line 66: | ||
name = sName, | name = sName, | ||
text = sAmt, | text = sAmt, | ||
show_caption = '1' | show_caption = '1', | ||
mobile = 'bulleted' | |||
} | } | ||
| Line 97: | Line 79: | ||
category, | category, | ||
sName, | sName, | ||
padLeft(tostring(sAmt or ''):gsub('%D', ''), 10) | padLeft(tostring(sAmt or ''):gsub('%D', ''), 10) | ||
) | ) | ||
| Line 109: | Line 90: | ||
text = sText or '', | text = sText or '', | ||
show_caption = '1', | show_caption = '1', | ||
mobile = 'bulleted', | |||
mini = '1' | mini = '1' | ||
} | } | ||
| Line 136: | Line 118: | ||
local function renderHeader(args, output, category) | local function renderHeader(args, output, category) | ||
local header = output:tag('div'):addClass(' | local header = output:tag('div'):addClass('recipe_header') | ||
local sType = args[param.sTypeArg] | local sType = args[param.sTypeArg] | ||
header:tag('span'):addClass(' | header:tag('span'):addClass('recipe_header_main') | ||
:tag('span'):addClass(' | -- Preserved from original module | ||
:tag('span'):addClass('mobileHide'):wikitext('<big>' .. sType .. '</big>'):done() | |||
:tag('span'):addClass('mobileHide'):wikitext('<big>' .. sType .. '</big>'):done() | |||
:tag('span'):addClass('recipe_header_text'):wikitext('[[' .. sType .. ']]'):done() | |||
category:wikitext('[[Category:' .. sType .. ']]') | category:wikitext('[[Category:' .. sType .. ']]') | ||
| Line 224: | Line 209: | ||
end | end | ||
header:tag('span'):addClass(' | header:tag('span'):addClass('recipe_header_sub') | ||
:tag('span'):wikitext(' for '):done() | :tag('span'):addClass('mobileHide'):wikitext(' for '):done() | ||
:tag('span'):addClass(' | :tag('span'):addClass('hidden'):wikitext(' for '):done() | ||
:tag('span'):addClass('recipe_header_text'):wikitext(sTime):done() | |||
end | end | ||
| Line 236: | Line 222: | ||
local sCharName = args[param.sCharArg] | local sCharName = args[param.sCharArg] | ||
header:tag('span'):addClass(' | header:tag('span'):addClass('recipe_header_sub') | ||
:tag('span'):addClass('mobileHide'):wikitext(' with '):done() | |||
:tag('span'):addClass(' | :tag('span'):addClass('hidden'):wikitext('[[File:' .. sCharName .. ' Icon.png|24x24px|link=' .. sCharName .. ']]'):done() | ||
:tag('span'):addClass('recipe_header_text'):wikitext('[[' .. sCharName .. ']]'):done() | |||
:tag('span'):addClass(' | |||
end | end | ||
| Line 272: | Line 247: | ||
end | end | ||
local sYield = args[param.sYieldArg] or | local sYield = args[param.sYieldArg] or '1' | ||
local pageTitle = getCurrentPageName(args) | local pageTitle = getCurrentPageName(args) | ||
| Line 278: | Line 253: | ||
body | body | ||
:tag('div'):addClass(' | :tag('div'):addClass('recipe_body_icon') | ||
:wikitext('➜'):done() | :wikitext('➜'):done() | ||
:tag('div'):addClass(' | :tag('div'):addClass('recipe_body_yield') | ||
:node(yieldCard) | :node(yieldCard) | ||
end | end | ||
| Line 292: | Line 267: | ||
renderCharacter(args, header) | renderCharacter(args, header) | ||
local body = output:tag('div'):addClass(' | local body = output:tag('div'):addClass('recipe_body') | ||
local sSortDelim = param.sSortDelim | local sSortDelim = param.sSortDelim | ||
| Line 300: | Line 275: | ||
end | end | ||
-- Process sort parameter. | |||
for sKey in string.gmatch(args[param.sSortArg] or '', '([^' .. sSortDelim .. ']+)') do | for sKey in string.gmatch(args[param.sSortArg] or '', '([^' .. sSortDelim .. ']+)') do | ||
if type(args[sKey]) ~= 'nil' then | if type(args[sKey]) ~= 'nil' then | ||
| Line 307: | Line 283: | ||
end | end | ||
-- Process rest of unrestricted parameters. | |||
for sKey, sVal in pairs(args) do | for sKey, sVal in pairs(args) do | ||
if tArgsProcessed[sKey] ~= true and not isRestrictedStandardParam(sKey) then | if tArgsProcessed[sKey] ~= true and not isRestrictedStandardParam(sKey) then | ||
| Line 344: | Line 321: | ||
local ingredient = { | local ingredient = { | ||
index = index, | index = index, | ||
amount = args[prefix .. '_amount'] or | amount = args[prefix .. '_amount'] or '1', | ||
quality = args[prefix .. '_quality'], | quality = args[prefix .. '_quality'], | ||
item = args[prefix], | item = args[prefix], | ||
| Line 351: | Line 328: | ||
} | } | ||
-- Specific type: | |||
-- |item_1_type = Fish | |||
if argExists(args, prefix .. '_type') then | if argExists(args, prefix .. '_type') then | ||
table.insert(ingredient.types, args[prefix .. '_type']) | table.insert(ingredient.types, args[prefix .. '_type']) | ||
end | end | ||
-- Multiple accepted types: | |||
-- |item_1_type_1 = Freshwater Fish | |||
-- |item_1_type_2 = Saltwater Fish | |||
local typeIndex = 1 | local typeIndex = 1 | ||
| Line 362: | Line 344: | ||
end | end | ||
-- Multiple accepted specific items: | |||
-- |item_1_option_1 = Rice | |||
-- |item_1_option_2 = Wheat | |||
local optionIndex = 1 | local optionIndex = 1 | ||
| Line 381: | Line 366: | ||
end | end | ||
local function getKitchenware(args) | |||
local kitchenware = {} | |||
if argExists(args, 'kitchenware') then | |||
table.insert(kitchenware, args.kitchenware) | |||
table.insert( | |||
end | end | ||
local index = 1 | |||
local | |||
while argExists(args, 'kitchenware_' .. index) do | |||
table.insert(kitchenware, args['kitchenware_' .. index]) | |||
index = index + 1 | |||
end | end | ||
return kitchenware | |||
end | end | ||
| Line 462: | Line 396: | ||
end | end | ||
local function | local function renderCookingTypeCards(category, body, ingredient) | ||
local wrapper = body:tag('div') | local wrapper = body:tag('div') | ||
:addClass(' | :addClass('recipe_body_cooking_ingredient') | ||
:addClass(' | :addClass('recipe_body_cooking_type_cards') | ||
for _, typeName in ipairs(ingredient.types) do | for _, typeName in ipairs(ingredient.types) do | ||
| Line 474: | Line 408: | ||
ingredient.quality | ingredient.quality | ||
)) | )) | ||
end | end | ||
end | end | ||
| Line 487: | Line 413: | ||
local function renderCookingOptionCards(category, body, ingredient) | local function renderCookingOptionCards(category, body, ingredient) | ||
local wrapper = body:tag('div') | local wrapper = body:tag('div') | ||
:addClass(' | :addClass('recipe_body_cooking_ingredient') | ||
:addClass(' | :addClass('recipe_body_cooking_option_cards') | ||
for _, itemName in ipairs(ingredient.options) do | for _, itemName in ipairs(ingredient.options) do | ||
| Line 501: | Line 427: | ||
local function renderCookingIngredient(category, body, ingredient) | local function renderCookingIngredient(category, body, ingredient) | ||
-- Specific item: | |||
-- |item_1 = Rice | |||
if ingredient.item then | if ingredient.item then | ||
renderCookingSpecificItem(category, body, ingredient) | renderCookingSpecificItem(category, body, ingredient) | ||
| Line 506: | Line 434: | ||
end | end | ||
-- Multiple accepted specific items: | |||
-- |item_1_option_1 = Rice | |||
-- |item_1_option_2 = Wheat | |||
if #ingredient.options > 0 then | if #ingredient.options > 0 then | ||
renderCookingOptionCards(category, body, ingredient) | renderCookingOptionCards(category, body, ingredient) | ||
| Line 511: | Line 442: | ||
end | end | ||
-- Type-based ingredient: | |||
-- |item_1_type = Fish | |||
-- |item_1_type_1 = Freshwater Fish | |||
-- |item_1_type_2 = Saltwater Fish | |||
if #ingredient.types > 0 then | if #ingredient.types > 0 then | ||
renderCookingTypeCards(category, body, ingredient) | renderCookingTypeCards(category, body, ingredient) | ||
return | return | ||
end | |||
end | |||
--[[ | |||
local function renderKitchenwareSlot(category, body, args) | |||
local kitchenware = getKitchenware(args) | |||
if #kitchenware == 0 then | |||
body:tag('div') | |||
:addClass('recipe_body_icon') | |||
:wikitext('➜') | |||
return | |||
end | |||
local wrapper = body:tag('div') | |||
:addClass('recipe_body_icon') | |||
:addClass('recipe_body_kitchenware_cards') | |||
for _, kitchenwareName in ipairs(kitchenware) do | |||
wrapper:node(addMiniCard( | |||
category, | |||
kitchenwareName, | |||
'', | |||
nil | |||
)) | |||
end | |||
end | |||
--]] | |||
local function renderKitchenwareSlot(category, body, args) | |||
local kitchenware = getKitchenware(args) | |||
if #kitchenware == 0 then | |||
body:tag('div') | |||
:addClass('recipe_body_icon') | |||
:wikitext('➜') | |||
return | |||
end | |||
local slot = body:tag('div') | |||
:addClass('recipe_body_icon') | |||
:addClass('recipe_header_sub') | |||
for i, kitchenwareName in ipairs(kitchenware) do | |||
if i > 1 then | |||
slot:tag('span') | |||
:addClass('recipe_header_text') | |||
:wikitext(' / ') | |||
:done() | |||
end | |||
slot | |||
:tag('span'):addClass('mobileHide') | |||
:wikitext('[[File:Icon_' .. kitchenwareName .. '.png|35x35px|link=' .. kitchenwareName .. ']]'):done() | |||
:tag('span'):addClass('hidden') | |||
:wikitext('[[File:Icon_' .. kitchenwareName .. '.png|35x35px|link=' .. kitchenwareName .. ']]'):done() | |||
:tag('span'):addClass('recipe_header_text') | |||
:wikitext('[[' .. kitchenwareName .. ']]'):done() | |||
addUseCategory(category, kitchenwareName) | |||
end | end | ||
end | end | ||
| Line 522: | Line 517: | ||
end | end | ||
local sYield = args[param.sYieldArg] or | local sYield = args[param.sYieldArg] or '1' | ||
local pageTitle = getCurrentPageName(args) | local pageTitle = getCurrentPageName(args) | ||
local yieldCard = addYieldCard(pageTitle, sYield) | local yieldCard = addYieldCard(pageTitle, sYield) | ||
renderKitchenwareSlot(category, body, args) | |||
body:tag('div') | |||
:addClass('recipe_body_yield') | |||
:node(yieldCard) | |||
end | end | ||
| Line 539: | Line 534: | ||
renderTime(args, header) | renderTime(args, header) | ||
renderCharacter(args, header) | renderCharacter(args, header) | ||
local body = output:tag('div') | local body = output:tag('div') | ||
:addClass(' | :addClass('recipe_body') | ||
:addClass(' | :addClass('recipe_body_cooking') | ||
local foundIngredient = false | local foundIngredient = false | ||
| Line 583: | Line 577: | ||
function p._main(args, frame) | function p._main(args, frame) | ||
local output = mw.html.create('div') | local output = mw.html.create('div') | ||
:addClass(' | :addClass('recipe_container') | ||
-- Must be local per render. | |||
-- Keeping this global can cause category leakage between recipe calls. | |||
local category = mw.html.create() | local category = mw.html.create() | ||