Module:BlacksmithSmeltingList

Revision as of 18:20, 6 December 2024 by Alsang (talk | contribs) (remove merchant hide module)
Module documentation
This documentation is transcluded from Module:BlacksmithSmeltingList/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:BlacksmithSmeltingList/doc. [edit]
Module:BlacksmithSmeltingList's function main is invoked by Template:BlacksmithSmeltingList.
Module:BlacksmithSmeltingList requires Module:Currency.
Module:BlacksmithSmeltingList requires Module:Mw.html extension.
Module:BlacksmithSmeltingList requires Module:Paramtest.
Module:BlacksmithSmeltingList 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::Goblin Smelter||Gnome Smelter]]', -- smelting
		'?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:Blacksmith small icon.png|15px]]  Level')
			:done()
			:tag('th')
				:wikitext('Product')
			:done()
			:tag('th')
				:wikitext('Material')
			:done()
			:tag('th')
				:wikitext('Facility')
			: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()
			:tag('td')
				:wikitext('[[File:' .. item.facility .. '.png|30px|link=' .. item.facility .. ']] [[' .. item.facility .. ']]<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