Modül:Futbol takımı kadrosu

Modül belgelemesi[oluştur]
local p = {}

function p.kadro(frame)
    local Args = frame.args
    local ii_start = tonumber(Args['highest_pos']) or 1
    local N_players = ii_start - 1
    local t = {}
    local player_list = {}
    
    -- Read team details
    local team_name = Args['team_name'] or Args['ad']
    local back_color = Args['back_color'] or Args['zeminrengi']
    local text_color = Args['text_color'] or Args['metinrengi']
    local side_color = Args['side_color'] or Args['kenarrengi']
    local temp_name = Args['temp_name'] or Args['takımadı']
    local coach_name = Args['coach_name'] or Args['td']
    local update = Args['update'] or Args['güncelleme']
    local typetemp = tonumber(Args['type']) or tonumber(Args['tip']) or 0


--if Args['player_order'] and Args['player_order'] ~= '' then
--		local tlist = mw.text.split(Args['player_order'], '%s*[;,]%s*')
	--	for k, tplayer in ipairs(tlist) do
	--		if tplayer ~= '' then
	--			Args['player' .. k] = tplayer
	--		end
	--	end
--end

     for i = 0, 120 do  -- Assuming 99 as a large enough limit for players
        local name_key = 'name_' .. i
        if Args[name_key] then
            N_players = N_players + 1
            player_list[N_players] = {
                number = Args['number_' .. i] or Args['no_'..i] or  i,
                name = Args[name_key],
                lname = Args['lname_' .. i] or Args['soyad_'..i] or i,
                country = Args['country_' .. i] or Args['nat_'..i] or Args['ülke_'..i] or i,
                position = Args['position_' .. i] or Args['pos_'..i] or i
            }
       
        end
    end

	local function get_lastname(name)
		local names = {}
		local final_name

		if name:find("%(") then

    	local position = name:find("%(")
    	local before_parenthesis = name:sub(1, position - 1):match("^%s*(.-)%s*$")
    

    	local sub_names = {}
    	for sub_name in before_parenthesis:gmatch("%S+") do
        table.insert(sub_names, sub_name)
    	end
    

		final_name = sub_names[#sub_names ] or sub_names[1]
		else

    	for name2 in name:gmatch("%S+") do
        table.insert(names, name2)
		 end
    	final_name = names[#names]
	end
	final_name=final_name:gsub("%[%[", ""):gsub("%]%]","")
	return (final_name)

end
	
	local function get_player_name(name)
	local pipe_position = name:find("|")
	local final_name

	if pipe_position then
    final_name = name:sub(1, pipe_position - 1)
	else
    final_name = name
	end

	final_name = final_name:gsub("%[%[", ""):gsub("%]%]", "")

	return(final_name)

		end

    local function insert_player(player)
       
        return '{{Futbol takımı kadrosu-oyuncu|no=' .. player.number .. '|pos=' .. player.position .. '|nat=' .. player.country .. '|name=' .. player.name .. '}}\n'
    end

    if typetemp == 0 or typetemp == 2 then
        table.insert(t, '{{Futbol takımı kadrosu|takımadı=' .. team_name .. '|zeminrengi=' .. back_color .. '|metinrengi=' .. text_color .. '|kenarrengi=' .. side_color .. '|ad=' .. temp_name .. '\n|liste=\n')

       for _, player in ipairs(player_list) do
            table.insert(t, '{{Futbol takımı kadrosu2-oyuncu|no=' .. player.number .. '|name=[[' ..get_player_name(player.name)..'|'.. get_lastname( player.name) .. ']]}}\n')
        end

        table.insert(t, '{{Futbol takımı kadrosu2-teknik direktör|name=' .. coach_name .. '}}\n')
        table.insert(t, '</div>}}\n')
    end

    if typetemp == 1 or typetemp == 2 then
    	table.insert(t,'{{güncellendi|' .. update .. '}}\n')
        table.insert(t, '{{Futbol takımı kadrosu-başlangıç}}\n')

        for ii = ii_start,math.ceil( N_players / 2 ) do
            table.insert(t, insert_player(player_list[ii]))
        end

        table.insert(t, '{{Futbol takımı kadrosu-orta}}\n')

        for ii = math.ceil( N_players / 2 ) + 1, N_players do
            table.insert(t, insert_player(player_list[ii]))
        end

        table.insert(t, '{{Futbol takımı kadrosu-son}}\n')
    end

    return mw.text.trim(frame:preprocess(table.concat(t)))
end

return p