17,101
edits
(getShopMiscUpgradeTable: Include requirements column) |
(getPurchaseBuyLimit: Initial implementation; _getShopTable: Support "Buy Limit" column) |
||
Line 2: | Line 2: | ||
local ShopData = mw.loadData('Module:Shop/data') | local ShopData = mw.loadData('Module:Shop/data') | ||
local ConstantData = mw.loadData('Module:Constants/data') | |||
-- Data instead of Module:CombatAreas to avoid loop whne that module attempts to require Module:Shop | -- Data instead of Module:CombatAreas to avoid loop whne that module attempts to require Module:Shop | ||
local AreaData = require('Module:CombatAreas/data') | local AreaData = require('Module:CombatAreas/data') | ||
Line 213: | Line 214: | ||
local args = frame.args ~= nil and frame.args or frame | local args = frame.args ~= nil and frame.args or frame | ||
local purchaseName = args[1] | local purchaseName = args[1] | ||
local asList = | local asList = (args[2] ~= nil and string.upper(args[2]) == 'TRUE') | ||
local purchase = p.getPurchase(purchaseName) | local purchase = p.getPurchase(purchaseName) | ||
Line 221: | Line 222: | ||
return p._getPurchaseContents(purchase, asList) | return p._getPurchaseContents(purchase, asList) | ||
end | end | ||
end | |||
function p._getPurchaseBuyLimit(purchase, asList) | |||
if asList == nil then asList = true end | |||
if type(purchase.buyLimit) == 'table' then | |||
local limitTable = {} | |||
local gamemodeHasIcon = { 1, 2 } | |||
-- Populate limitTable for each game mode to be included | |||
for id, modeName in pairs(ConstantData.gamemode) do | |||
if tonumber(id) ~= nil and string.upper(modeName) ~= 'CHAOS' then | |||
local buyLimit = tostring(purchase.buyLimit[id + 1]) | |||
if limitTable[buyLimit] == nil then | |||
limitTable[buyLimit] = {} | |||
end | |||
local gamemodeText = '[[Game Mode#' .. modeName .. '|' .. modeName .. ']]' | |||
if Shared.contains(gamemodeHasIcon, id) then | |||
gamemodeText = Icons.Icon({modeName, notext=(not asList or nil)}) | |||
end | |||
table.insert(limitTable[buyLimit], gamemodeText) | |||
end | |||
end | |||
local numLimits = Shared.tableCount(limitTable) | |||
local resultPart = {} | |||
for buyLimit, gameModes in Shared.skpairs(limitTable, true) do | |||
local limitText = (buyLimit == '0' and 'Unlimited' or tostring(buyLimit)) | |||
if numLimits == 1 then | |||
-- Buy limit is the same for all game modes | |||
return limitText | |||
else | |||
table.insert(resultPart, limitText .. (asList and ' for ' or ' ') .. mw.text.listToText(gameModes, ', ', (asList and ' and ' or ', '))) | |||
end | |||
end | |||
return table.concat(resultPart, (asList and ' or ' or '<br/>')) | |||
end | |||
end | |||
function p.getPurchaseBuyLimit(frame) | |||
local args = frame.args ~= nil and frame.args or frame | |||
local purchaseName = args[1] | |||
local asList = (args[2] ~= nil and string.upper(args[2]) == 'TRUE') | |||
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._getPurchaseBuyLimit(purchase, asList) | |||
end | |||
end | end | ||
Line 266: | Line 315: | ||
function p._getShopTable(Purchases, options) | function p._getShopTable(Purchases, options) | ||
local availableColumns = { 'Purchase', 'Type', 'Description', 'Cost', 'Requirements' } | local availableColumns = { 'Purchase', 'Type', 'Description', 'Cost', 'Requirements', 'Buy Limit' } | ||
local headerPropsDefault = { | local headerPropsDefault = { | ||
["Purchase"] = 'colspan="2"', | ["Purchase"] = 'colspan="2"', | ||
Line 360: | Line 409: | ||
elseif column == 'Requirements' then | elseif column == 'Requirements' then | ||
table.insert(resultPart, '| ' .. p.getRequirementString(purchase.unlockRequirements)) | table.insert(resultPart, '| ' .. p.getRequirementString(purchase.unlockRequirements)) | ||
elseif column == 'Buy Limit' then | |||
local buyLimit = p._getPurchaseBuyLimit(purchase, false) | |||
local sortValue = (tonumber(buyLimit) == nil and -1 or buyLimit) | |||
table.insert(resultPart, '| data-sort-value="' .. sortValue .. '"| ' .. buyLimit) | |||
else | else | ||
-- Shouldn't be reached, but will prevent the resulting table becoming horribly mis-aligned if it ever happens | -- Shouldn't be reached, but will prevent the resulting table becoming horribly mis-aligned if it ever happens |