Module:Sandbox/User:Alsang: Difference between revisions

From Brighter Shores Wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
(84 intermediate revisions by the same user not shown)
Line 1: Line 1:
p = {}
require('Module:Mw.html extension')
local p = {}


p.query = '[[Category:Guardian Equipment]] AND [[Variant type::~*]] AND [[Category:Armorer]]|?#-=name|limit=500'
function sort_entries(entry1, entry2)
-- Sort the variants based on the sum of the profession levels
local entry1_value = (entry1['Profession Level A'] or 0) + (entry1['Profession Level B'] or 0)
local entry2_value = (entry2['Profession Level A'] or 0) + (entry2['Profession Level B'] or 0)
return entry1_value < entry2_value
end


function get_table_info(args, get_images)
function p.main()
local variant_name = args.variant or mw.title.getCurrentTitle().fullText
local query = {
'[[Variant of::'..variant_name..']]',
'?Profession A #', -- Adding a # to this query makes it return plaintext instead of a link
'?Profession B #',
'?Profession Level A',
'?Profession Level B',
'?Profession Level A High',
'?Profession Level B High',
'?Variant name',
get_images and '?Image#64px;x64px = Image' or nil,
limit = args.limit or 500,
}
local smw_data = mw.smw.ask(query)
if not smw_data then
return nil
end
table.sort(smw_data, sort_entries)
return smw_data
end


local results = mw.smw.ask(p.query)
function p.variants_header(args)
local smw_data = get_table_info(args)
local out = mw.html.create('table')
local contents
:addClass('wikitable sortable')
if smw_data then
for _,page in ipairs(results) do
local formatted = {}
out:tag('tr')
for _, entry in ipairs(smw_data) do
:tag('th')
local variant_name = entry['Variant name']
:wikitext('[[' .. page.name .. ']]')
if variant_name then
:done()
local page = entry[1]
local pipe = page:find('|')
:tag('td')
:wikitext('[[' .. page.name .. ' (basic)]]')
if pipe then
:done()
page = page:sub(3, pipe-1)
else
:tag('td')
page = page:sub(3, -3)
:wikitext('[[' .. page.name .. ' (moderate)]]')
end
:done()
:tag('td')

