Module:GELimits
Jump to navigation
Jump to search
Module documentation
This documentation is transcluded from Module:GELimits/doc. [edit] [history] [purge]
Module:GELimits loads data from Module:GELimits/data.json.
main
takes a single unnamed argument that is the items name and returns the GE Limit of the item, or 0 if the item is not found.
table
Generates tables of all the GE Limits, with ==
sections for # and each letter.
local p = {}
local data = mw.loadJsonData('Module:GELimits/data.json')
function p.main(frame)
local args = frame:getParent().args[1]
return data[args] or 0
end
function p.table(frame)
local sectionString = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ"
local bySection = {}
for name, _ in pairs(data) do
local letter = string.sub(name, 1, 1)
if letter ~= '%' then
if string.find(sectionString, letter) == nil then
letter = "#"
end
if bySection[letter] == nil then
bySection[letter] = {}
end
table.insert(bySection[letter], name)
end
end
local ret = {}
for i = 1, #sectionString do
local sectionHeader = sectionString:sub(i, i)
local limits = bySection[sectionHeader]
if limits ~= nil then
table.sort(limits)
table.insert(ret, '\n\n=='..sectionHeader..'==\n')
local inner = mw.html.create('table')
:addClass('wikitable')
:addClass('sortable')
:tag('tr')
:tag('th')
:wikitext('Item')
:done()
:tag('th')
:wikitext('Limit')
:done()
:done()
for _, name in ipairs(limits) do
local limit = data[name]
row = inner:tag('tr')
:tag('td')
:wikitext('[[Exchange:' .. name .. '|' .. name .. ']]')
:done()
:tag('td')
:wikitext(limit)
:done()
:done()
end
inner:done()
table.insert(ret, tostring(inner))
end
end
return mw.text.trim(table.concat(ret, ''))
end
function p.table_nosections(frame)
local lang = mw.getContentLanguage()
function fnum(x)
if tonumber(x) then
return lang:formatNum(tonumber(x))
end
return x
end
function sortfunc(a,b)
return a[1] < b[1]
end
local ret = mw.html.create('table')
ret:addClass('wikitable align-right-2 sortable')
:tag('tr')
:tag('th'):wikitext('Item'):done()
:tag('th'):wikitext('Limit'):done()
:done()
:newline()
local data_list = {}
for name,limit in pairs(data) do
if name ~= '%LAST_UPDATE%' and name ~= '%LAST_UPDATE_F%' then
table.insert(data_list, {name,limit})
end
end
table.sort(data_list, sortfunc)
for _,info in ipairs(data_list) do
ret:tag('tr')
:tag('td'):wikitext('[['..info[1]..']]'):done()
:tag('td'):wikitext(fnum(info[2])):attr('data-sort-value',info[2]):done()
:done()
:newline()
end
return ret
end
return p