Skip to content

Commit d09384f

Browse files
committed
Added 'entity' return_type for EntityIter that returns the BaseEntity instance for the entity.
Removed most of the _return_<type> functions in filters.weapons and replaced them with lambda functions. Added missing __all__ declaration in 2 modules.
1 parent 3cbb878 commit d09384f

File tree

5 files changed

+36
-59
lines changed

5 files changed

+36
-59
lines changed

addons/source-python/packages/source-python/filters/entities.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Source.Python Imports
77
# Entities
88
from entities import EntityGenerator
9+
from entities.entity import BaseEntity
910
from entities.helpers import basehandle_from_edict
1011
from entities.helpers import index_from_edict
1112
from entities.helpers import inthandle_from_edict
@@ -108,5 +109,7 @@ def _is_valid(self, edict):
108109
_EntityIterManagerInstance.register_return_type(
109110
'inthandle', inthandle_from_edict)
110111
_EntityIterManagerInstance.register_return_type('pointer', pointer_from_edict)
112+
_EntityIterManagerInstance.register_return_type(
113+
'entity', lambda edict: BaseEntity(index_from_edict(edict)))
111114
_EntityIterManagerInstance.register_return_type(
112115
'classname', lambda edict: edict.get_class_name())

addons/source-python/packages/source-python/filters/weapons.py

Lines changed: 19 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def iterator():
9696
# =============================================================================
9797
# >> WEAPON TAG CLASSES
9898
# =============================================================================
99-
class __WeaponTagsInstance(dict):
99+
class _WeaponTags(dict):
100100
'''Class used to store weapon tags for the current game'''
101101

102102
def __missing__(self, item):
@@ -108,8 +108,8 @@ def __missing__(self, item):
108108
# Return the instance
109109
return instance
110110

111-
# Get the __WeaponTagsInstance instance
112-
_WeaponTagsInstance = __WeaponTagsInstance()
111+
# Get the _WeaponTags instance
112+
_WeaponTagsInstance = _WeaponTags()
113113

114114

115115
class _Tag(object):
@@ -147,13 +147,8 @@ def _class_weapon_contains_tag(self, weapon):
147147

148148

149149
# =============================================================================
150-
# >> WEAPON EDICT RETURN TYPE FUNCTIONS
150+
# >> WEAPON EDICT RETURN TYPES
151151
# =============================================================================
152-
def _return_edict(edict):
153-
'''Returns the weapon's edict'''
154-
return edict
155-
156-
157152
def _return_instance(edict):
158153
'''Returns the weapon's BaseEntity instance'''
159154
from entities.entity import BaseEntity
@@ -167,63 +162,29 @@ def _return_instance(edict):
167162
'inthandle', inthandle_from_edict)
168163
_WeaponEdictIterManagerInstance.register_return_type(
169164
'pointer', pointer_from_edict)
170-
_WeaponEdictIterManagerInstance.register_return_type('edict', _return_edict)
165+
_WeaponEdictIterManagerInstance.register_return_type(
166+
'edict', lambda edict: edict)
171167
_WeaponEdictIterManagerInstance.register_return_type(
172168
'weapon', _return_instance)
173169

174170

175171
# =============================================================================
176-
# >> WEAPON CLASS RETURN TYPE FUNCTIONS
172+
# >> WEAPON CLASS RETURN TYPES
177173
# =============================================================================
178-
def _return_weapon(weapon):
179-
'''Returns the weapon type's WeaponManager item'''
180-
return weapon
181-
182-
183-
def _return_classname(weapon):
184-
'''Returns the weapon type's classname'''
185-
return weapon.name
186-
187-
188-
def _return_basename(weapon):
189-
'''Returns the weapon type's basename'''
190-
return weapon.basename
191-
192-
193-
def _return_slot(weapon):
194-
'''Returns the weapon type's slot'''
195-
return weapon.slot
196-
197-
198-
def _return_maxammo(weapon):
199-
'''Returns the weapon type's maxammo'''
200-
return weapon.maxammo
201-
202-
203-
def _return_ammoprop(weapon):
204-
'''Returns the weapon type's ammoprop'''
205-
return weapon.ammoprop
206-
207-
208-
def _return_clip(weapon):
209-
'''Returns the weapon type's clip'''
210-
return weapon.clip
211-
212-
213-
def _return_tags(weapon):
214-
'''Returns the weapon type's tags'''
215-
return weapon.tags
216-
217174
# Register the return type functions
218-
_WeaponClassIterManagerInstance.register_return_type('weapon', _return_weapon)
219175
_WeaponClassIterManagerInstance.register_return_type(
220-
'classname', _return_classname)
176+
'weapon', lambda weapon: weapon)
177+
_WeaponClassIterManagerInstance.register_return_type(
178+
'classname', lambda weapon: weapon.name)
179+
_WeaponClassIterManagerInstance.register_return_type(
180+
'basename', lambda weapon: weapon.basename)
181+
_WeaponClassIterManagerInstance.register_return_type(
182+
'slot', lambda weapon: weapon.slot)
183+
_WeaponClassIterManagerInstance.register_return_type(
184+
'maxammo', lambda weapon: weapon.maxammo)
221185
_WeaponClassIterManagerInstance.register_return_type(
222-
'basename', _return_basename)
223-
_WeaponClassIterManagerInstance.register_return_type('slot', _return_slot)
186+
'ammoprop', lambda weapon: weapon.ammoprop)
224187
_WeaponClassIterManagerInstance.register_return_type(
225-
'maxammo', _return_maxammo)
188+
'clip', lambda weapon: weapon.clip)
226189
_WeaponClassIterManagerInstance.register_return_type(
227-
'ammoprop', _return_ammoprop)
228-
_WeaponClassIterManagerInstance.register_return_type('clip', _return_clip)
229-
_WeaponClassIterManagerInstance.register_return_type('tags', _return_tags)
190+
'tags', lambda weapon: weapon.tags)

addons/source-python/packages/source-python/players/weapons/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
except ImportError:
3737

3838
# Set the game's _GameWeapons class to the basic "object" type
39-
_GameWeapons = set()
39+
_GameWeapons = object
4040

4141
# Was no ImportError encountered?
4242
else:

addons/source-python/packages/source-python/players/weapons/projectiles.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ../players/weapons/projectiles.py
22

3+
# =============================================================================
4+
# >> ALL DECLARATION
5+
# =============================================================================
6+
# Set __all__ to an empty list
7+
__all__ = []
8+
39

410
# =============================================================================
511
# >> CLASSES

addons/source-python/packages/source-python/players/weapons/types.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
from entities.helpers import index_from_edict
1111

1212

13+
# =============================================================================
14+
# >> ALL DECLARATION
15+
# =============================================================================
16+
# Set __all__ to an empty list
17+
__all__ = []
18+
19+
1320
# =============================================================================
1421
# >> CLASSES
1522
# =============================================================================

0 commit comments

Comments
 (0)