:wikitext('[[' .. page.name .. ' (fine)]]')
if page:sub(1, 1 + #variant_name + #' (grade ') == ':' .. variant_name .. ' (grade ' and page:sub(-1) == ')' then
:done()
local grade_number = page:sub(2 + #variant_name + #' (grade ', -2)
:tag('td')
mw.log('"' .. grade_number .. '"')
:wikitext('[[' .. page.name .. ' (strong)]]')
variant_name = 'Grade ' .. grade_number
end
:done()
:tag('td')

table.insert(formatted, ('[[%s|%s]]'):format(page, variant_name))
:wikitext('[[' .. page.name .. ' (superior)]]')
else
:done()
:tag('td')
table.insert(formatted, entry[1])
:wikitext('[[' .. page.name .. ' (perfect)]]')
end
:done()
end
:done()
contents = table.concat(formatted, '&nbsp;•&nbsp;')
else
contents = '[[Category:Empty variant list]]'
end
end
return mw.html.create('div')
return out
:addClass('variants-header')
:wikitext(contents)
:done()
end

function p.main(frame)
local args = frame:getParent().args
args.variant = args[1] or args.variant
return p.variants_header(args)
end
end


function p.variants_table(args)
function p.main2()
local smw_data = get_table_info(args, true)
if not smw_data then
return ':No variants found.'
end
local profession_b_flag = false
local results = mw.smw.ask(p.query)
for _, entry in ipairs(smw_data) do
if entry['Profession B'] or entry['Profession Level B'] then
profession_b_flag = true
end
break
end
local table = mw.html.create('table')
local out = mw.html.create('table')
:addClass('sortable wikitable')
:addClass('wikitable sortable')
for _,page in ipairs(results) do
:tag('tr')
out:tag('tr')
:tag('th')
:tag('th')
:attr{ colspan = '2' }
:attr{ rowspan = '2' }
:wikitext('Item')
:wikitext('[[' .. page.name .. ']]')
:done()
:done()
:tag('th')
:tag('td')
:wikitext('Level')
:wikitext('[[File:' .. page.name .. ' (basic).png]]')
:done()
:attrIf(profession_b_flag, 'colspan', 2)
:tag('td')
:wikitext('[[File:' .. page.name .. ' (moderate).png]]')
:done()
:tag('td')
:wikitext('[[File:' .. page.name .. ' (fine).png]]')
:done()
:tag('td')
:wikitext('[[File:' .. page.name .. ' (strong).png]]')
:done()
:tag('td')
:wikitext('[[File:' .. page.name .. ' (superior).png]]')
:done()
:tag('td')
:wikitext('[[File:' .. page.name .. ' (perfect).png]]')
:done()
:done()
:done()
:done()
:tag('tr')
:tag('td')
local function formatProfessionLevel(profession, level, high)
:wikitext('[[File:' .. page.name .. ' (basic) dye.png]]')
if not (profession or level) then
return nil
end
profession = profession or 'Unknown profession'
local level_text = tostring(level or '?')
if high then
level_text = ('%s➨%d'):format(level_text, high)
end
return ('%s [[File:%s small icon.png|21x21px|link=%s]]'):format(level_text, profession, profession)
end

for _, entry in ipairs(smw_data) do
local profession_level_a = entry['Profession Level A'] or '?'
local profession_level_b = entry['Profession Level B'] or '?'
local profession_a = entry['Profession A'] or ''
local profession_b = entry['Profession B'] or ''
table
:tag('tr')
:tag('td')
:css{ ['border-right'] = 'none' }
:wikitext(entry.Image)
:done()
:tag('td')
:css{ ['border-left'] = 'none' }
:wikitext(entry[1])
:done()
:tag('td')
:css{ ['text-align'] = 'right' }
:wikitext(formatProfessionLevel(entry['Profession A'], entry['Profession Level A'], entry['Profession Level A High']))
:IF(profession_b_flag)
:tag('td')
:IF(entry['Profession B'])
:css{ ['text-align'] = 'right' }
:wikitext(formatProfessionLevel(entry['Profession B'], entry['Profession Level B'], entry['Profession Level B High']))
:done()
:END()
:done()
:done()
:tag('td')
:wikitext('[[File:' .. page.name .. ' (moderate) dye.png]]')
:done()
:tag('td')
:wikitext('[[File:' .. page.name .. ' (fine) dye.png]]')
:done()
:tag('td')
:wikitext('[[File:' .. page.name .. ' (strong) dye.png]]')
:done()
:tag('td')
:wikitext('[[File:' .. page.name .. ' (superior) dye.png]]')
:done()
:tag('td')
:wikitext('[[File:' .. page.name .. ' (perfect) dye.png]]')
:done()
:done()
end
end

return table
return out
end
end


function p.main_table(frame)
local args = frame:getParent().args
args.variant = args[1] or args.variant
return p.variants_table(args)
end


return p
return p

Revision as of 20:30, 1 January 2025

Module documentation
This documentation is transcluded from Module:Sandbox/User:Alsang/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Sandbox/User:Alsang/doc. [edit]
Module:Sandbox/User:Alsang's function main is invoked by Template:Sandbox/User:Alsang.

p = {}

p.query = '[[Category:Guardian Equipment]] AND [[Variant type::~*]] AND [[Category:Armorer]]|?#-=name|limit=500'

function p.main()

	local results = mw.smw.ask(p.query)
	
	local out = mw.html.create('table')
		:addClass('wikitable sortable')
	for _,page in ipairs(results) do
		out:tag('tr')
			:tag('th')
				:wikitext('[[' .. page.name .. ']]')
			:done()
			:tag('td')
				:wikitext('[[' .. page.name .. ' (basic)]]')
			:done()
			:tag('td')
				:wikitext('[[' .. page.name .. ' (moderate)]]')
			:done()
			:tag('td')
				:wikitext('[[' .. page.name .. ' (fine)]]')
			:done()
			:tag('td')
				:wikitext('[[' .. page.name .. ' (strong)]]')
			:done()
			:tag('td')
				:wikitext('[[' .. page.name .. ' (superior)]]')
			:done()
			:tag('td')
				:wikitext('[[' .. page.name .. ' (perfect)]]')
			:done()
		:done()
	end
	
	return out
	
end

function p.main2()
	
	local results = mw.smw.ask(p.query)
	
	local out = mw.html.create('table')
		:addClass('wikitable sortable')
	for _,page in ipairs(results) do
		out:tag('tr')
			:tag('th')
				:attr{ rowspan = '2' }
				:wikitext('[[' .. page.name .. ']]')
			:done()
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (basic).png]]')
			:done()
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (moderate).png]]')
			:done()
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (fine).png]]')
			:done()
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (strong).png]]')
			:done()
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (superior).png]]')
			:done()
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (perfect).png]]')
			:done()
		:done()
		:tag('tr')
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (basic) dye.png]]')
			:done()
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (moderate) dye.png]]')
			:done()
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (fine) dye.png]]')
			:done()
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (strong) dye.png]]')
			:done()
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (superior) dye.png]]')
			:done()
			:tag('td')
				:wikitext('[[File:' .. page.name .. ' (perfect) dye.png]]')
			:done()
		:done()
	end
	
	return out
	
end


return p