Module:TalentTable: Difference between revisions

From TwogPedia
mNo edit summary
mNo edit summary
 
(3 intermediate revisions by the same user not shown)
Line 46: Line 46:
section = section + 1  
section = section + 1  
sections[section] = {val = '', lists = {}}
sections[section] = {val = '', lists = {}}
-- listCol = listCol + 1
listCol = 1
listCol = 1
sections[section].lists[listCol] = ''
sections[section].lists[listCol] = ''
end
end
sections[section].title = mw.html.create('div'):wikitext(role.section)
sections[section].title = mw.html.create('div'):wikitext(role.section)
else
end
if role.div then  
if role.div then  
listCol = listCol + 1  
listCol = listCol + 1  
Line 67: Line 66:
if role['t1'] then  
if role['t1'] then  
while role['t' .. i] do
while role['t' .. i] do
people = people .. 'People/' .. role['t' .. i] .. ','
local link = role['t' .. i .. 'link'] or 'People/' .. role['t' .. i]
local link = role['t' .. i .. 'link'] and 'People/' .. role['t' .. i .. 'link'] or 'People/' .. role['t' .. i]
local flag = makeFlag(role['t'.. i .. 'flag'], role['t'.. i .. 'link'] or 'People/' .. role['t'.. i], gameCategory)
                        people = people .. link .. ','
local flag = makeFlag(role['t'.. i .. 'flag'], link, gameCategory)
local talentCell = mw.html.create('li'):wikitext(flag):wikitext('[[' .. link ..'|' .. role['t' .. i] .. ']]')
local talentCell = mw.html.create('li'):wikitext(flag):wikitext('[[' .. link ..'|' .. role['t' .. i] .. ']]')
roleList:node(talentCell)
roleList:node(talentCell)
Line 84: Line 84:
sections[section].lists[listCol] = tostring(sections[section].lists[listCol]) .. tostring(roleCell)
sections[section].lists[listCol] = tostring(sections[section].lists[listCol]) .. tostring(roleCell)
end
end
end
 
for i = 1, #sections do
for i = 1, #sections do
local wrapper = mw.html.create('div')
local wrapper = mw.html.create('div')

Latest revision as of 15:10, 14 February 2024

Documentation for this module may be created at Module:TalentTable/doc

local cargo = mw.ext.cargo

local getArgs = require('Module:Arguments').getArgs
local makeFlag = require('Module:Person/Flag').makeFlag
local Links = require('Module:Links')

local p = {}

function p.main(frame)
	local args = getArgs(frame)

	local currentTitle = mw.title.getCurrentTitle().text
	local gameCategory = mw.text.split(currentTitle, '/')[1]
	
	local fullString = ''
	-- Cycle through different tabs
	for key, value in ipairs (args) do
		local tab = mw.text.jsonDecode(value)
		if key == 1 then
			fullString = '<tabber>|-|' .. tab.lang .. '=' 
		else
			fullString = fullString .. '|-|' .. tab.lang .. '='
		end
	
		local tabCell = mw.html.create('div')
		
		local container = mw.html.create('div')
		
		if tab.topNote then container:wikitext(tab.topNote) end
		
		container:node(tabCell)
		
		local lists = {}
		local listCol = 1
		local section = 1
		local firstSection = true
		local sections = {}
		sections[section] = {val = '', lists = {} }
		sections[section].lists[listCol] = ''
		
		for tabKey, tabValue in ipairs (tab) do
			local role = mw.text.jsonDecode(tabValue)
			
			if role.section then
				if firstSection then firstSection = false else 
					section = section + 1 
					sections[section] = {val = '', lists = {}}
					listCol = 1
					sections[section].lists[listCol] = ''
				end
				sections[section].title = mw.html.create('div'):wikitext(role.section)
			end
				if role.div then 
					listCol = listCol + 1 
					sections[section].lists[listCol] = ''
				end
				
				local roleTitle = mw.html.create('div'):addClass('tc'):wikitext(role[1])
				local roleList = mw.html.create('ul')
				local roleCell = mw.html.create('div'):addClass('talent__role'):node(roleTitle):node(roleList)
				
				local i = 1
				
				local people = ''
				-- Loop through all the talent
				if role['t1'] then 
					while role['t' .. i] do
						
						local link = role['t' .. i .. 'link'] and 'People/' .. role['t' .. i .. 'link'] or 'People/' .. role['t' .. i]
                        people = people .. link .. ','
						local flag = makeFlag(role['t'.. i .. 'flag'], link, gameCategory)
						local talentCell = mw.html.create('li'):wikitext(flag):wikitext('[[' .. link ..'|' .. role['t' .. i] .. ']]')
						roleList:node(talentCell)
						i = i + 1
					end
				else 
					roleList:node(mw.html.create('li'):wikitext('TBD'))	
				end
				
				
				
				-- Save talent to cargo
				frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Talent', people = people, role = role[1], lang = tab.lang}}
			
				sections[section].lists[listCol] = tostring(sections[section].lists[listCol]) .. tostring(roleCell)
			
		end

		for i = 1, #sections do
			local wrapper = mw.html.create('div')
			local title = mw.html.create('div'):addClass('talent__stage'):node(sections[i].title)
			local cell = mw.html.create('div'):addClass('talent__container')
			
			for j, subtable in ipairs(sections[i].lists) do
			     cell:node(mw.html.create('div'):node(subtable))
			end
			
			container:node(wrapper:node(title):node(cell))
		end
		
		if tab.botNote then container:wikitext(tab.botNote) end
		
		fullString = fullString .. tostring(container)
	end
	fullString = fullString .. '</tabber>'
	return mw.html.create():wikitext(frame:preprocess(fullString))
end

return p