FANDOM


-- <pre>
local p = {}
local JSONS = require('Dev:Json')
 
function p.main(frame)
	-- This template is fairly expensive to use, so it should be limited
	mw.incrementExpensiveFunctionCount()
 
	local args = frame:getParent().args
 
	local item = string.gsub(args['?item'] or args.item or '','[][]','')
	item = mw.text.decode(item)
 
	local material = string.lower(args.userparam or args.material or '')
	material = mw.text.decode(material)
 
	-- escape lua characters
	local _material = material:gsub('([%^%$%(%)%%%.%[%]%*%+%-%?])','%%%1')
 
	local smwdata = frame:preprocess('{{'..
					'{{{|safesubst:}}}#show:'..
					item..
				[[
					|?Production JSON
					|headers=plain
					|format=list
					}}
				]])
 
	smwdata = mw.text.decode(tostring(smwdata))
	local _found = false
 
	local json = smwdata
 
	local json_good
	json_good, json = pcall(JSONS.decode,string.format('[ %s ]',json))
 
	if not json_good then
		return ''
	end
 
	local ret = {}
 
	local maxi = 0
	for _, v in pairs(json) do
		for _, w in pairs(v.mats) do
			if material == string.lower(w.name) or material == '' then
				table.insert(ret,v)
				maxi = maxi + 1
				_found = true
				break
			end
		end
	end
 
	if not _found then
		return ''
	end
	local retrows = mw.html.create('filler')
 
	for i, v in pairs(ret) do
		local retrow = retrows:tag('tr')
		retrow	:tag('td')
				:wikitext(string.format('%s&nbsp;[[%s]]',v.image,v.product))
			:done()
			:tag('td')
				:wikitext(string.format('%s&nbsp;%s',v.level,v.skill))
			:done()
 
		local matrow = retrow:tag('td')
		local matlisttag = matrow:tag('ul')
						:css({ ['list-style-type'] = 'none',
							margin = '0' })
		for _, w in ipairs(v.mats) do
			local css = ''
			if string.lower(w.name) == material then
				css = 'production-selected'
			end
			matlisttag	:tag('li')
						:addClass(css)
						:wikitext(string.format('%s × [[%s]]',mw.ustring.gsub(w.quantity,'%-','–'),w.name))
					:done()
		end
 
		matlisttag:done()
		matrow:done()
		retrow:done()
	end
 
	retrows:done()
 
	retrows = tostring(retrows)
 
	retrows = mw.ustring.gsub(retrows,'</?filler>','')
 
	return retrows
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.