FANDOM


-- <pre>
local disdata = mw.loadData('Module:Disassemble/data')
local mats = mw.loadData('Module:Disassemble/mats')
local chances = mw.loadData('Module:Disassembly material calculator/data')
local hc = require('Module:Paramtest').has_content
 
local p = {}
 
function get_mat(m)
	local str = mw.text.trim(string.gsub(string.gsub(string.lower(m), ' parts?', ''), ' components?', ''))
 
	if mats[str] then
		return mats[str], true
	else
		return (m or ''), false
	end
end
 
 
function p.simple(frame)
	local args = frame:getParent().args
	local v = disdata[string.lower(args[1])]
	if v then
		v = v.cat
		if v then
			return v
		end
	end
	return '&#35;N/A'
end
 
 
function p.main(frame)
	local args = frame:getParent().args
	local skipAliasses = args.skip_aliasses or false
 
	local ret = mw.html.create('table')
				:addClass('wikitable')
				:addClass('sortable')
				:addClass('autosort=1,a')
				:css('text-align','right')
				:tag('tr')
					:tag('th')
						:wikitext('Category')
					:done()
					:tag('th')
						:wikitext('often')
					:done()
					:tag('th')
						:wikitext('sometimes')
					:done()
					:tag('th')
						:wikitext('rarely')
					:done()
					:tag('th')
						:wikitext('itemqty')
					:done()
					:tag('th')
						:wikitext('compqty')
					:done()
					:tag('th')
						:wikitext('x10')
					:done()
					:tag('th')
						:wikitext('Desc')
					:done()
				:done()
 
	for w, v in pairs(disdata) do
		local _rarely = v.rarely
		if #(v.rarely or '') > 30 then
			_rarely = '...'
		end
 
		if (not skipAliasses) or (v.isAlias == nil) or (not v.isAlias) then
			ret:tag('tr')
				:tag('td')
					:wikitext(w)
				:done()
				:tag('td')
					:wikitext(v.often)
				:done()
				:tag('td')
					:wikitext(v.sometimes)
				:done()
				:tag('td')
					:wikitext(_rarely)
				:done()
				:tag('td')
					:wikitext(v.itemqty or 1)
				:done()
				:tag('td')
					:wikitext(v.compqty)
				:done()
				:tag('td')
					:wikitext(tostring(v.x10 or false))
				:done()
				:tag('td')
					:wikitext(string.format('[[:Category:Disassemble category/%s|%s]]', v.cat, v.name))
				:done()
			:done()
		end
	end
 
	return ret
end
 
 
function p.get_info(frame)
	local a = frame:getParent().args
	local cat = a.cat
	local data = false
	local matchances = nil
	local ret = {}
 
 
	function get_chance(mat)
		if not matchances then
			return ''
		end
		local str = mw.text.trim(string.gsub(string.gsub(string.lower(mat), ' parts?', ''), ' components?', ''))
		if matchances[mat] then
			return string.format(' - %s%%', matchances[mat]*100)
		else
			return "''Unknown''"
		end
	end
 
 
 
	if disdata[cat] then
		-- passed in an internal category name, e.g. 'melee 8'
		data = disdata[cat]
	else
		-- attempt to see if its a grouped category name, e.g. 'melee armour'
		for i,v  in pairs(disdata) do
			if v.cat == cat then
				data = v
				break
			end
		end
	end
 
	if data.cat and chances[data.cat] then
		matchances = chances[data.cat]
	end
 
 
	if data then
		table.insert(ret, string.format('Items in the "%s" category break down into:', cat))
		if data.often then
			table.insert(ret, "\n* '''Often:'''")
			for i,v in ipairs(mw.text.split(data.often,'%s*,%s')) do
				table.insert(ret, string.format('\n** [[%s]]%s', get_mat(v), get_chance(v)))
			end	
		end
		if data.sometimes then
			table.insert(ret, "\n* '''Sometimes:'''")
			for i,v in ipairs(mw.text.split(data.sometimes,'%s*,%s')) do
				table.insert(ret, string.format('\n** [[%s]]%s', get_mat(v), get_chance(v)))
			end	
		end
		if data.rarely then
			table.insert(ret, "\n* '''Rarely:'''")
			for i,v in ipairs(mw.text.split(data.rarely,'%s*,%s')) do
				table.insert(ret, string.format('\n** [[%s]]%s', get_mat(v), get_chance(v)))
			end	
		end
	else
		return "''Invalid category name passed''"
	end
 
	return table.concat(ret)
