Module:BonewrightBrewingList
Jump to navigation
Jump to search
Module documentation
This documentation is transcluded from Module:BonewrightBrewingList/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:BonewrightBrewingList/doc. [edit]
Module:BonewrightBrewingList's function main is invoked by Template:BonewrightBrewingList.
Module:BonewrightBrewingList requires Module:Currency.
Module:BonewrightBrewingList requires Module:Mw.html extension.
Module:BonewrightBrewingList requires Module:Paramtest.
Module:BonewrightBrewingList requires strict.
require('strict')
require('Module:Mw.html extension')
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local lang = mw.getContentLanguage()
local p = {}
-- non dynamic module, no inputs
function p.main()
-- returns only directly needed parameter needed for the row,
-- other parameters are determined by subqueries of chained pages
local query = {
'[[Uses facility::B.R.E.W.S. Vat]]', -- etching
'?Uses facility #- = facility',
'?Profession Level A = lvl',
'? #- = name',
'?Recipe JSON = recipeJSON',
'?Activity XP = XP',
'?Uses item #- = rawmat',
'sort = Profession Level A',
'limit = 500'
}
local results = mw.smw.ask(query)
return p.displayTable(results)
--for debugging
--return '<pre>'..mw.text.jsonEncode(results, mw.text.JSON_PRETTY)..'</pre>'
end
-- makes the html for the cells containing currency directly
-- Replaces nil with an "unknown" cell
local function currency_cell(amount)
if not amount then
return mw.html.create('td')
:addClass('table-bg-gray')
:css{ ['text-align'] = 'center' }
:attr{ colspan = '10' }
:wikitext("''unknown''")
:done()
end
return currency._cell(amount, { html = 'yes' })
end
-- make the table
function p.displayTable(results)
local out = mw.html.create('table')
:addClass('wikitable sortable')
:tag('tr')
:tag('th')
:wikitext('[[File:Bonewright small icon.png|15px]] Level')
:done()
:tag('th')
:wikitext('Product')
:done()
:tag('th')
:wikitext('Material')
:done()
:tag('th')
:wikitext('XP')
:done()
:done()
local unknown_value_cell = mw.html.create('td')
:addClass('table-bg-gray')
:css{ ['text-align'] = 'center' }
:wikitext("''unknown''")
for i, item in ipairs(results) do
local row = out:tag('tr')
:tag('td')
:css{ ['text-align'] = 'center' }
:wikitext(item.lvl)
:done()
:tag('td')
:wikitext('[[File:' .. item.name .. '.png|link=' .. item.name .. '|30px]] [[' .. item.name .. ']]')
:done()
:tag('td')
:wikitext('[[File:' .. item.rawmat .. '.png|30px|link=' .. item.rawmat .. ']] [[' .. item.rawmat .. ']]<br>')
:done()
:IF(item.XP)
:tag('td')
:css{ ['text-align'] = 'center' }
:wikitext(item.XP and lang:formatNum(tonumber(item.XP)))
:done()
:ELSE()
:node(unknown_value_cell)
:END()
:done()
end
return out
end
return p