Module:BlacksmithSmeltingList: Difference between revisions

From Brighter Shores Wiki
Jump to navigation Jump to search
Content added Content deleted
(shorten name of smelter)
(offload much of the search, screen, and format functions to the new ProfessionList module, so they work the same for all table)
Line 1: Line 1:
require('strict')
require('strict')
require('Module:Mw.html extension')
require('Module:Mw.html extension')
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local lang = mw.getContentLanguage()
local lang = mw.getContentLanguage()
local plist = require('Module:ProfessionList')
local rts = require('Module:RecipeTreeSearch')


local p = {}
local p = {}
Line 9: Line 9:
-- non dynamic module, no inputs
-- non dynamic module, no inputs
function p.main()
function p.main()
-- returns only directly needed parameter needed for the row,
-- other parameters are determined by subqueries of chained pages
local queryString = '[[Category:Blacksmith]] AND [[Category:Pages with recipes]]'
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)
local function screenFunction(item)
return (item.facility=='Goblin Smelter' or item.facility=='Gnome Smelter')
end
local results = plist.generate_recipe_table(queryString,screenFunction)

results = p.formatResults(results)

return p.displayTable(results)
return p.displayTable(results)
Line 32: Line 27:
end
end


-- do calculations and determine strings to go in cells
-- makes the html for the cells containing currency directly
function p.formatResults(results)
-- Replaces nil with an "unknown" cell
local function currency_cell(amount)
--simple check for nil results
if not amount then
if results ==nil or results[1] == nil then
return mw.html.create('td')
return nil
:addClass('table-bg-gray')
:css{ ['text-align'] = 'center' }
:attr{ colspan = '10' }
:wikitext("''unknown''")
:done()
end
end
return currency._cell(amount, { html = 'yes' })
-- iterate through products
for _, item in ipairs(results) do
if item.facility=='Goblin Smelter' then
item.facilityDisplay = 'Goblin'
else
item.facilityDisplay = 'Gnome'
end
item.material = (item.materials and item.materials[1] and item.materials[1].name) or ''
end

return results
end
end


-- make the table
-- make the table
function p.displayTable(results)
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')
local out = mw.html.create('table')
:addClass('wikitable sortable')
:addClass('wikitable sortable')
Line 55: Line 66:
:done()
:done()
:tag('th')
:tag('th')
:attr{ colspan = '2' }
:wikitext('Product')
:wikitext('Product')
:done()
:done()
:tag('th')
:tag('th')
:attr{ colspan = '2' }
:wikitext('Material')
:wikitext('Material')
:done()
:done()
:tag('th')
:tag('th')
:attr{ colspan = '2' }
:wikitext('Smelter')
:wikitext('Smelter')
:done()
:done()
Line 67: Line 81:
:done()
:done()
: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
for i, item in ipairs(results) do
local row = out:tag('tr')
local row = out:tag('tr')
:tag('td')
--level
:css{ ['text-align'] = 'center' }
:wikitext(item.lvl)
:IF(item.level)
: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')
:tag('td')
:css{ ['text-align'] = 'center' }
:css{ ['text-align'] = 'center' }
:wikitext(item.XP and lang:formatNum(tonumber(item.XP)))
:wikitext(item.level)
:done()
:done()
:ELSE()
:ELSE()
:node(plist.unknown_value_edit_cell(item.pageName,1))
:node(unknown_value_cell)
:END()
:END()
:done()
-- 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))
:node(plist.two_column_image_text(item.facility,'File:' .. item.facility .. '.png',item.facilityDisplay,item.facility))


-- 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
end



Revision as of 22:05, 19 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:Mw.html extension.
Module:BlacksmithSmeltingList requires Module:ProfessionList.
Module:BlacksmithSmeltingList requires Module:RecipeTreeSearch.
Module:BlacksmithSmeltingList 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:Blacksmith]] AND [[Category:Pages with recipes]]'
	
	local function screenFunction(item)
		return (item.facility=='Goblin Smelter' or item.facility=='Gnome Smelter')
	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
		
		if item.facility=='Goblin Smelter' then
			item.facilityDisplay = 'Goblin'
		else
			item.facilityDisplay = 'Gnome'
		end
		
		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:Blacksmith small icon.png|15px]]  Level')
			:done()
			:tag('th')
				:attr{ colspan = '2' }
				:wikitext('Product')
			:done()
			:tag('th')
				:attr{ colspan = '2' }
				:wikitext('Material')
			:done()
			:tag('th')
				:attr{ colspan = '2' }
				:wikitext('Smelter')
			: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))
			:node(plist.two_column_image_text(item.facility,'File:' .. item.facility .. '.png',item.facilityDisplay,item.facility))

			-- 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