-------------------------------------------------------------------------------
-- GAME STATE -----------------------------------------------------------------
-------------------------------------------------------------------------------

function HasGameState(state, value, tag)
    tag = tag or DEFAULT_TAG_NAME
	if IsLevelCollectorsEdition(GetCurrentLevel().name) then
	    tag = CE_TAG_NAME
	end
	
	local level           = GetCurrentLevel()
    local is_state_exists = level.state:HasState(state, tag)
    
	if value == nil then
		return is_state_exists
	else
		return is_state_exists and (not value or level.state:GetState(state, tag):HasValue(value))
	end
end
-------------------------------------------------------------------------------

function AddGameState(state, value, tag)
	tag = tag or DEFAULT_TAG_NAME
	if IsLevelCollectorsEdition(GetCurrentLevel().name) then
	    tag = CE_TAG_NAME
	end
    GetCurrentLevel().state:AddState(state, value, tag)
end
-------------------------------------------------------------------------------

function AddUniqueGameState(state, value, tag)
    if not HasGameState(state, value, tag) then
        AddGameState(state, value, tag)
    end
end
-------------------------------------------------------------------------------

function GetGameState(state, tag)
	tag = tag or DEFAULT_TAG_NAME
	if IsLevelCollectorsEdition(GetCurrentLevel().name) then
	    tag = CE_TAG_NAME
	end
    return GetCurrentLevel().state:GetState(state, tag)
end
-------------------------------------------------------------------------------

function SetGameState(state, value, tag)
	tag = tag or DEFAULT_TAG_NAME
	if IsLevelCollectorsEdition(GetCurrentLevel().name) then
	    tag = CE_TAG_NAME
	end
    GetCurrentLevel().state:SetState(state, value, tag)
end
-------------------------------------------------------------------------------

function RemoveGameState(state, value, tag)
    tag = tag or DEFAULT_TAG_NAME
	if IsLevelCollectorsEdition(GetCurrentLevel().name) then
	    tag = CE_TAG_NAME
	end
    if not value then
        GetCurrentLevel().state:RemoveState(state, tag)
    else
        GetCurrentLevel().state:RemoveStateValue(state, value, tag)
    end
end
-------------------------------------------------------------------------------

function HasActionCompletedState(actionName, levelName)
    levelName = levelName or GetCurrentLevel().name
    
    local value = levelName.."("..actionName..")"
    return HasGameState(ACTION_COMPLETED, value)
end
-------------------------------------------------------------------------------

function AddActionCompletedState(actionName, levelName)
    levelName = levelName or GetCurrentLevel().name
    
    local value = levelName.."("..actionName..")"
    AddUniqueGameState(ACTION_COMPLETED, value)
end
-------------------------------------------------------------------------------

function RemoveActionCompletedState(actionName, levelName)
    levelName = levelName or GetCurrentLevel().name
    
    local value = levelName.."("..actionName..")"
    RemoveGameState(ACTION_COMPLETED, value)
end
-------------------------------------------------------------------------------