Module:Shop: Difference between revisions

1,103 bytes added ,  1 August 2021
getShopTable: Implement columnProps parameter & document other parameters
(getGodUpgradeTable: Initial implementation)
(getShopTable: Implement columnProps parameter & document other parameters)
Line 235: Line 235:
end
end


-- getShopTable parameter definition:
--  columns:        Comma separated values indicating which columns are to be included & the order
--                  in which they are displayed.
--                  Values can be any of: Purchase, Type, Description, Cost, Requirements
--  columnProps:    Comma separated values indicating formatting to be applied to each column. Each
--                  value must be in the format column:property, e.g. Purchase:colspan="2"
--  sortOrder:      A function determining the order in which table items appear
--  purchaseHeader: Specifies header text for the Purchase column if not 'Purchase'
function p.getShopTable(frame)
function p.getShopTable(frame)
   local cat = frame.args ~= nil and frame.args[1] or frame
   local cat = frame.args ~= nil and frame.args[1] or frame
Line 242: Line 250:
     if frame.args.purchaseHeader ~= nil then options.purchaseHeader = frame.args.purchaseHeader end
     if frame.args.purchaseHeader ~= nil then options.purchaseHeader = frame.args.purchaseHeader end
     if frame.args.sortOrder ~= nil then options.sortOrder = frame.args.sortOrder end
     if frame.args.sortOrder ~= nil then options.sortOrder = frame.args.sortOrder end
    if frame.args.columnProps ~= nil then
      local columnPropValues = Shared.splitString(frame.args.columnProps, ',')
      local columnProps = {}
      for i, prop in pairs(columnPropValues) do
        local propName, propValue = string.match(prop, '^([^:]+):(.*)$')
        if propName ~= nil then
          columnProps[propName] = propValue
        end
      end
      if Shared.tableCount(columnProps) > 0 then options.headerProps = columnProps end
    end
   end
   end
   local shopCat = ShopData.Shop[cat]
   local shopCat = ShopData.Shop[cat]