-- Clone map upon game start. This is what will be loaded and unloaded
-- Destroy original after cloning

map = mapContainer:FindFirstChild(MAP_NAME)
local cachedMap = map:Clone()

function MapManager.loadMap()
	if map then
		print("Current map must be unloaded before loading a new map. Returning current map.")
		return map
	end
	
	map = cachedMap:Clone()
	map.Parent = mapContainer -- Parent it to the map container
	map.Name = MAP_NAME -- Rename the map so that we can use the unloadMap() function later to remove it.
	return map -- Return the map we selected, in case we want to display its info.
end

function MapManager.unloadMap()
	if map then
		map:Destroy()
		map = false -- Easier to handle than nil
	end 
end

function MapManager.reloadMap()
	if map then
		print("Removing current map before reloading")
		map:Destroy()
	end
	
	map = cachedMap:Clone()
	map.Parent = mapContainer -- Parent it to the map container
	map.Name = MAP_NAME -- Rename the map so that we can use the unloadMap() function later to remove it.
	return map -- Return the map we selected, in case we want to display its info.
end

function MapManager.getMap()
	return map
end

function MapManager.getSpawnLocations()
	if map then
		return map:FindFirstChild("SpawnLocations")
	end
	
	return false
end

return MapManager
