Module:Recipe: Difference between revisions

No edit summary
No edit summary
 
(11 intermediate revisions by 2 users not shown)
Line 43: Line 43:
end
end


local function addUseCategory(category, name, sort)
local function addUseCategory(category, name, quality, sort)
  if not name or tostring(name) == '' then
if not name or tostring(name) == '' then
    return
return
  end
end
 
if quality and tostring(quality) ~= '' then
if sort and tostring(sort) ~= '' then
category:wikitext('[[Category:Uses ', quality, '-Quality ', name, '|', sort, ']]')
else
category:wikitext('[[Category:Uses ', quality, '-Quality ', name, ']]')
end
 
return
end


  if sort then
if sort and tostring(sort) ~= '' then
    category:wikitext('[[Category:Uses ', name, '|', sort, ']]')
category:wikitext('[[Category:Uses ', name, '|', sort, ']]')
  else
else
    category:wikitext('[[Category:Uses ', name, ']]')
category:wikitext('[[Category:Uses ', name, ']]')
  end
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
local function getQualityClass(quality)
  if not quality or tostring(quality) == '' then
    return nil
  end
  return 'card-quality-' .. normalizeText(quality)
end
end


Line 67: Line 85:
     name = sName,
     name = sName,
     text = sAmt,
     text = sAmt,
     show_caption = '1',
     show_caption = '1'
    mobile = 'bulleted'
   }
   }


Line 80: Line 97:
     category,
     category,
     sName,
     sName,
    quality,
     padLeft(tostring(sAmt or ''):gsub('%D', ''), 10)
     padLeft(tostring(sAmt or ''):gsub('%D', ''), 10)
   )
   )
Line 91: Line 109:
     text = sText or '',
     text = sText or '',
     show_caption = '1',
     show_caption = '1',
    mobile = 'bulleted',
     mini = '1'
     mini = '1'
   }
   }
Line 119: Line 136:


local function renderHeader(args, output, category)
local function renderHeader(args, output, category)
   local header = output:tag('div'):addClass('recipe_header')
   local header = output:tag('div'):addClass('recipe-header')
   local sType = args[param.sTypeArg]
   local sType = args[param.sTypeArg]


   header:tag('span'):addClass('recipe_header_main')
   header:tag('span'):addClass('recipe-header-main')
    -- Preserved from original module
     :tag('span'):addClass('recipe-header-text'):wikitext('[[' .. sType .. ']]'):done()
    :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 210: Line 224:
   end
   end


   header:tag('span'):addClass('recipe_header_sub')
   header:tag('span'):addClass('recipe-header-sub')
     :tag('span'):addClass('mobileHide'):wikitext(' for '):done()
     :tag('span'):wikitext(' for '):done()
    :tag('span'):addClass('hidden'):wikitext(' for '):done()
     :tag('span'):addClass('recipe-header-text'):wikitext(sTime):done()
     :tag('span'):addClass('recipe_header_text'):wikitext(sTime):done()
end
end


Line 223: Line 236:
   local sCharName = args[param.sCharArg]
   local sCharName = args[param.sCharArg]


   header:tag('span'):addClass('recipe_header_sub')
   header:tag('span'):addClass('recipe-header-sub')
     :tag('span'):addClass('mobileHide'):wikitext(' with '):done()
    :tag('span'):wikitext('[[File:' .. sCharName .. ' Icon.png|24x24px|link=' .. sCharName .. ']]'):done()
     :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('recipe_header_text'):wikitext('[[' .. sCharName .. ']]'):done()
end
 
local function renderKitchenwareHeader(args, header)
  if type(args[param.sKitchArg]) ~= 'string' then
     return
  end
 
  local sKitchName = args[param.sKitchArg]
 
  header:tag('span'):addClass('recipe-header-sub')
    :tag('span'):wikitext('[[File:' .. sKitchName .. ' Icon.png|24x24px|link=' .. sKitchName .. ']]'):done()
     :tag('span'):addClass('recipe-header-text'):wikitext('[[' .. sKitchName .. ']]'):done()
end
end


Line 248: Line 272:
   end
   end


   local sYield = args[param.sYieldArg] or '1'
   local sYield = args[param.sYieldArg] or nil
   local pageTitle = getCurrentPageName(args)
   local pageTitle = getCurrentPageName(args)


Line 254: Line 278:


   body
   body
     :tag('div'):addClass('recipe_body_icon')
     :tag('div'):addClass('recipe-body-icon')
       :wikitext('➜'):done()
       :wikitext('➜'):done()
     :tag('div'):addClass('recipe_body_yield')
     :tag('div'):addClass('recipe-body-yield')
       :node(yieldCard)
       :node(yieldCard)
end
end
Line 268: Line 292:
   renderCharacter(args, header)
   renderCharacter(args, header)


   local body = output:tag('div'):addClass('recipe_body')
   local body = output:tag('div'):addClass('recipe-body')


   local sSortDelim = param.sSortDelim
   local sSortDelim = param.sSortDelim
Line 276: Line 300:
   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 284: Line 307:
   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 322: Line 344:
   local ingredient = {
   local ingredient = {
     index = index,
     index = index,
     amount = args[prefix .. '_amount'] or '1',
     amount = args[prefix .. '_amount'] or nil,
     quality = args[prefix .. '_quality'],
     quality = args[prefix .. '_quality'],
     item = args[prefix],
     item = args[prefix],
Line 329: Line 351:
   }
   }


  -- 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 345: Line 362:
   end
   end


  -- Multiple accepted specific items:
  -- |item_1_option_1 = Rice
  -- |item_1_option_2 = Wheat
   local optionIndex = 1
   local optionIndex = 1


Line 367: Line 381:
end
end


