--------------------------------------------------------------------------------
-- HIDDEN-OBJECT HELPERS -------------------------------------------------------
--------------------------------------------------------------------------------
TASK_IS_ACTIVE          = "TaskIsActive"
TASK_OBJECT_FOUND       = "TaskObjectFound"

function RegisterHOInteractives(...)
	local Interactives = { Functions = {} }
	local level = GetCurrentLevel()
	
	for i,Func in pairs({...}) do
		Interactives.Functions[Func] = true
	end
	
	Interactives.Using = function(...)
		local UsingInter   = {...}
		local Functions = table.copy(Interactives.Functions)
		
		for i,Func in ipairs(UsingInter) do
			Func(level, true)
			Functions[Func] = nil
		end
		
		for Func,v in pairs(Functions) do
			Func(level, false)
		end
	end
	
	return Interactives
end
--------------------------------------------------------------------------------

function GetTask(objectName)
	return current_scene:getPlayField():getHOLogic():getTaskByObjectName(objectName)
end
--------------------------------------------------------------------------------


function GetActiveTaskStateName(scene_name, task)
	return scene_name.."("..task:getName()..")"
end
--------------------------------------------------------------------------------

function IsActiveTask(scene_name, task)
	return HasGameState(TASK_IS_ACTIVE, GetActiveTaskStateName(scene_name, task))
end
--------------------------------------------------------------------------------

function SetActiveTaskState(scene_name, task)
	if not IsActiveTask(scene_name, task) then
		AddGameState(TASK_IS_ACTIVE, GetActiveTaskStateName(scene_name, task))
	end
end
--------------------------------------------------------------------------------

function RemoveActiveTaskState(scene_name, task)
	local value = GetActiveTaskStateName(scene_name, task)
	RemoveGameState(TASK_IS_ACTIVE, value)
end
--------------------------------------------------------------------------------

function RemoveActiveTaskStates(scene_name)
	local tasks = play_field:GetLevelScreen():GetTasks()
	
	for task in tasks do
		local value = GetActiveTaskStateName(task)
		RemoveGameState(TASK_IS_ACTIVE, value)
	end
end
--------------------------------------------------------------------------------

function GetTaskObjectFoundState(scene_name, objectName)
	return scene_name..'('..objectName..')'
end
--------------------------------------------------------------------------------

function IsTaskObjectFound(scene_name, objectName)
	return HasGameState(TASK_OBJECT_FOUND, GetTaskObjectFoundState(scene_name, objectName))    
end
--------------------------------------------------------------------------------

function SetTaskObjectFound(scene_name, objectName)
	local stateValue = GetTaskObjectFoundState(scene_name, objectName)
	
	if not HasGameState(TASK_OBJECT_FOUND, stateValue) then
		AddGameState(TASK_OBJECT_FOUND, stateValue)
	end
end
--------------------------------------------------------------------------------

function RemoveTaskObjectsFound(scene_name, object_name)
	local stateValue = GetTaskObjectFoundState(scene_name, object_name)
		
	if HasGameState(TASK_OBJECT_FOUND, stateValue) then
		RemoveGameState(TASK_OBJECT_FOUND, stateValue)
	end
end
--------------------------------------------------------------------------------



function SetTaskActionObject(objName, bAction)
	local level = current_scene:getPlayField()
	local panel = level:getPanel()
	
	if level:getHOLogic():isTaskObject(objName) and not IsTaskObjectFound(level:getName(), objName) then
		local task = GetTask(objName)
		
		task:setActionObject(objName, bAction)
		level:getHOLogic():getIndicator():updateCaptionColor(task)	
	end
end
--------------------------------------------------------------------------------

function DefineToolFindOrder(...)
	GetCurrentLevel():GetAdditionalLogic():DefineToolFindOrder(...)
end
--------------------------------------------------------------------------------

function RegisterTasks(keyPrefix, randomObjectsName, actionTasksObjectsName, ...)
	-- local level = GetCurrentLevel()
	
	-- assert(level:GetPanelLuaObject():GetMode() == EPanelMode.PM_HIDDENOBJECT)
	
	-- local logic = level:GetAdditionalLogic()
	-- logic:RegisterTasks(keyPrefix, randomObjectsName, actionTasksObjectsName, ...)
end

--------------------------------------------------------------------------------

function RegisterTaskHP(...)
	local level = GetCurrentLevel()
	local logic = level:GetAdditionalLogic()
	
	assert(logic)
	logic:RegisterTask(...)
end
--------------------------------------------------------------------------------

function RegisterTaskObjectsShadow(objectName, shadowName)
	if IsTaskObjectFound(objectName) then
		Object(shadowName):SetOpacity(0)
		return
	end
	
	local level = GetCurrentLevel()
	
	if not level.task_objects_shadows then
		level.task_objects_shadows = {}
	end
	level.task_objects_shadows[objectName] = shadowName
	
	play_field:IgnoreOnTestPoint(shadowName)
end
--------------------------------------------------------------------------------

function RegisterItemFoundAction(objName, action)
	assert(action)
	
	local level = GetCurrentLevel()
	level.item_found_actions[objName] = action
	
	if IsTaskObjectFound(objName) then
		local event   = {}
		event.objName = objName
		event.save    = true
		
		action(event)
	end
end
--------------------------------------------------------------------------------

function isDebugLocalization()
	if not isCheatMode() then
		return false
	end
	
	local activeProfile = ProfilesManager:getCurrentProfile()
	return bDebugLocalization or ( activeProfile and activeProfile.name == 'Test2' )
end
--------------------------------------------------------------------------------

function hasTaskObjectDropped(object_name, scene_name)
	assert(object_name)

	scene_name = scene_name or current_scene:getName()
	return HasGameState(TASK_OBJECT_DROPPED, scene_name..'_'..object_name)
end
--------------------------------------------------------------------------------