Module:Gamemodes

local p = {}

function p.table(frame) local mode_data = mw.loadData('Module:Gamemodes/data') local role_data = mw.loadData('Module:Roles/data') local mode_name = frame.args[1] if not mode_name or not mode_data.modes[mode_name] then mw.addWarning("Error: #invoke:gamemodes|table: Invalid mode name") return "" end local mode = mode_data.modes[mode_name] local main_roles = {} local secondary_roles = {} for _, role in ipairs(mode['secondary roles']) do		secondary_roles[role] = true end for role, _ in pairs(mode['role guide'][mode.min]) do		if not secondary_roles[role] and not mode['role sets'][role] then main_roles[role] = true end end local t = '{| class="wikitable gamemode-table"\n! ' ..		frame:expandTemplate{ title = 'diagonal split header', args = { 'Role', 'Players' } }

for i = mode.min, mode.max do t = t .. ' !! ' .. i	end -- do main roles first (in team order) for _, role in ipairs(role_data.order) do		if main_roles[role] then local team = role_data.roles[role][1] -- are they a team switcher? local switcher = false for _, cat in ipairs(role_data.roles[role]) do				if cat == "Team Switcher" then switcher = true end end -- hidden role? local hidden = false if team == "Hidden" then hidden = true if mode['default role'] == "villager" then team = "Village" else team = "Wolfteam" end end -- generate one of, , or 			local tpl_args = { role } if switcher then tpl_args.switcher = '1' end if hidden then tpl_args.hidden = '1' end t = t .. '\n|-\n! ' .. frame:expandTemplate{ title = team, args = tpl_args } for i = mode.min, mode.max do				local num = mode['role guide'][i][role] local x = num if num == 0 then x = '-' end if i == mode.min then t = t .. '\n| ' .. x				else t = t .. ' || ' .. x				end end end end -- now do secondary roles (in alphabetical order) for role, _ in pairs(role_data.roles) do		if secondary_roles[role] then t = t .. '\n|-\n! ' .. frame:expandTemplate{ title = 'Secondary', args = { role } } for i = mode.min, mode.max do				local num = mode['role guide'][i][role] local x = num if num == 0 then x = '-' end if i == mode.min then t = t .. '\n| ' .. x				else t = t .. ' || ' .. x				end end end end -- finally do role sets (in alphabetical order) for role, _ in pairs(mode['role sets']) do t = t .. '\n|-\n! ' .. frame:expandTemplate{ title = 'Role set', args = { role } } for i = mode.min, mode.max do			local num = mode['role guide'][i][role] local x = num if num == 0 then x = '-' end if i == mode.min then t = t .. '\n| ' .. x			else t = t .. ' || ' .. x			end end end t = t .. '\n|}' return t end

return p