4,951
edits
Falterfire (talk | contribs) (Moved to generic getShopTable) |
Falterfire (talk | contribs) (Added p.getPurchases for use in the ModifierTables module I'm working on) |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
local Constants = require('Module:Constants') | local Constants = require('Module:Constants') | ||
local Areas = require('Module:CombatAreas') | local Areas = require('Module:CombatAreas') | ||
function p.processPurchase(category, purchaseID) | |||
local purchase = Shared.clone(ShopData.Shop[category][purchaseID + 1]) | |||
purchase.id = purchaseID | |||
purchase.category = category | |||
return purchase | |||
end | |||
function p.getCostString(cost) | function p.getCostString(cost) | ||
Line 17: | Line 24: | ||
table.insert(costArray, Icons.SC(cost.slayerCoins)) | table.insert(costArray, Icons.SC(cost.slayerCoins)) | ||
end | end | ||
local itemArray = {} | |||
if cost.items ~= nil then | if cost.items ~= nil then | ||
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( | table.insert(itemArray, Icons.Icon({item.name, type="item", notext=true, qty=itemCost[2]})) | ||
end | |||
if Shared.tableCount(itemArray) > 0 then | |||
table.insert(costArray, table.concat(itemArray, ", ")) | |||
end | end | ||
end | end | ||
return table.concat(costArray, " | return table.concat(costArray, "<br/>") | ||
end | end | ||
Line 64: | Line 76: | ||
table.insert(reqArray, Icons.Icon({purchase.name, type=(isUpgrade and 'upgrade' or 'item')})..' Purchased') | table.insert(reqArray, Icons.Icon({purchase.name, type=(isUpgrade and 'upgrade' or 'item')})..' Purchased') | ||
end | end | ||
end | |||
if reqs.completionPercentage ~= nil then | |||
table.insert(reqArray, tostring(reqs.completionPercentage) .. '% Completion Log') | |||
end | |||
if reqs.text ~= nil then | |||
table.insert(reqArray, reqs.text) | |||
end | end | ||
Line 72: | Line 92: | ||
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: | result = result..'\r\n!colspan="2"|Purchase!!Type!!Description!!style="min-width:100"|Cost!!Requirements' | ||
for i, purchase in Shared.skpairs(Purchases) do | for i, purchase in Shared.skpairs(Purchases) do | ||
Line 111: | Line 131: | ||
return p._getShopTable(shopCat) | return p._getShopTable(shopCat) | ||
end | end | ||
end | |||
function p.getItemCostArray(itemID) | |||
local purchaseArray = {} | |||
for catName, cat in Shared.skpairs(ShopData.Shop) do | |||
for j, purchase in Shared.skpairs(cat) do | |||
if purchase.cost.items ~= nil then | |||
for k, costLine in Shared.skpairs(purchase.cost.items) do | |||
if costLine[1] == itemID then | |||
local temp = p.processPurchase(catName, j - 1) | |||
temp.qty = costLine[2] | |||
table.insert(purchaseArray, temp) | |||
break | |||
end | |||
end | |||
end | |||
end | |||
end | |||
return purchaseArray | |||
end | |||
function p.getItemSourceArray(itemID) | |||
local purchaseArray = {} | |||
for catName, cat in Shared.skpairs(ShopData.Shop) do | |||
for j, purchase in Shared.skpairs(cat) do | |||
if purchase.contains.items ~= nil and purchase.contains.items ~= nil then | |||
for k, containsLine in Shared.skpairs(purchase.contains.items) do | |||
if containsLine [1] == itemID then | |||
local temp = p.processPurchase(catName, j - 1) | |||
temp.qty = containsLine[2] | |||
table.insert(purchaseArray, temp) | |||
break | |||
end | |||
end | |||
end | |||
end | |||
end | |||
return purchaseArray | |||
end | |||
function p.getPurchases(checkFunc) | |||
local purchaseList = {} | |||
for category, purchaseArray in Shared.skpairs(ShopData.Shop) do | |||
for i, purchase in Shared.skpairs(purchaseArray) do | |||
if checkFunc(purchase) then | |||
table.insert(purchaseList, p.processPurchase(category, i - 1)) | |||
end | |||
end | |||
end | |||
return purchaseList | |||
end | |||
function p._getPurchaseTable(purchase) | |||
local result = '{| class="wikitable"\r\n|-' | |||
result = result..'\r\n!colspan="2"|'..Icons.Icon({'Shop'})..' Purchase' | |||
if purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 1 then | |||
result = result..' - '..Icons.Icon({purchase.name, type='item'}) | |||
end | |||
result = result..'\r\n|-\r\n!style="text-align:right;"|Cost' | |||
result = result..'\r\n|'..p.getCostString(purchase.cost) | |||
result = result..'\r\n|-\r\n!style="text-align:right;"|Requirements' | |||
result = result..'\r\n|'..p.getRequirementString(purchase.unlockRequirements) | |||
result = result..'\r\n|-\r\n!style="text-align:right;"|Contains' | |||
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 | |||
result = result..'\r\n|style="text-align:right;"|'..table.concat(containArray, '<br/>') | |||
result = result..'\r\n|}' | |||
return result | |||
end | |||
function p._getItemShopTable(item) | |||
local tableArray = {} | |||
local purchaseArray = p.getItemSourceArray(item.id) | |||
for i, purchase in Shared.skpairs(purchaseArray) do | |||
table.insert(tableArray, p._getPurchaseTable(purchase)) | |||
end | |||
return table.concat(tableArray, '\r\n\r\n') | |||
end | |||
function p.getItemShopTable(frame) | |||
local itemName = frame.args ~= nil and frame.args[1] or frame | |||
local item = Items.getItem(itemName) | |||
if item == nil then | |||
return "ERROR: No item named "..itemName.." exists in the data module" | |||
end | |||
return p._getItemShopTable(item) | |||
end | end | ||
return p | return p |