end
 
 
p.calctable = function(frame)
	-- local args = frame:getParent().args
	local catdata = {} -- reveresed disdata
	local cat, often, sometimes, rarely, cqty, iqty
 
	for k,v in pairs(disdata) do
		cat = v.cat
		data = catdata[cat]
		if data then
			table.insert(data.alias, k)
			cqty = tonumber(v.compqty) or 1
			iqty = tonumber(v.itemqty) or 1
			data.cqty[cqty] = true
			data.iqty[iqty] = true
		else
			often, sometimes, rarely = nil, nil, nil
			if hc(v.often) then
				often = mw.text.split(v.often,'%s*,%s')
			end
			if hc(v.sometimes) then
				sometimes = mw.text.split(v.sometimes,'%s*,%s')
			end
			if hc(v.rarely) then
				rarely = mw.text.split(v.rarely,'%s*,%s')
			end
 
			cqty = tonumber(v.compqty) or 1
			iqty = tonumber(v.itemqty) or 1
 
			catdata[cat] = {
				name = v.name,
				often = often,
				sometimes = sometimes,
				rarely = rarely,
				cqty = {[cqty] = true},
				alias = {k},
				iqty = {[iqty] = true},
			}
 
		end
	end
 
	local t = mw.html.create('table')
	t	:addClass('wikitable smalllistmargin align-right-5 align-right-6 sortable autosort=1,a')
			:tag('tr')
				:tag('th')
					:wikitext('Category')
				:done()
				:tag('th')
					:wikitext('Often')
					:addClass('unsortable')
				:done()
				:tag('th')
					:wikitext('Sometimes')
					:addClass('unsortable')
				:done()
				:tag('th')
					:wikitext('Rarely')
					:addClass('unsortable')
				:done()
				:tag('th')
					:wikitext('Items')
					:addClass('unsortable')
				:done()
				:tag('th')
					:wikitext('Materials')
					:addClass('unsortable')
				:done()
				:tag('th')
					:wikitext('Alternative<br />names')
					:addClass('unsortable')
				:done()
			:done()
 
	tr = nil
	local str = ''
	local arr
	for k,v in pairs(catdata) do
		tr = t:tag('tr')
		tr	:tag('td')
				:wikitext(string.format('[[:Category:Disassemble category/%s|%s]]',k,v.name))
			:done()
 
		if v.often then
			str = '\n* ' .. table.concat(v.often, '\n* ', 1, math.min(#v.often, 6))
			if #v.often > 6 then
				str = str .. '\n* ... and more'
			end
			str = str .. '\n'
		else
			str = ''
		end
		tr	:tag('td')
				:wikitext(str)
			:done()
 
		if v.sometimes then
			str = '\n* ' .. table.concat(v.sometimes, '\n* ', 1, math.min(#v.sometimes, 6))
			if #v.sometimes > 6 then
				str = str .. '\n* ... and more'
			end
			str = str .. '\n'
		else
			str = ''
		end
		tr	:tag('td')
				:wikitext(str)
			:done()
 
		if v.rarely then
			str = '\n* ' .. table.concat(v.rarely, '\n* ', 1, math.min(#v.rarely, 6))
			if #v.rarely > 6 then
				str = str .. '\n* ... and more'
			end
			str = str .. '\n'
		else
			str = ''
		end
		tr	:tag('td')
				:wikitext(str)
			:done()
 
		arr = {}
		for l,b in pairs(v.iqty) do
			table.insert(arr, l)
		end
		table.sort(arr)
		tr	:tag('td')
				:wikitext(table.concat(arr, ', '))
			:done()
 
		arr = {}
		for l,b in pairs(v.cqty) do
			table.insert(arr, l)
		end
		table.sort(arr)
		tr	:tag('td')
				:wikitext(table.concat(arr, ', '))
			:done()
 
		if next(v.alias) then
			table.sort(v.alias)
			str = '\n* ' .. table.concat(v.alias, '\n* ') .. '\n'
		else
			str = ''
		end
		tr	:tag('td')
				:wikitext(str)
			:done()
	end
 
	return t
 
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.