Module:Infobox/Widget/Role: Difference between revisions

From TwogPedia
No edit summary
No edit summary
Tag: Manual revert
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
local Role = {}
local Role = {}


function Role.make(rowName, role, game)
function Role.make(rowName, role, game, frame)
local container = mw.html.create('div')
local container = mw.html.create('div')
local array = mw.text.split(role, ',')
local array = mw.text.split(role, ',')
mw.log('array: ')
 
mw.log(array)
mw.logObject(array)
for i, v in ipairs(array) do
for i, v in ipairs(array) do
v = mw.text.trim(v)
local value = string.upper(mw.text.trim(v))
v = string.upper(v)
 
local valueNode = mw.html.create('div')
local valueNode = mw.html.create('div')
-- If no game then return value without link
-- If no game then return value without link
if game == nil then
if game == nil then
return container:node(valueNode:wikitext(v))
return container:node(valueNode:wikitext(value))
end
end
mw.log('ON VVVVVVVV')
 
mw.log(v)
local catName = ''
local catName = ''
local visibleName = ''
local visibleName = ''
-- General
-- General
if value == 'COACH' then
if value == 'COACH' then
mw.log('OLEN CATNAMEEEEEE')
catName = 'Coaches'
catName = 'Coaches'
visibleName = 'Coach'
visibleName = 'Coach'
Line 28: Line 25:
catName = 'Managers'
catName = 'Managers'
visibleName = 'Manager'
visibleName = 'Manager'
end
if value == 'TALENT' then
catName = 'Talents'
visibleName = 'Talent'
end
end
Line 69: Line 70:
-- CS:GO Values
-- CS:GO Values
if value == 'AWPER' then
if value == 'AWPER' or value == 'AWP' then
catName = 'AWPers'
catName = 'AWPers'
visibleName = 'Top'
visibleName = 'AWPer'
end
if value == 'LURKER' then
catName = 'Lurkers'
visibleName = 'Lurker'
end
end
-- if value == 'SUPPORT' then
-- catName = 'Support'
-- visibleName = 'Support'
-- end
if value == 'RIFLER' then
if value == 'RIFLER' then
catName = 'Riflers'
catName = 'Riflers'
visibleName = 'Rifler'
visibleName = 'Rifler'
end
if value == 'ENTRY' or value == 'ENTRY FRAGGER' then
catName = 'Entry_fraggers'
visibleName = 'Entry fragger'
end
end
if value == 'IGL' or value == 'IN-GAME LEADER' then
if value == 'IGL' or value == 'IN-GAME LEADER' then
Line 86: Line 91:
end
end
local categoryLink = '[[Category:' .. game .. '/' .. catName .. '|' .. visibleName ..']]'
local link = 'Category:' .. game .. '/' .. catName
valueNode:wikitext(categoryLink)
local pageExists = frame:callParserFunction('#ifexist', link, 'yes', 'no' )
container:node(valueNode)
if pageExists == 'no' then
container:node(valueNode:wikitext(visibleName))
else
local categoryLink = '[[:Category:' .. game .. '/' .. catName .. '|' .. visibleName ..']]'
valueNode:wikitext(categoryLink)
container:node(valueNode)
end
end
end
return container
return container
end
end

Latest revision as of 08:26, 2 September 2022

Documentation for this module may be created at Module:Infobox/Widget/Role/doc

local Role = {}

function Role.make(rowName, role, game, frame)
	local container = mw.html.create('div')
	local array = mw.text.split(role, ',')

	for i, v in ipairs(array) do
		local value = string.upper(mw.text.trim(v))

		local valueNode = mw.html.create('div')
		-- If no game then return value without link
		if game == nil then
			return container:node(valueNode:wikitext(value))
		end

		local catName = ''
		local visibleName = ''
		
		-- General
		if value == 'COACH' then
			catName = 'Coaches'
			visibleName = 'Coach'
		end
		if value == 'MANAGER' then
			catName = 'Managers'
			visibleName = 'Manager'
		end
		if value == 'TALENT' then
			catName = 'Talents'
			visibleName = 'Talent'
		end
		
		-- Dota 2
		if value == 'CARRY' then
			catName = 'Carry_players'
			visibleName = 'Carry'
		end
		if value == 'HARD SUPPORT' then
			catName = 'Hard_support_players'
			visibleName = 'Hard support'
		end
		if value == 'OFFLANE' then
			catName = 'Offlaners'
			visibleName = 'Offlane'
		end
		
		-- Dota and LoL overlap
		if value == 'SUPPORT' then
			catName = 'Support_players'
			visibleName = 'Support'
		end
		if value == 'MID' then
			catName = 'Mid_players'
			visibleName = 'Mid'
		end
		
		-- LoL
		if value == 'TOP' then
			catName = 'Top_players'
			visibleName = 'Top'
		end
		if value == 'BOT' then
			catName = 'Bot_players'
			visibleName = 'Bot'
		end
		if value == 'JUNGLE' then
			catName = 'Junglers'
			visibleName = 'Jungle'
		end
		
		-- CS:GO Values
		if value == 'AWPER' or value == 'AWP' then
			catName = 'AWPers'
			visibleName = 'AWPer'
		end
		if value == 'LURKER' then
			catName = 'Lurkers'
			visibleName = 'Lurker'
		end
		if value == 'RIFLER' then
			catName = 'Riflers'
			visibleName = 'Rifler'
		end
		if value == 'ENTRY' or value == 'ENTRY FRAGGER' then
			catName = 'Entry_fraggers'
			visibleName = 'Entry fragger'
		end
		if value == 'IGL' or value == 'IN-GAME LEADER' then
			catName = 'In-game_leaders'
			visibleName = 'In-game Leader'
		end
		
		local link = 'Category:' .. game .. '/' .. catName
		local pageExists = frame:callParserFunction('#ifexist', link, 'yes', 'no' )
			
		if pageExists == 'no' then
			container:node(valueNode:wikitext(visibleName))
		else
			local categoryLink = '[[:Category:' .. game .. '/' .. catName .. '|' .. visibleName ..']]'
			valueNode:wikitext(categoryLink)
			container:node(valueNode)
		end
	end
	return container
end


return Role