17,097
edits
(getShopTable: Implement columnProps parameter & document other parameters) |
(Implement getPurchase, getPurchaseStat, getCostString, _getPurchaseType, _getPurchaseContents, getPurchaseIcon; facilitates implementing a 'PurchaseBox' template) |
||
Line 8: | Line 8: | ||
local Constants = require('Module:Constants') | local Constants = require('Module:Constants') | ||
local Areas = require('Module:CombatAreas') | local Areas = require('Module:CombatAreas') | ||
-- Overrides for various items, mostly relating to icon overrides | |||
local purchOverrides = { | |||
["Extra Bank Slot"] = { icon = {'Bank Slot', 'upgrade'}, link = 'Bank Slot', cost = Icons.Icon({'Coins', size = 25, notext = true}) .. ' <span style="font-size:127%; font-family: MathJax_Math; font-style: italic;">C<sub>b</sub></span>*' }, | |||
-- Golbin Raid items | |||
["Reduce Wave Skip Cost"] = { icon = {'Melvor Logo', nil}, link = nil }, | |||
["Food Bonus"] = { icon = {'Melvor Logo', nil}, link = nil }, | |||
["Ammo Gatherer"] = { icon = {'Melvor Logo', nil}, link = nil }, | |||
["Rune Pouch"] = { icon = {'Melvor Logo', nil}, link = nil }, | |||
["Increase Starting Prayer Points"] = { icon = {'Melvor Logo', nil}, link = nil }, | |||
["Unlock Combat Passive Slot"] = { icon = {'Melvor Logo', nil}, link = nil }, | |||
["Prayer"] = { icon = {'Prayer', 'skill'}, link = nil }, | |||
["Increase Prayer Level"] = { icon = {'Prayer', 'skill'}, link = nil }, | |||
["Increase Prayer Points gained per Wave Completion"] = { icon = {'Prayer', 'skill'}, link = nil } | |||
} | |||
function p.getPurchase(purchaseName) | |||
for categoryName, categoryData in pairs(ShopData.Shop) do | |||
for i, purchase in ipairs(categoryData) do | |||
if purchase.name == purchaseName then | |||
return p.processPurchase(categoryName, i - 1) | |||
end | |||
end | |||
end | |||
end | |||
function p.processPurchase(category, purchaseID) | function p.processPurchase(category, purchaseID) | ||
Line 16: | Line 41: | ||
end | end | ||
function p.getCostString(cost) | function p._getPurchaseStat(purchase, stat, inline) | ||
local displayInline = (inline ~= nil and inline or false) | |||
if stat == 'cost' then | |||
return p.getCostString(purchase.cost, displayInline) | |||
elseif stat == 'requirements' then | |||
return p.getRequirementString(purchase.unlockRequirements) | |||
elseif stat == 'contents' then | |||
return p._getPurchaseContents(purchase) | |||
elseif stat == 'type' then | |||
return p._getPurchaseType(purchase) | |||
else | |||
return purchase[stat] | |||
end | |||
end | |||
function p.getPurchaseStat(frame) | |||
local args = frame.args ~= nil and frame.args or frame | |||
local purchaseName = args[1] | |||
local statName = args[2] | |||
local displayInline = (args['inline'] ~= nil and string.lower(args['inline']) == 'true' or false) | |||
local purchase = p.getPurchase(purchaseName) | |||
if purchase == nil then | |||
return "ERROR: Couldn't find purchase with name '" .. purchaseName .. "'[[Category:Pages with script errors]]" | |||
else | |||
return p._getPurchaseStat(purchase, statName, displayInline) | |||
end | |||
end | |||
function p.getCostString(cost, inline) | |||
local displayInline = (inline ~= nil and inline or false) | |||
local costArray = {} | local costArray = {} | ||
if cost.gp ~= nil and cost.gp > 0 then | if cost.gp ~= nil and cost.gp > 0 then | ||
Line 31: | Line 86: | ||
for i, itemCost in Shared.skpairs(cost.items) do | for i, itemCost in Shared.skpairs(cost.items) do | ||
local item = Items.getItemByID(itemCost[1]) | local item = Items.getItemByID(itemCost[1]) | ||
table.insert(itemArray, Icons.Icon({item.name, type="item", notext=true, qty=itemCost[2]})) | table.insert(itemArray, Icons.Icon({item.name, type="item", notext=(not displayInline and true or nil), qty=itemCost[2]})) | ||
end | end | ||
Line 39: | Line 94: | ||
end | end | ||
return | local sep, lastSep = '<br/>', nil | ||
if displayInline then | |||
sep = ', ' | |||
lastSep = Shared.tableCount(costArray) > 2 and ', and ' or ' and ' | |||
end | |||
return Shared.joinList(costArray, sep, lastSep) | |||
end | end | ||
Line 90: | Line 150: | ||
return table.concat(reqArray, '<br/>') | return table.concat(reqArray, '<br/>') | ||
end | |||
function p._getPurchaseType(purchase) | |||
if purchase.contains == nil then | |||
return 'Unknown' | |||
elseif purchase.contains.pet ~= nil then | |||
return 'Pet' | |||
elseif purchase.contains.modifiers ~= nil or purchase.contains.items == nil or Shared.tableCount(purchase.contains.items) == 0 then | |||
return 'Upgrade' | |||
elseif purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 1 then | |||
return 'Item Bundle' | |||
else | |||
return 'Item' | |||
end | |||
end | |||
function p._getPurchaseContents(purchase) | |||
local containArray = {} | |||
if purchase.contains.items ~= nil then | |||
for i, itemLine in Shared.skpairs(purchase.contains.items) do | |||
local item = Items.getItemByID(itemLine[1]) | |||
table.insert(containArray, Icons.Icon({item.name, type='item', qty=itemLine[2]})) | |||
end | |||
end | |||
if purchase.charges ~= nil and purchase.charges > 0 then | |||
table.insert(containArray, '+'..purchase.charges..' '..Icons.Icon({purchase.name, type='item'})..' Charges') | |||
end | |||
return table.concat(containArray, '<br/>') | |||
end | |||
-- Accept similar arguments to Icons.Icon | |||
function p._getPurchaseIcon(iconArgs) | |||
local purchase = iconArgs[1] | |||
local override = purchOverrides[purchase.name] | |||
local purchType = p._getPurchaseType(purchase) | |||
-- Amend iconArgs before passing to Icons.Icon() | |||
iconArgs[1] = ((override ~= nil and override.icon[1]) or purchase.name) | |||
if override ~= nil then | |||
iconArgs['type'] = override.icon[2] | |||
if override.link == nil then | |||
iconArgs['nolink'] = true | |||
end | |||
else | |||
iconArgs['type'] = (purchType == 'Item Bundle' and 'item') or string.lower(purchType) | |||
end | |||
return Icons.Icon(iconArgs) | |||
end | |||
function p.getPurchaseIcon(frame) | |||
local args = frame.args ~= nil and frame.args or frame | |||
local purchaseName = args[1] | |||
local purchase = p.getPurchase(purchaseName) | |||
if purchase == nil then | |||
return "ERROR: Couldn't find purchase with name '" .. purchaseName .. "'[[Category:Pages with script errors]]" | |||
else | |||
args[1] = purchase | |||
return p._getPurchaseIcon(args) | |||
end | |||
end | end | ||
Line 178: | Line 298: | ||
end | end | ||
local purchType = | local purchType = p._getPurchaseType(purchase) | ||
local iconNoLink = nil | local iconNoLink = nil | ||
local purchLink = '' | local purchLink = '' | ||
local costString = p.getCostString(purchase.cost) | local costString = p.getCostString(purchase.cost, false) | ||
if purchOverride ~= nil then | if purchOverride ~= nil then | ||
if purchOverride.link == nil then | if purchOverride.link == nil then | ||
iconNoLink = true | iconNoLink = true | ||
Line 211: | Line 317: | ||
for j, column in ipairs(usedColumns) do | for j, column in ipairs(usedColumns) do | ||
if column == 'Purchase' then | if column == 'Purchase' then | ||
table.insert(resultPart, '|style="min-width:25px"|' .. Icons.Icon({iconName, type=iconType, notext=true, nolink=iconNoLink, size='50'})) | table.insert(resultPart, '|style="min-width:25px"|' .. p._getPurchaseIcon({purchase, notext=true, size='50'})) | ||
--table.insert(resultPart, '|style="min-width:25px"|' .. Icons.Icon({iconName, type=iconType, notext=true, nolink=iconNoLink, size='50'})) | |||
table.insert(resultPart, '| ' .. purchName) | table.insert(resultPart, '| ' .. purchName) | ||
elseif column == 'Type' then | elseif column == 'Type' then | ||
Line 332: | Line 439: | ||
result = result..'\r\n|-\r\n!style="text-align:right;"|Cost' | result = result..'\r\n|-\r\n!style="text-align:right;"|Cost' | ||
result = result..'\r\n|'..p.getCostString(purchase.cost) | result = result..'\r\n|'..p.getCostString(purchase.cost, false) | ||
result = result..'\r\n|-\r\n!style="text-align:right;"|Requirements' | result = result..'\r\n|-\r\n!style="text-align:right;"|Requirements' | ||
Line 338: | Line 445: | ||
result = result..'\r\n|-\r\n!style="text-align:right;"|Contains' | result = result..'\r\n|-\r\n!style="text-align:right;"|Contains' | ||
result = result..'\r\n|style="text-align:right;"|'..p._getPurchaseContents(purchase) | |||
result = result..'\r\n|style="text-align:right;"|'.. | |||
result = result..'\r\n|}' | result = result..'\r\n|}' | ||
Line 441: | Line 538: | ||
end | end | ||
end | end | ||
local upgradeList = p.getPurchases( | local upgradeList = p.getPurchases( | ||
function(cat, purch) | function(cat, purch) | ||
Line 464: | Line 561: | ||
table.insert(resultPart, '| ' .. upgrade.description) | table.insert(resultPart, '| ' .. upgrade.description) | ||
table.insert(resultPart, '| data-sort-value="' .. dung.name .. '"| ' .. Icons.Icon({dung.name, type='dungeon'})) | table.insert(resultPart, '| data-sort-value="' .. dung.name .. '"| ' .. Icons.Icon({dung.name, type='dungeon'})) | ||
table.insert(resultPart, '| style="text-align:right;" data-sort-value="' .. costSortValue .. '"| ' .. p.getCostString(upgrade.cost)) | table.insert(resultPart, '| style="text-align:right;" data-sort-value="' .. costSortValue .. '"| ' .. p.getCostString(upgrade.cost, false)) | ||
end | end | ||
table.insert(resultPart, '|}') | table.insert(resultPart, '|}') |