Module:Recipe: Difference between revisions

No edit summary
let's see how much this breaks.
Line 57: Line 57:
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 123: Line 131:


   header:tag('span'):addClass('recipe_header_main')
   header:tag('span'):addClass('recipe_header_main')
    -- 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('mobileHide'):wikitext('<big>' .. sType .. '</big>'):done()
     :tag('span'):addClass('mobileHide'):wikitext('<big>' .. sType .. '</big>'):done()
Line 227: Line 234:
     :tag('span'):addClass('hidden'):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'):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 276: Line 296:
   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 303:
   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 329: Line 347:
   }
   }


  -- 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 358:
   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 377:
end
end


local function getKitchenware(args)
--------------------------------------------------------------------------------
   local kitchenware = {}
-- Cooking type split-card helpers
--------------------------------------------------------------------------------
 
local function makeTypeIcon(typeName)
  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
 
  return table.concat(out, ' / ')
end
 
local function renderCookingSplitTypeCard(category, body, ingredient)
  local qualityClass = getQualityClass(ingredient.quality)
 
  local container = body:tag('span')
    :addClass('card-container')
    :addClass('recipe-type-split-card')


   if argExists(args, 'kitchenware') then
   if qualityClass then
     table.insert(kitchenware, args.kitchenware)
     container:addClass(qualityClass)
   end
   end


   local index = 1
   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()


   while argExists(args, 'kitchenware_' .. index) do
   imageContainer:tag('span')
     table.insert(kitchenware, args['kitchenware_' .. index])
    :addClass('recipe-type-split-half')
     index = index + 1
     :addClass('recipe-type-split-half-b')
    :wikitext(makeTypeIcon(ingredient.types[2]))
     :done()
 
  if tostring(ingredient.amount or '') ~= '' then
    cardBody:tag('span')
      :addClass('card-text')
      :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 458:
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')
Line 409: Line 470:
       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 428: Line 497:


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 502:
   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 507:
   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 513: Line 535:
   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')
Line 559: Line 581:
     :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()