Module:BlacksmithSmeltingList: Difference between revisions

From Brighter Shores Wiki
Jump to navigation Jump to search
Content added Content deleted
(icon)
(shorten name of smelter)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
require('strict')
require('strict')
require('Module:Mw.html extension')
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 param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local currency = require('Module:Currency')
local discount = require('Module:MerchantHideDiscount')
local lang = mw.getContentLanguage()
local lang = mw.getContentLanguage()


Line 63: Line 61:
:done()
:done()
:tag('th')
:tag('th')
:wikitext('Facility')
:wikitext('Smelter')
:done()
:done()
:tag('th')
:tag('th')
Line 88: Line 86:
:done()
:done()
:tag('td')
:tag('td')
:wikitext('[[File:' .. item.facility .. '.png|30px|link=' .. item.facility .. ']] [[' .. item.facility .. ']]<br>')
:wikitext('[[File:' .. item.facility .. '.png|30px|link=' .. item.facility .. ']] [[' .. item.facility .. '|' .. string.gsub(item.facility,' Smelter','') .. ']]')
:done()
:done()
:IF(item.XP)
:IF(item.XP)

Latest revision as of 00:37, 9 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.
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('Smelter')
			: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 .. '|' .. string.gsub(item.facility,' Smelter','') .. ']]')
			: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