Module:ItemSources: Difference between revisions

From Brighter Shores Wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
Line 39: Line 39:
for _, v in ipairs(sourcesmwdata) do
for _, v in ipairs(sourcesmwdata) do
local professionreq = v.professionreq or 'Unknown'
local professionreq = v.professionreq or 'Unknown'
local professonlevel = professionreq
if professionreq ~= 'Unknown' then
if professionreq ~= 'Unknown' then
local profession, level = v.professionreq:match("([^,]+),([^,]+)")
local profession, level = v.professionreq:match("([^,]+),([^,]+)")
mw.logObject(profession)
professionlevel = pcp(profession, level)
mw.logObject(level)
end
end


out:tag('tr')
out:tag('tr')
:tag('td'):wikitext(source.source):done()
:tag('td'):wikitext(source.source):done()
:tag('td'):wikitext():done()
:tag('td'):wikitext(professionlevel):done()
:tag('td'):wikitext(dropJSON['Dropped quantity']):done()
:tag('td'):wikitext(dropJSON['Dropped quantity']):done()
:tag('td'):wikitext(dropJSON['Frequency']):done()
:tag('td'):wikitext(dropJSON['Frequency']):done()
:done()
:done()
end
end
end
end

Revision as of 07:21, 2 December 2024

Module documentation
This documentation is transcluded from Module:ItemSources/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:ItemSources/doc. [edit]
Module:ItemSources's function main is invoked by Template:ItemSources.
Module:ItemSources requires Module:Param Parse.
Module:ItemSources requires Module:Profession clickpic.

local p = {}
local hc = require('Module:Param Parse').has_content
local pcp = require('Module:Profession clickpic')._main

function p.main(frame)
	local args = frame:getParent().args
	return p._main(args)
end

function p._main(args)
	local item = args[1] or mw.title.getCurrentTitle().fullText
	
	local q = {
		'[[Dropped item::' .. item .. ']]',
		'?Dropped from=source',
		'?Dropped quantity=quantity',
		'?Rarity=rarity',
		'?Drop JSON'
	}
	local sourcessmwdata = mw.smw.ask(q)
	
	local out = mw.html.create('table')
		:addClass('wikitable')
		:tag('tr')
			:tag('th'):wikitext('Source'):done()
			:tag('th'):wikitext('Level'):done()
			:tag('th'):wikitext('Quantity'):done()
			:tag('th'):wikitext('Frequency'):done()
		:done()
		
	for _, source in ipairs(sourcessmwdata) do
		local dropJSON = mw.text.jsonDecode(source['Drop JSON'] or '{}')
		
		local q2 = {
			'[[:' .. dropJSON['Dropped from'] .. ']]',
			'?Profession Requirement A=professionreq',
		}
		local sourcesmwdata = mw.smw.ask(q2)
		
		for _, v in ipairs(sourcesmwdata) do
			local professionreq = v.professionreq or 'Unknown'
			local professonlevel = professionreq
			if professionreq ~= 'Unknown' then
				local profession, level = v.professionreq:match("([^,]+),([^,]+)")
				professionlevel = pcp(profession, level)
			end

			out:tag('tr')
				:tag('td'):wikitext(source.source):done()
				:tag('td'):wikitext(professionlevel):done()
				:tag('td'):wikitext(dropJSON['Dropped quantity']):done()
				:tag('td'):wikitext(dropJSON['Frequency']):done()
			:done()
		end
		
	end
	
	return out
end

return p