--[[ Revisit, not needed atm
function map:CreateFatGrid()
	
	map.fatgrid = {}
	for x = 0, map.sizeX - 1, map.fatgridSize do
		for y = 0, map.sizeY - 1, map.fatgridSize do
			
			local node = {}
			node.x = x
			node.y = y
			node.nodes = {}
			map.fatgrid[Vector3.new(x/map.fatgridSize, y/map.fatgridSize)] = node
			
		end
	end
	
	
	for counter 
			--find all the edge cells that have connections (north soth east west)
			--top edge
			
			local tempList = {}
			for xx = 0, map.fatgridSize-1 do
				
				local coord = map:GetPoint( Vector3.new(x+xx, y + 0))
				local otherCoord = map:GetPoint( Vector3.new(x+xx, y + 0 - 1) )
				
				
				if (coord and otherCoord and coord.cost < map.impassible and otherCoord.cost < map.impassible) then
					--We have a link
					tempList[xx] = { coord, otherCoord }		
					--debugBall(coord,Color3.new(1,0,0))
					--debugBall(otherCoord, Color3.new(1,1,0))
				end
				
			end

			--Create a new list of connections with only 1 neighbor
			local newList = {}
			for xx = 0, map.fatgridSize-1 do
				if (tempList[xx] ~= nil and (tempList[xx-1] ==nil or tempList[xx+1] == nil)) then
					table.insert(newList, tempList[xx])
				end
				
			end
			
			local tileCol = Color3.fromHSV(math.random(),1,1)
			for key,tab in pairs(newList) do
				debugBall(tab[1], tileCol)
				debugBall(tab[2], Color3.new(1,1,0))
			end
			
	 
		end
	end
	
end
]]
--

map:GenerateDummy()
map:CreateVisuals()


 



local server = {}
server.playerRecords = {}

function server:OnPlayerConnected(player)

	local playerRecord = {}
	playerRecord.userId = player.UserId
	playerRecord.name = player.Name
	playerRecord.displayName = player.DisplayName
	playerRecord.player = player
	
	self.playerRecords[player.UserId] = playerRecord
	
	nerds:PlayerConnected(playerRecord)
	
end

function server:GetPlayers()
	return self.playerRecords
end

function server:OnPlayerDisconnected(player)

	self.playerRecords[player.UserId] = nil
end


function server:Setup()
	
	nerds:Setup()

	
	game.Players.PlayerAdded:Connect(function(player)
		self:OnPlayerConnected(player)
	end)
	game.Players.PlayerRemoving:Connect(function(player)
		self:OnPlayerDisconnected(player)
	end)
	for key,player in pairs(game.Players:GetPlayers()) do
		self:OnPlayerConnected(player)
	end
	
	wait(10)
	nerds:SetMap(map)
	nerds:CreateNerds(1000, server)
end

server:Setup()

