Difference between revisions of "Module:Sandbox/Botanist/CharacterWeapons"

From Granblue Fantasy Wiki
Jump to navigation Jump to search
(Created page with "local p = {} function p.fetchCharacters(frame) local argList = { '%PAGE%', 'name', 'jpname', 'rarity', 'type', 'element', 'race', 'weapon', 'charid', 'id...")
 
Line 91: Line 91:
 
table.insert(result, '</tr>')
 
table.insert(result, '</tr>')
 
for link,character in pairs(characters) do
 
for link,character in pairs(characters) do
local chartier = chartiers[link]
 
 
 
table.insert(result, '<tr>')
 
table.insert(result, '<tr>')
  
printCell(chartier.id)
+
printCell(character.id)
printCell(chartier.charid)
+
printCell(character.charid)
printCell(chartier.weapon)
+
printCell(character.weapon)
printCell(chartier.jpname)
+
printCell(character.jpname)
  
 
table.insert(result, '<td>[['..character.link..']]</td>')
 
table.insert(result, '<td>[['..character.link..']]</td>')
  
printCell(chartier.name)
+
printCell(character.name)
printCell(chartier.rarity)
+
printCell(character.rarity)
printCell(chartier.element)
+
printCell(character.element)
printCell(chartier.type)
+
printCell(character.type)
printCell(chartier.race)
+
printCell(character.race)
  
 
table.insert(result, '</tr>')
 
table.insert(result, '</tr>')

Revision as of 06:50, 1 February 2017

Lua error at line 64: bad argument #1 to 'insert' (table expected, got nil).


local p = {}

function p.fetchCharacters(frame)
	local argList = {
		'%PAGE%',
		'name',
		'jpname',
		'rarity',
		'type',
		'element',
		'race',
		'weapon',
		'charid',
		'id'
	}
	local params = {
		category = 'Characters',
		include = '{Character}:' .. table.concat(argList, ':'),
		mode = 'userformat',
		secseparators = '====',
		multisecseparators = '===='
	}
	local data = frame:callParserFunction('#dpl:', params)
	argList[1] = 'link'
	return p.indexDPLTable(frame, argList, data)
end

function p.indexDPLTable(frame, argList, data)
	local pagenames = {}
	pagenames[frame:getTitle()] = true
	local pf = frame:getParent()
	while (pf ~= nil) and (pf ~= pf:getParent()) do
		pagenames[pf:getTitle()] = true
		pf = pf:getParent()
	end
	local result = {}
	local ix = 1
	for row in mw.text.gsplit(data, '====', true) do
		local found_value = false
		local args = {}
		local i = 0
		for arg in mw.text.gsplit(row, '\n|') do
			i = i+1
			if (arg ~= '') and (arg ~= nil) then
				local key = argList[i]
				args[key] = arg
				found_value = true
			end
		end
		ix = ix + 1
		args.ix = ix
		if found_value then
			if pagenames[args['name']] ~= nil then
				args['name'] = args['link']
			end
			table.insert(result, args)
		end
	end
	return result
end

function printCell(contents)
		if contents ~= nil then
			table.insert(result, '<td>'..contents..'</td>')
		else
			table.insert(result, '<td style="background-color: red;">???</td>')
		end
end

function p.makeCharacterReport(frame)
	local temp = p.fetchCharacters(frame)
	-- index by link
	local characters = {}
	for key,value in pairs(temp) do
		characters[value.link] = value
	end

	local result = {}
	table.insert(result, '<table class="wikitable sortable jquery-tablesorter">')
	table.insert(result, '<tr>')
	table.insert(result, '<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">id</th>')
	table.insert(result, '<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">cid</th>')
	table.insert(result, '<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">wpns</th>')
	table.insert(result, '<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">jpname</th>')
	table.insert(result, '<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">link</th>')
	table.insert(result, '<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">name</th>')
	table.insert(result, '<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">r</th>')
	table.insert(result, '<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">el</th>')
	table.insert(result, '<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">ty</th>')
	table.insert(result, '<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">ra</th>')
	table.insert(result, '</tr>')
	for link,character in pairs(characters) do
		table.insert(result, '<tr>')

		printCell(character.id)
		printCell(character.charid)
		printCell(character.weapon)
		printCell(character.jpname)

		table.insert(result, '<td>[['..character.link..']]</td>')

		printCell(character.name)
		printCell(character.rarity)
		printCell(character.element)
		printCell(character.type)
		printCell(character.race)

		table.insert(result, '</tr>')
	end
	table.insert(result, '</table>')

	return table.concat(result, '\n')
end

return p