Module:TalentTable: Difference between revisions

From TwogPedia
mNo edit summary
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local makeFlag = require('Module:Person/Flag').makeFlag
local makeFlag = require('Module:Person/Flag').makeFlag
Line 9: Line 8:
function p.main(frame)
function p.main(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local currentTitle = mw.title.getCurrentTitle().text
local currentTitle = mw.title.getCurrentTitle().text
local gameCategory = mw.text.split(currentTitle, '/')[1]
local gameCategory = mw.text.split(currentTitle, '/')[1]
local fullString = ''
local fullString = ''
-- Cycle through different tabs
 
for key, value in ipairs (args) do
for _, value in ipairs(args) do
local tab = mw.text.jsonDecode(value)
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')
local container = mw.html.create('div')
 
if tab.topNote then container:wikitext(tab.topNote) end
if tab.topNote then container:wikitext(tab.topNote) end
 
container:node(tabCell)
local lists = {}
local listCol = 1
local listCol = 1
local section = 1
local section = 1
local firstSection = true
local firstSection = true
local sections = {}
local sections = {}
sections[section] = {val = '', lists = {} }
sections[section] = {val = '', lists = {}}
sections[section].lists[listCol] = ''
sections[section].lists[listCol] = ''
 
for tabKey, tabValue in ipairs (tab) do
for _, tabValue in ipairs(tab) do
local role = mw.text.jsonDecode(tabValue)
local role = mw.text.jsonDecode(tabValue)
 
if role.section then
if role.section then
if firstSection then firstSection = false else  
if firstSection then  
section = section + 1  
firstSection = false  
else
section = section + 1
sections[section] = {val = '', lists = {}}
sections[section] = {val = '', lists = {}}
listCol = 1
listCol = 1
Line 51: Line 39:
sections[section].title = mw.html.create('div'):wikitext(role.section)
sections[section].title = mw.html.create('div'):wikitext(role.section)
end
end
if role.div then  
 
listCol = listCol + 1  
if role.div then
sections[section].lists[listCol] = ''
listCol = listCol + 1
end
sections[section].lists[listCol] = ''
end
local roleTitle = mw.html.create('div'):addClass('tc'):wikitext(role[1])
 
local roleList = mw.html.create('ul')
-- local roleTitle = mw.html.create('div'):addClass('tc'):wikitext(role[1])
local roleCell = mw.html.create('div'):addClass('talent__role'):node(roleTitle):node(roleList)
-- local roleList = mw.html.create('ul')
-- local roleCell = mw.html.create('div'):addClass('talent__role'):node(roleTitle):node(roleList)
local i = 1
local roleIcons = {
local people = ''
    ["Hosts"] = "Tourrnament-players-icon.png",
-- Loop through all the talent
    ["Commentators"] = "Tournament-commentators-icon.png",
if role['t1'] then
    ["Observers"] = "Tournament-observers-icon.png",
while role['t' .. i] do
    ["Mandarin Interpreters"] = "Tournament-observers-icon.png",
    ["Production"] = "Tournament-production-icon.png",
local link = role['t' .. i .. 'link'] or 'People/' .. role['t' .. i]
    ["Statistician"] = "Tournament-statistician-icon.png",
                        people = people .. link .. ','
    ["Coaches"] = "Tournament-coaches-icon.png"
local flag = makeFlag(role['t'.. i .. 'flag'], role['t'.. i .. 'link'] or 'People/' .. role['t'.. i], gameCategory)
}
local talentCell = mw.html.create('li'):wikitext(flag):wikitext('[[' .. link ..'|' .. role['t' .. i] .. ']]')
roleList:node(talentCell)
local iconFile = roleIcons[role[1]] or "Tournament-production-icon.png"
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)
local roleTitle = mw.html.create('div')
    :addClass('tc')
    :wikitext('[[File:' .. iconFile .. '|20px]]' .. 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 = ''
if role['t1'] then
while role['t' .. i] do
people = people .. 'People/' .. role['t' .. i] .. ','
local link = 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)
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
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Talent', people = people, role = role[1]}}
sections[section].lists[listCol] = tostring(sections[section].lists[listCol]) .. tostring(roleCell)
end
end


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


return p
return p

Latest revision as of 01:07, 26 April 2025

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 = ''

	for _, value in ipairs(args) do
		local tab = mw.text.jsonDecode(value)
		local container = mw.html.create('div')

		if tab.topNote then container:wikitext(tab.topNote) end

		local listCol = 1
		local section = 1
		local firstSection = true
		local sections = {}
		sections[section] = {val = '', lists = {}}
		sections[section].lists[listCol] = ''

		for _, 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 roleIcons = {
			    ["Hosts"] = "Tourrnament-players-icon.png",
			    ["Commentators"] = "Tournament-commentators-icon.png",
			    ["Observers"] = "Tournament-observers-icon.png",
			    ["Mandarin Interpreters"] = "Tournament-observers-icon.png",
			    ["Production"] = "Tournament-production-icon.png",
			    ["Statistician"] = "Tournament-statistician-icon.png",
			    ["Coaches"] = "Tournament-coaches-icon.png"
			}
			
			local iconFile = roleIcons[role[1]] or "Tournament-production-icon.png"
			
			local roleTitle = mw.html.create('div')
			    :addClass('tc')
			    :wikitext('[[File:' .. iconFile .. '|20px]]' .. 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 = ''

			if role['t1'] then
				while role['t' .. i] do
					people = people .. 'People/' .. role['t' .. i] .. ','
					local link = 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)
					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

			frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Talent', people = people, role = role[1]}}
			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 _, 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

	return mw.html.create():wikitext(frame:preprocess(fullString))
end

return p