3434# =============================================================================
3535# >> CLASSES
3636# =============================================================================
37- class _TempEntityHook (AutoUnload ):
38- """Create temp entity pre and post hooks that auto unload."""
37+ class TempEntityPreHook (AutoUnload ):
38+ """Decorator used to create temp entity pre hooks that auto unload."""
3939
4040 def __init__ (self , temp_entity_name ):
4141 """Initialize the hook object.
4242
4343 :param str temp_entity_name:
4444 The name of the temp entity to hook.
4545 """
46- # Store the given temp entity name...
47- self .name = temp_entity_name
48-
4946 # Get and store the temp entity template...
5047 self .template = temp_entity_templates [temp_entity_name ]
5148
@@ -58,31 +55,38 @@ def __call__(self, callback):
5855 self .callback = callback
5956
6057 # Initialize the hook...
61- self .template .add_hook (self . hook_type , callback )
58+ self .template .add_hook (callback )
6259
6360 # Return the callback...
6461 return callback
6562
66- @property
67- def hook_type (self ):
68- """Raise an error if the inheriting class does not have their own."""
69- raise NotImplementedError ('No hook_type defined for class.' )
70-
7163 def _unload_instance (self ):
7264 """Unload the hook."""
73- self .template .remove_hook (self .hook_type , self .callback )
65+ # Exit the call if the callback wasn't registered...
66+ if self .callback is None :
67+ return
7468
69+ # Unregister the hook...
70+ self .template .remove_hook (self .callback )
7571
76- class TempEntityPreHook (_TempEntityHook ):
77- """Decorator used to create temp entity pre hooks that auto unload."""
7872
79- hook_type = HookType .PRE
73+ class TempEntityPostHook (TempEntityPreHook ):
74+ """Decorator used to create temp entity post hooks that auto unload."""
8075
76+ def __init__ (self , temp_entity_name ):
77+ """Initialize the hook object.
8178
82- class TempEntityPostHook (_TempEntityHook ):
83- """Decorator used to create temp entity post hooks that auto unload."""
79+ :param str temp_entity_name:
80+ The name of the temp entity to hook.
81+ """
82+ from warnings import warn
83+ warn (
84+ 'TempEntityPostHook has been deprecated and will be entirely '
85+ 'unsupported in a future update. Use TempEntityPreHook instead '
86+ 'or register your own post hook on '
87+ 'CEngineServer::PlaybackTempEntity/CBaseTempEntity::Create.' )
8488
85- hook_type = HookType . POST
89+ super (). __init__ ( temp_entity_name )
8690
8791
8892# =============================================================================
@@ -92,12 +96,5 @@ class TempEntityPostHook(_TempEntityHook):
9296def pre_playback_temp_entity (stack_data ):
9397 """Handle pre hooks."""
9498 temp_entity = TempEntity (stack_data [3 ])
95- return temp_entity .template .handle_hook (HookType .PRE , temp_entity ,
96- make_object (RecipientFilter , stack_data [1 ]))
97-
98- @PostHook (get_virtual_function (engine_server , 'PlaybackTempEntity' ))
99- def post_playback_temp_entity (stack_data , return_value ):
100- """Handle post hooks."""
101- temp_entity = TempEntity (stack_data [3 ])
102- return temp_entity .template .handle_hook (HookType .POST , temp_entity ,
99+ return temp_entity .template .handle_hook (temp_entity ,
103100 make_object (RecipientFilter , stack_data [1 ]))
0 commit comments