Module:BlacksmithSmeltingList: Difference between revisions

From Brighter Shores Wiki
Jump to navigation Jump to search
Content added Content deleted
(Created page with "require('strict') require('Module:Mw.html extension') local recipe = require('Module:Infobox Recipe') -- to make use of its extensive material searching function local param = require( 'Module:Paramtest' ) local currency = require('Module:Currency') local discount = require('Module:MerchantHideDiscount') local lang = mw.getContentLanguage() local p = {} -- non dynamic module, no inputs function p.main() -- returns only directly needed parameter needed for the row, -...")
 
(icon)
Line 54: Line 54:
:tag('tr')
:tag('tr')
:tag('th')
:tag('th')
:wikitext('[[File:Bonewright small icon.png|15px]] Level')
:wikitext('[[File:Blacksmith small icon.png|15px]] Level')
:done()
:done()
:tag('th')
:tag('th')

Revision as of 16:38, 5 December 2024

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.

require('strict')
require('Module:Mw.html extension')
local recipe = require('Module:Infobox Recipe') -- to make use of its extensive  material searching function
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local discount = require('Module:MerchantHideDiscount')
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