Anonymous

Module:Shop: Difference between revisions

From Melvor Idle
getCostString/_getShopTable: Support Golbin Raid shop items
(Added p.getPurchases for use in the ModifierTables module I'm working on)
(getCostString/_getShopTable: Support Golbin Raid shop items)
Line 23: Line 23:
   if cost.slayerCoins ~= nil and cost.slayerCoins > 0 then
   if cost.slayerCoins ~= nil and cost.slayerCoins > 0 then
     table.insert(costArray, Icons.SC(cost.slayerCoins))
     table.insert(costArray, Icons.SC(cost.slayerCoins))
  end
  if cost.raidCoins ~= nil and cost.raidCoins > 0 then
    table.insert(costArray, Icons.RC(cost.raidCoins))
   end
   end
   local itemArray = {}
   local itemArray = {}
Line 92: Line 95:
   local result = '{| class="wikitable sortable stickyHeader"'
   local result = '{| class="wikitable sortable stickyHeader"'
   result = result..'\r\n|- class="headerRow-0"'
   result = result..'\r\n|- class="headerRow-0"'
   result = result..'\r\n!colspan="2"|Purchase!!Type!!Description!!style="min-width:100"|Cost!!Requirements'
   result = result..'\r\n!colspan="2"|Purchase!!Type!!Description!!style="min-width:110px"|Cost!!Requirements'


  local costCurrencies = {'gp', 'slayerCoins', 'raidCoins'}
   for i, purchase in Shared.skpairs(Purchases) do
   for i, purchase in Shared.skpairs(Purchases) do
     result = result..'\r\n|-\r\n|'
     result = result..'\r\n|-\r\n|'


     local isUpgrade = purchase.contains.items == nil or Shared.tableCount(purchase.contains.items) == 0
     local purchType = 'Item'
     local isBundle = purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 1
    if purchase.contains.pet ~= nil then
    local iconTxt = purchase.name
      purchType = 'Pet'
    result = result..Icons.Icon({purchase.name, type=(isUpgrade and 'upgrade' or 'item'), notext=true, size='50'})
    elseif purchase.contains.modifiers ~= nil or purchase.contains.items == nil or Shared.tableCount(purchase.contains.items) == 0 then
    result = result..'||'..purchase.name..'||'
      purchType = 'Upgrade'
    if isUpgrade then
     elseif purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 1 then
       result = result..'Upgrade'
       purchType = 'Item Bundle'
    elseif isBundle then
      result = result..'Item Bundle'
    else
      result = result..'Item'
     end
     end


    -- Translate certain media strings to icons, mostly for Golbin Raid shop objects
    local iconOverrides = {
      ["assets/media/main/logo.svg"] = { icon = 'Melvor Logo', type = nil },
      ["assets/media/skills/prayer/prayer.svg"] = { icon = 'Prayer', type = 'skill' }
    }
    local iconName, iconType = purchase.name, (purchType == 'Item Bundle' and 'item' or string.lower(purchType))
    if iconOverrides[purchase.media] ~= nil then
      iconName, iconType = iconOverrides[purchase.media].icon, iconOverrides[purchase.media].type
    end
    result = result..Icons.Icon({iconName, type=iconType, notext=true, size='50'})
    result = result..'||'..purchase.name..'||'..purchType
     result = result..'||'..purchase.description..'||style="text-align:right;"'
     result = result..'||'..purchase.description..'||style="text-align:right;"'
     if purchase.cost.gp ~= nil and purchase.cost.gp > 0 then
 
       result = result..' data-sort-value="'..purchase.cost.gp..'"'
     for j, curr in Shared.skpairs(costCurrencies) do
    elseif purchase.cost.slayerCoins ~= nil and purchase.cost.slayerCoins > 0 then
       local costAmt = purchase.cost[curr]
      result = result..' data-sort-value="'..purchase.cost.slayerCoins..'"'
      if costAmt ~= nil and costAmt > 0 then
        result = result..' data-sort-value="'..costAmt..'"'
        break
      end
     end
     end
     result = result..'|'..p.getCostString(purchase.cost)..'||'..p.getRequirementString(purchase.unlockRequirements)
     result = result..'|'..p.getCostString(purchase.cost)..'||'..p.getRequirementString(purchase.unlockRequirements)