34
34
# =============================================================================
35
35
# >> CLASSES
36
36
# =============================================================================
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."""
39
39
40
40
def __init__ (self , temp_entity_name ):
41
41
"""Initialize the hook object.
42
42
43
43
:param str temp_entity_name:
44
44
The name of the temp entity to hook.
45
45
"""
46
- # Store the given temp entity name...
47
- self .name = temp_entity_name
48
-
49
46
# Get and store the temp entity template...
50
47
self .template = temp_entity_templates [temp_entity_name ]
51
48
@@ -58,31 +55,38 @@ def __call__(self, callback):
58
55
self .callback = callback
59
56
60
57
# Initialize the hook...
61
- self .template .add_hook (self . hook_type , callback )
58
+ self .template .add_hook (callback )
62
59
63
60
# Return the callback...
64
61
return callback
65
62
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
-
71
63
def _unload_instance (self ):
72
64
"""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
74
68
69
+ # Unregister the hook...
70
+ self .template .remove_hook (self .callback )
75
71
76
- class TempEntityPreHook (_TempEntityHook ):
77
- """Decorator used to create temp entity pre hooks that auto unload."""
78
72
79
- hook_type = HookType .PRE
73
+ class TempEntityPostHook (TempEntityPreHook ):
74
+ """Decorator used to create temp entity post hooks that auto unload."""
80
75
76
+ def __init__ (self , temp_entity_name ):
77
+ """Initialize the hook object.
81
78
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.' )
84
88
85
- hook_type = HookType . POST
89
+ super (). __init__ ( temp_entity_name )
86
90
87
91
88
92
# =============================================================================
@@ -92,12 +96,5 @@ class TempEntityPostHook(_TempEntityHook):
92
96
def pre_playback_temp_entity (stack_data ):
93
97
"""Handle pre hooks."""
94
98
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 ,
103
100
make_object (RecipientFilter , stack_data [1 ]))
0 commit comments