local function getKitchenware(args)
--------------------------------------------------------------------------------
  local kitchenware = {}
-- Cooking type split-card helpers
--------------------------------------------------------------------------------


   if argExists(args, 'kitchenware') then
local function makeTypeIcon(typeName)
     table.insert(kitchenware, args.kitchenware)
   return '[[File:' .. typeName .. ' Icon.png|74x74px|link=' .. typeName .. ']]'
end
 
local function joinTypeCaption(types)
  local out = {}
 
  for _, typeName in ipairs(types) do
     table.insert(out, '[[' .. typeName .. ']]')
   end
   end


   local index = 1
   return table.concat(out, ' / ')
end
 
local function renderCookingSplitTypeCard(category, body, ingredient)
  local qualityClass = getQualityClass(ingredient.quality or 'Gray')
 
  local container = body:tag('span')
    :addClass('card-container')
    :addClass('recipe-type-split-card')
 
  local wrapper = container:tag('span')
    :addClass('card-wrapper')
 
  local cardBody = wrapper:tag('span')
    :addClass('card-body')
 
  local imageContainer = cardBody:tag('span')
    :addClass('card-image-container')
    :addClass('recipe-type-split-image')
 
  imageContainer:tag('span')
    :addClass('recipe-type-split-half')
    :addClass('recipe-type-split-half-a')
    :wikitext(makeTypeIcon(ingredient.types[1]))
    :done()
 
  imageContainer:tag('span')
    :addClass('recipe-type-split-half')
    :addClass('recipe-type-split-half-b')
    :wikitext(makeTypeIcon(ingredient.types[2]))
    :done()
   
if qualityClass then
    imageContainer:addClass(qualityClass)
end


   while argExists(args, 'kitchenware_' .. index) do
   if tostring(ingredient.amount or '') ~= '' then
     table.insert(kitchenware, args['kitchenware_' .. index])
     container:tag('span')
    index = index + 1
      :addClass('card-label')
      :wikitext(tostring(ingredient.amount or '1'))
      :done()
   end
   end


   return kitchenware
   container:tag('span')
    :addClass('card-caption')
    :wikitext(joinTypeCaption(ingredient.types))
    :done()
 
  for _, typeName in ipairs(ingredient.types) do
    addUseCategory(category, typeName)
  end
end
end


Line 397: Line 462:
end
end


local function renderCookingTypeCards(category, body, ingredient)
local function renderCookingTypeFallback(category, body, ingredient)
   local wrapper = body:tag('div')
   local wrapper = body:tag('div')
     :addClass('recipe_body_cooking_ingredient')
     :addClass('recipe-body-cooking-ingredient')
     :addClass('recipe_body_cooking_type_cards')
     :addClass('recipe-body-cooking-type-cards')


   for _, typeName in ipairs(ingredient.types) do
   for _, typeName in ipairs(ingredient.types) do
Line 409: Line 474:
       ingredient.quality
       ingredient.quality
     ))
     ))
  end
end
local function renderCookingTypeCards(category, body, ingredient)
  if #ingredient.types == 2 then
    renderCookingSplitTypeCard(category, body, ingredient)
  else
    renderCookingTypeFallback(category, body, ingredient)
   end
   end
end
end
Line 414: Line 487:
local function renderCookingOptionCards(category, body, ingredient)
local function renderCookingOptionCards(category, body, ingredient)
   local wrapper = body:tag('div')
   local wrapper = body:tag('div')
     :addClass('recipe_body_cooking_ingredient')
     :addClass('recipe-body-cooking-ingredient')
     :addClass('recipe_body_cooking_option_cards')
     :addClass('recipe-body-cooking-option-cards')


   for _, itemName in ipairs(ingredient.options) do
   for _, itemName in ipairs(ingredient.options) do
Line 428: Line 501:


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 435: Line 506:
   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 443: Line 511:
   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
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(args, header)
  if type(args[param.sKitchArg]) ~= 'string' then
    return
  end
  local sKitchName = args[param.sKitchArg]
  header:tag('span'):addClass('recipe_header_sub')
    :tag('span'):addClass('mobileHide'):wikitext(' with '):done()
    :tag('span'):addClass('hidden'):wikitext('[[File:' .. sKitchName .. ' Icon.png|24x24px|link=' .. sKitchName .. ']]'):done()
    :tag('span'):addClass('recipe_header_text'):wikitext('[[' .. sKitchName .. ']]'):done()
end
end


Line 496: Line 522:
   end
   end


   local sYield = args[param.sYieldArg] or '1'
   local sYield = args[param.sYieldArg] or nil
   local pageTitle = getCurrentPageName(args)
   local pageTitle = getCurrentPageName(args)


Line 502: Line 528:


   body
   body
     :tag('div'):addClass('recipe_body_icon')
     :tag('div'):addClass('recipe-body-icon')
       :wikitext('➜'):done()
       :wikitext('➜'):done()
     :tag('div'):addClass('recipe_body_yield')
     :tag('div'):addClass('recipe-body-yield')
       :node(yieldCard)
       :node(yieldCard)
end
end
Line 513: Line 539:
   renderTime(args, header)
   renderTime(args, header)
   renderCharacter(args, header)
   renderCharacter(args, header)
   renderKitchenwareSlot(args, header)
   renderKitchenwareHeader(args, header)


   local body = output:tag('div')
   local body = output:tag('div')
     :addClass('recipe_body')
     :addClass('recipe-body')
     :addClass('recipe_body_cooking')
     :addClass('recipe-body-cooking')


   local foundIngredient = false
   local foundIngredient = false
Line 557: Line 583:
function p._main(args, frame)
function p._main(args, frame)
   local output = mw.html.create('div')
   local output = mw.html.create('div')
     :addClass('recipe_container')
     :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()