|
39 | 39 | from engines.trace import Ray |
40 | 40 | from engines.trace import TraceFilterSimple |
41 | 41 | # Entities |
42 | | -from _entities._entity import BaseEntity |
43 | 42 | from entities import BaseEntityGenerator |
| 43 | +from entities import Edict |
44 | 44 | from entities import TakeDamageInfo |
45 | 45 | from entities.classes import server_classes |
46 | 46 | from entities.constants import DamageTypes |
|
59 | 59 | # Mathlib |
60 | 60 | from mathlib import NULL_VECTOR |
61 | 61 | # Memory |
| 62 | +from memory import get_object_pointer |
62 | 63 | from memory import make_object |
63 | 64 | from memory.helpers import MemberFunction |
64 | 65 | # Players |
|
68 | 69 | from studio.constants import INVALID_ATTACHMENT_INDEX |
69 | 70 |
|
70 | 71 |
|
| 72 | +# ============================================================================= |
| 73 | +# >> FORWARD IMPORTS |
| 74 | +# ============================================================================= |
| 75 | +# Source.Python Imports |
| 76 | +# Entities |
| 77 | +from _entities._entity import BaseEntity |
| 78 | + |
| 79 | + |
71 | 80 | # ============================================================================= |
72 | 81 | # >> GLOBAL VARIABLES |
73 | 82 | # ============================================================================= |
@@ -529,7 +538,7 @@ def get_property_edict(self, name): |
529 | 538 | Name of the property to retrieve. |
530 | 539 | :rtype: Edict |
531 | 540 | """ |
532 | | - return self._get_property(name, 'Edict') |
| 541 | + return make_object(Edict, self.get_property_pointer(name)) |
533 | 542 |
|
534 | 543 | def get_property_float(self, name): |
535 | 544 | """Return the float property. |
@@ -687,29 +696,6 @@ def get_property_vector(self, name): |
687 | 696 | except ValueError: |
688 | 697 | return self.get_datamap_property_vector(name) |
689 | 698 |
|
690 | | - def _get_property(self, name, prop_type): |
691 | | - """Verify the type and return the property.""" |
692 | | - # Loop through all entity server classes |
693 | | - for server_class in self.server_classes: |
694 | | - |
695 | | - # Is the name a member of the current server class? |
696 | | - if name not in server_class.properties: |
697 | | - continue |
698 | | - |
699 | | - # Is the type the correct type? |
700 | | - if prop_type != server_class.properties[name].prop_type: |
701 | | - raise TypeError('Property "{0}" is of type {1} not {2}'.format( |
702 | | - name, server_class.properties[name].prop_type, prop_type)) |
703 | | - |
704 | | - # Return the property for the entity |
705 | | - return getattr( |
706 | | - make_object(server_class._properties, self.pointer), name) |
707 | | - |
708 | | - # Raise an error if the property name was not found |
709 | | - raise ValueError( |
710 | | - 'Property "{0}" not found for entity type "{1}"'.format( |
711 | | - name, self.classname)) |
712 | | - |
713 | 699 | def set_property_bool(self, name, value): |
714 | 700 | """Set the boolean property. |
715 | 701 |
|
@@ -744,7 +730,11 @@ def set_property_edict(self, name, value): |
744 | 730 | :param Edict value: |
745 | 731 | The value to set. |
746 | 732 | """ |
747 | | - self._set_property(name, 'Edict', value) |
| 733 | + if not isinstance(value, Edict): |
| 734 | + raise TypeError( |
| 735 | + f'"{value}" of type "{type(value)}" is not a valid Edict.' |
| 736 | + ) |
| 737 | + self.set_property_pointer(name, get_object_pointer(value)) |
748 | 738 |
|
749 | 739 | def set_property_float(self, name, value): |
750 | 740 | """Set the float property. |
@@ -915,38 +905,6 @@ def set_property_vector(self, name, value): |
915 | 905 | except ValueError: |
916 | 906 | self.set_datamap_property_vector(name, value) |
917 | 907 |
|
918 | | - def _set_property(self, name, prop_type, value): |
919 | | - """Verify the type and set the property.""" |
920 | | - # Loop through all entity server classes |
921 | | - for server_class in self.server_classes: |
922 | | - |
923 | | - # Is the name a member of the current server class? |
924 | | - if name not in server_class.properties: |
925 | | - continue |
926 | | - |
927 | | - # Is the type the correct type? |
928 | | - if prop_type != server_class.properties[name].prop_type: |
929 | | - raise TypeError('Property "{0}" is of type {1} not {2}'.format( |
930 | | - name, server_class.properties[name].prop_type, prop_type)) |
931 | | - |
932 | | - # Set the property for the entity |
933 | | - setattr(make_object( |
934 | | - server_class._properties, self.pointer), name, value) |
935 | | - |
936 | | - # Is the property networked? |
937 | | - if server_class.properties[name].networked: |
938 | | - |
939 | | - # Notify the change of state |
940 | | - self.edict.state_changed() |
941 | | - |
942 | | - # No need to go further |
943 | | - return |
944 | | - |
945 | | - # Raise an error if the property name was not found |
946 | | - raise ValueError( |
947 | | - 'Property "{0}" not found for entity type "{1}"'.format( |
948 | | - name, self.classname)) |
949 | | - |
950 | 908 | def delay( |
951 | 909 | self, delay, callback, args=(), kwargs=None, |
952 | 910 | cancel_on_level_end=False): |
|
0 commit comments