|
4 | 4 | # >> IMPORTS |
5 | 5 | # ============================================================================= |
6 | 6 | # Source.Python Imports |
7 | | -#from Source import Binutils |
8 | 7 | from conversions_c import edict_from_index |
| 8 | +from memory_c import CPointer |
9 | 9 | from public import public |
10 | 10 | # Entities |
11 | 11 | #from entities.functions import EntityFunctions |
@@ -94,55 +94,55 @@ def __getattr__(self, attr): |
94 | 94 | def _get_property(self, item): |
95 | 95 | '''Gets the value of the given property''' |
96 | 96 |
|
97 | | - # Get the property's type |
98 | | - prop_type = self.properties[item].type |
| 97 | + # Get the property so that we don't have to make multiple calls |
| 98 | + prop = self.properties[item] |
99 | 99 |
|
100 | 100 | # Get the property's value |
101 | | - value = getattr(self.edict, 'get_prop_{0}'.format( |
102 | | - prop_type))(self.properties[item].prop) |
| 101 | + value = getattr( |
| 102 | + self.edict, 'get_prop_{0}'.format(prop.type))(prop.prop) |
103 | 103 |
|
104 | 104 | # Is the property a True/False property? |
105 | | - if 'True' in self.properties[item]: |
| 105 | + if 'True' in prop: |
106 | 106 |
|
107 | 107 | # Return if the current value equals the "True" value |
108 | | - return value == self.properties[item]['True'] |
| 108 | + return value == prop['True'] |
109 | 109 |
|
110 | 110 | # Return the value of the property |
111 | 111 | return value |
112 | 112 |
|
113 | 113 | def _get_keyvalue(self, item): |
114 | 114 | '''Gets the value of the given keyvalue''' |
115 | 115 |
|
116 | | - # Get the keyvalue's type |
117 | | - kv_type = self.keyvalues[item].type |
118 | | - |
119 | 116 | # Return the value of the given keyvalue |
120 | | - return getattr(self.edict, 'get_keyvalue_{0}'.format(kv_type))(item) |
| 117 | + return getattr( |
| 118 | + self.edict, 'get_keyvalue_{0}'.format(self.keyvalues[item]))(item) |
121 | 119 |
|
122 | 120 | def _get_offset(self, item): |
123 | 121 | '''Gets the value of the given offset''' |
124 | 122 |
|
125 | | - # Get the offset's type |
126 | | - offset_type = self.offsets[item].type |
| 123 | + # Get the offset so that we don't have to make multiple calls |
| 124 | + offset = self.offsets[item] |
127 | 125 |
|
128 | 126 | # Get the CPointer instance for the entity |
129 | 127 | pointer = CPointer(self.pointer) |
130 | 128 |
|
131 | 129 | # Return the value of the offset |
132 | | - return getattr(pointer, 'get_{0}'.format( |
133 | | - offset_type))(self.offsets[item].offset) |
| 130 | + return getattr(pointer, 'get_{0}'.format(offset.type))(offset.offset) |
134 | 131 |
|
135 | 132 | def _get_function(self, item): |
136 | 133 | '''Calls a dynamic function''' |
137 | 134 |
|
| 135 | + # Get the function so that we don't have to make multiple calls |
| 136 | + function = self.functions[item] |
| 137 | + |
138 | 138 | # Does the entity's pointer need to be added to the arguments? |
139 | | - if self.functions[item].pointer_index != -1: |
| 139 | + if function.pointer_index != -1: |
140 | 140 |
|
141 | 141 | # Set the entity's pointer as the current one |
142 | | - self.functions[item].current_pointer = self.pointer |
| 142 | + function.current_pointer = self.pointer |
143 | 143 |
|
144 | 144 | # Return the pre call function method |
145 | | - return self.functions[item]._pre_call_function |
| 145 | + return function._pre_call_function |
146 | 146 |
|
147 | 147 | def __setattr__(self, attr, value): |
148 | 148 | '''Finds if the attribute is value and sets its value''' |
@@ -194,40 +194,36 @@ def __setattr__(self, attr, value): |
194 | 194 | def _set_property(self, item, value): |
195 | 195 | '''Sets the value of the given propery''' |
196 | 196 |
|
197 | | - # Get the property's type |
198 | | - prop_type = self.properties[item].type |
| 197 | + # Get the property so that we don't have to make multiple calls |
| 198 | + prop = self.properties[item] |
199 | 199 |
|
200 | 200 | # Is the property a True/False property? |
201 | | - if 'True' in self.properties[item]: |
| 201 | + if 'True' in prop: |
202 | 202 |
|
203 | 203 | # Get the exact value to set the property to |
204 | | - value = self.properties[item][str(value)] |
| 204 | + value = prop[str(value)] |
205 | 205 |
|
206 | 206 | # Set the property's value |
207 | | - getattr(prop, 'set_prop_{0}'.format( |
208 | | - prop_type))(self.properties[item].prop, value) |
| 207 | + getattr(self.edict, 'set_prop_{0}'.format(prop.type))(prop.prop, value) |
209 | 208 |
|
210 | 209 | def _set_keyvalue(self, item, value): |
211 | 210 | '''Sets the value of the given keyvalue''' |
212 | 211 |
|
213 | | - # Get the keyvalue's type |
214 | | - kv_type = self.keyvalues[item] |
215 | | - |
216 | 212 | # Set the keyvalue's value |
217 | | - getattr(self.edict, 'set_keyvalue_{0}'.format(kv_type))(item, value) |
| 213 | + getattr(self.edict, 'set_keyvalue_{0}'.format( |
| 214 | + self.keyvalues[item]))(item, value) |
218 | 215 |
|
219 | 216 | def _set_offset(self, item, value): |
220 | 217 | '''Sets the value of the given offset''' |
221 | 218 |
|
222 | | - # Get the offset's type |
223 | | - offset_type = self.offsets[item].type |
| 219 | + # Get the offset so that we don't have to make multiple calls |
| 220 | + offset = self.offsets[item] |
224 | 221 |
|
225 | 222 | # Get the CPointer instance for the entity |
226 | 223 | pointer = CPointer(self.pointer) |
227 | 224 |
|
228 | 225 | # Set the offset's value |
229 | | - getattr(pointer, 'set_{0}'.format( |
230 | | - offset_type))(self.offsets[item].offset, value) |
| 226 | + getattr(pointer, 'set_{0}'.format(offset.type))(offset.offset, value) |
231 | 227 |
|
232 | 228 | def get_color(self): |
233 | 229 | '''Returns a 4 part tuple (RGBA) for the entity's color''' |
|
0 commit comments