Module:StonemasonEtchingList

From Brighter Shores Wiki
Revision as of 22:09, 19 December 2024 by Alsang (talk | contribs) (offload much of the search, screen, and format functions to the new ProfessionList module, so they work the same for all table)
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:StonemasonEtchingList/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:StonemasonEtchingList/doc. [edit]
Module:StonemasonEtchingList's function main is invoked by Template:StonemasonEtchingList.
Module:StonemasonEtchingList requires Module:Mw.html extension.
Module:StonemasonEtchingList requires Module:ProfessionList.
Module:StonemasonEtchingList requires Module:RecipeTreeSearch.
Module:StonemasonEtchingList requires strict.

require('strict')
require('Module:Mw.html extension')
local lang = mw.getContentLanguage()
local plist = require('Module:ProfessionList')
local rts = require('Module:RecipeTreeSearch')

local p = {}

-- non dynamic module, no inputs
function p.main()
	
	local queryString = '[[Category:Stonemason]] AND [[Category:Pages with recipes]]'
	
	local function screenFunction(item)
		return item.facility=='T.E.A. Machine'
	end
	
	local results = plist.generate_recipe_table(queryString,screenFunction)

	results = p.formatResults(results)

	return p.displayTable(results)
	
	--for debugging
	--return '<pre>'..mw.text.jsonEncode(results, mw.text.JSON_PRETTY)..'</pre>'

end

-- do calculations and determine strings to go in cells
function p.formatResults(results)
	
	--simple check for nil results
	if results ==nil or results[1] == nil then
		return nil
	end
	
	-- iterate through products
	for _, item in ipairs(results) do
		
		item.material = (item.materials and item.materials[1] and item.materials[1].name) or ''
		
	end

	return results
end

-- make the table
function p.displayTable(results)
	
	--simple check for nil results
	if results ==nil or results[1] == nil then
		return 'No data found for table'
	end
	
	local out = mw.html.create('table')
		:addClass('wikitable sortable')
		:tag('tr')
			:tag('th')
				:wikitext('[[File:Stonemason small icon.png|15px]]  Level')
			:done()
			:tag('th')
				:attr{ colspan = '2' }
				:wikitext('Product')
			:done()
			:tag('th')
				:attr{ colspan = '2' }
				:wikitext('Material')
			:done()
			:tag('th')
				:wikitext('XP')
			:done()
		:done()

	for i, item in ipairs(results) do
		local row = out:tag('tr')
		
			--level
			:IF(item.level)
				:tag('td')
					:css{ ['text-align'] = 'center' }
					:wikitext(item.level)
				:done()
			:ELSE()
				:node(plist.unknown_value_edit_cell(item.pageName,1))
			:END()
			
			-- product
			:node(plist.two_column_image_text(item.product,'File:' .. item.product .. '.png',item.product,item.product))
			:node(plist.two_column_image_text(item.material,'File:' .. item.material .. '.png',item.material,item.material))

			-- XP
			:IF(item.xp)
				:tag('td')
					:css{ ['text-align'] = 'center' }
					:wikitext(item.xp and lang:formatNum(tonumber(item.xp)))
				:done()
			:ELSE()
				:node(plist.unknown_value_edit_cell(item.pageName,1))
			:END()
			
		:done()
	end

	return out
end

return p