class 'DragObjectManager'

function DragObjectManager:__init(playfield)
	assert(playfield)

	self.playfield	= playfield
	self.objects	= {}
end
-------------------------------------------------------------------------------

function DragObjectManager:add(dragObject)
	if not self:has(dragObject) then
		table.insert(self.objects, dragObject)
	end
end
-------------------------------------------------------------------------------

function DragObjectManager:has(dragObject)
	local name = dragObject:getDraggedEntity():getName()

	for i, theDragobject in ipairs(self.objects) do
		if theDragobject:getDraggedEntity():getName() == name then
			return true
		end
	end

	return false
end
-------------------------------------------------------------------------------

function DragObjectManager:get(draggedEntityName)
	local predicate = function(dragObject)
		return dragObject:getDraggedEntity():getName() == draggedEntityName
	end

	return self:find( predicate )
end
-------------------------------------------------------------------------------

function DragObjectManager:dropAll(bCheckTarget, bDropInstant)
	for i, dragObject in ipairs(self.objects) do
		dragObject:drop(bCheckTarget, bDropInstant)
	end
end
-------------------------------------------------------------------------------

function DragObjectManager:find(predicate)
	assert(predicate)

	for i, object in ipairs(self.objects) do
		if predicate( object ) then
			return object
		end
	end

	return nil
end
-------------------------------------------------------------------------------

function DragObjectManager:isDragging()
	local predicate = function(dragObject)
		return dragObject:isDragging()
	end

	local dragObject = self:find( predicate )
	return (dragObject ~= nil)
end
-------------------------------------------------------------------------------
