Skip to content

Commit 815fab4

Browse files
committed
Converted all C++ side conversions functions to use the C++ side naming ie index_from_edict is now IndexFromEdict. The changes do not affect Python side imports.
Fixed all conversions_c functions to use inline. Changed all pointer_from_<type> functions to return a CPointer instance instead of just the memory location. Updated some data files to reflect recent changes in method names. Changed name of a few entities package classes (EntityFunctions, EntityKeyValues, EntityOffset, and EntityProperties). Imports of these have always been by BaseEntity itself, so no real changes for scripters. The new Entity classes now all inherit from EntityAttributes, since much of the functionality of each of the classes was identical.
1 parent 3f1e8a1 commit 815fab4

File tree

12 files changed

+256
-401
lines changed

12 files changed

+256
-401
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
gravity = Float
1+
gravity = float
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
gravity = Float
1+
gravity = float
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[kills]
22
nt = 3760
33
linux = 3780
4-
type = "Int"
4+
type = "int"
55

66
[assists]
77
nt = 3764
88
linux = 3784
9-
type = "Int"
9+
type = "int"
1010

1111
[deaths]
1212
nt = 3768
1313
linux = 3788
14-
type = "Int"
14+
type = "int"
1515

1616
[hitgroup]
1717
nt = 1776
1818
linux = 1800
19-
type = "Int"
19+
type = "int"
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# ../entities/attributes.py
2+
3+
# =============================================================================
4+
# >> IMPORTS
5+
# =============================================================================
6+
# Site-Package Imports
7+
# ConfigObj
8+
from configobj import ConfigObj
9+
10+
# Source.Python Imports
11+
from core import GAME_NAME
12+
from paths import SP_DATA_PATH
13+
14+
15+
# =============================================================================
16+
# >> ALL DECLARATION
17+
# =============================================================================
18+
__all__ = []
19+
20+
21+
# =============================================================================
22+
# >> CLASSES
23+
# =============================================================================
24+
class EntityAttributes(dict):
25+
'''Base Attribute class used to interact with
26+
entity's based off of ini data files.'''
27+
28+
'''Each class that inherits from EntityAttributes
29+
must have the following attributes:
30+
type - used to know which directory within data to get values
31+
unrepr - used to know what to have ConfigObj unrepr set to
32+
instance - used to know which class to use to create the objects
33+
'''
34+
35+
def __missing__(self, entity):
36+
'''Called the first time an entity is added to the dictionary'''
37+
38+
# Get all attributes for the given entity
39+
values = self[entity] = self._retrieve_attributes(entity)
40+
41+
# Return the attributes and their values
42+
return values
43+
44+
def get_game_attributes(self, args):
45+
'''Returns all attributes for the given entities'''
46+
47+
# Create an empty dictionary
48+
values = dict()
49+
50+
# Loop through all given entities
51+
for arg in args:
52+
53+
# Add teh entities to the dictionary
54+
values.update(self[arg])
55+
56+
# Return all attributes for the given entities
57+
return values
58+
59+
def _retrieve_attributes(self, entity):
60+
'''Retrieves all attributes for the given entity'''
61+
62+
# Create an empty dictionary
63+
game_attributes = dict()
64+
65+
# Get the path to the entity's attributes
66+
inifile = SP_DATA_PATH.joinpath(self.type, entity, GAME_NAME + '.ini')
67+
68+
# Does the file exist?
69+
if not inifile.isfile():
70+
71+
# Return the empty dictionary
72+
return game_attributes
73+
74+
# Get the file's contents
75+
ini = ConfigObj(inifile, unrepr=self.unrepr)
76+
77+
# Loop through all items in the file
78+
for key in ini:
79+
80+
# Add the item to the dictionary
81+
game_attributes[key] = self.instance(ini[key])
82+
83+
# Return the dictionary
84+
return game_attributes

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from conversions_c import edict_from_index
99
from public import public
1010
# Entities
11-
#from entities.functions import Functions
12-
from entities.keyvalues import KeyValues
13-
from entities.offsets import Offsets
14-
from entities.properties import Properties
11+
#from entities.functions import EntityFunctions
12+
from entities.keyvalues import EntityKeyValues
13+
from entities.offsets import EntityOffsets
14+
from entities.properties import EntityProperties
1515
#from entities.specials import _EntitySpecials
1616

1717

@@ -328,19 +328,19 @@ def pointer(self):
328328
@property
329329
def properties(self):
330330
'''Returns all properties for all entities'''
331-
return Properties.get_entity_properties(self.entities)
331+
return EntityProperties.get_game_attributes(self.entities)
332332

333333
@property
334334
def keyvalues(self):
335335
'''Returns all keyvalues for all entities'''
336-
return KeyValues.get_entity_keyvalues(self.entities)
336+
return EntityKeyValues.get_game_attributes(self.entities)
337337

338338
@property
339339
def offsets(self):
340340
'''Returns all offsets for all entities'''
341-
return Offsets.get_entity_offsets(self.entities)
341+
return EntityOffsets.get_game_attributes(self.entities)
342342

343343
@property
344344
def functions(self):
345345
'''Returns all dynamic calling functions for all entities'''
346-
return Functions.get_entity_functions(self.entities)
346+
return EntityFunctions.get_game_attributes(self.entities)

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

Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
# =============================================================================
44
# >> IMPORTS
55
# =============================================================================
6-
# Site Package Imports
7-
# ConfigObj
8-
from configobj import ConfigObj
9-
106
# Source.Python Imports
11-
from core import GAME_NAME
12-
from paths import SP_DATA_PATH
137
# DynCall
148
from dyncall.dictionary import SignatureDictionary
9+
# Entities
10+
from entities.attributes import EntityAttributes
1511

1612

1713
# =============================================================================
@@ -21,47 +17,9 @@
2117
__all__ = []
2218

2319

24-
# =============================================================================
25-
# >> GLOBAL VARIABLES
26-
# =============================================================================
27-
# Store the base "functions" path
28-
_basepath = SP_DATA_PATH.joinpath('functions')
29-
30-
3120
# =============================================================================
3221
# >> CLASSES
3322
# =============================================================================
34-
class _Functions(dict):
35-
'''Dictionary that stores all entities with their functions'''
36-
37-
def __missing__(self, item):
38-
'''Called the first time an entity is added to the dictionary'''
39-
40-
# Get all functions for the given entity
41-
value = self[item] = _get_all_entity_functions(item)
42-
43-
# Return the functions
44-
return value
45-
46-
def get_entity_functions(self, args):
47-
'''Returns all functions for the given entities'''
48-
49-
# Create an empty dictionary
50-
values = dict()
51-
52-
# Loop through all given entities
53-
for arg in args:
54-
55-
# Add the entities to the dictionary
56-
values.update(self[arg])
57-
58-
# Return all functions for the given entities
59-
return values
60-
61-
# Get the _Functions instance
62-
Functions = _Functions()
63-
64-
6523
class _FunctionInstance(object):
6624
'''Class used to store a function to be called with
6725
the entity's pointer as the first argument'''
@@ -108,32 +66,12 @@ def _pre_call_function(self, *args):
10866
self.current_pointer = None
10967

11068

111-
# =============================================================================
112-
# >> FUNCTIONS
113-
# =============================================================================
114-
def _get_all_entity_functions(entity):
115-
'''Retrieves all functions for the given entity'''
116-
117-
# Create an empty dictionary to pass
118-
game_functions = {}
119-
120-
# Get the path to the entity's function file
121-
inifile = _basepath.join(entity, GAME_NAME + '.ini')
122-
123-
# Does the file exist?
124-
if not inifile.isfile():
125-
126-
# Return the empty dictionary
127-
return game_functions
128-
129-
# Get the file's contents
130-
ini = ConfigObj(inifile, unrepr=True)
131-
132-
# Loop through all items in the file
133-
for key in ini:
69+
class _EntityFunctions(EntityAttributes):
70+
'''Dictionary that stores all entities with their functions'''
13471

135-
# Add the item to the dictionary
136-
game_functions[key] = _FunctionInstance(ini[key])
72+
type = 'functions'
73+
unrepr = True
74+
instance = _FunctionInstance
13775

138-
# Return the dictionary
139-
return game_functions
76+
# Get the _EntityFunctions instance
77+
EntityFunctions = _EntityFunctions()

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,23 @@
77
from conversions_c import *
88

99

10+
# =============================================================================
11+
# >> PLAYER OBJECT REMOVAL
12+
# =============================================================================
13+
# Loop through all functions imported
14+
for function in dict(globals()):
15+
16+
# Is the current function a "player" based function?
17+
if 'playerinfo' in function or 'userid' in function:
18+
19+
# Remove the function
20+
del globals()[function]
21+
22+
# Remove the function variable
23+
del function
24+
25+
1026
# =============================================================================
1127
# >> ALL DECLARATION
1228
# =============================================================================
13-
__all__ = [x for x in globals() if not 'userid' in x and
14-
not 'playerinfo' in x and not x.startswith('__')]
29+
__all__ = [x for x in globals() if not x.startswith('__')]

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

Lines changed: 8 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
# =============================================================================
44
# >> IMPORTS
55
# =============================================================================
6-
# Site Package Imports
7-
# ConfigObj
8-
from configobj import ConfigObj
9-
106
# Source.Python Imports
11-
from core import GAME_NAME
12-
from paths import SP_DATA_PATH
7+
# Entities
8+
from entities.attributes import EntityAttributes
139

1410

1511
# =============================================================================
@@ -19,73 +15,15 @@
1915
__all__ = []
2016

2117

22-
# =============================================================================
23-
# >> GLOBAL VARIABLES
24-
# =============================================================================
25-
# Store the base "keyvalues" path
26-
_basepath = SP_DATA_PATH.joinpath('keyvalues')
27-
28-
2918
# =============================================================================
3019
# >> CLASSES
3120
# =============================================================================
32-
class _KeyValues(dict):
21+
class _EntityKeyValues(EntityAttributes):
3322
'''Dictionary that stores all entities with their keyvalues'''
3423

35-
def __missing__(self, item):
36-
'''Called the first time an entity is added to the dictionary'''
37-
38-
# Get all keyvalues for the given entity
39-
value = self[item] = _get_all_entity_keyvalues(item)
40-
41-
# Return the keyvalues
42-
return value
43-
44-
def get_entity_keyvalues(self, args):
45-
'''Returns all keyvalues for the given entities'''
46-
47-
# Create an empty dictionary
48-
values = dict()
49-
50-
# Loop through all given entities
51-
for arg in args:
52-
53-
# Add the entities to the dictionary
54-
values.update(self[arg])
55-
56-
# Return all keyvalues for the given entities
57-
return values
58-
59-
# Get the _KeyValues instance
60-
KeyValues = _KeyValues()
61-
62-
63-
# =============================================================================
64-
# >> FUNCTIONS
65-
# =============================================================================
66-
def _get_all_entity_keyvalues(entity):
67-
'''Retrieves all keyvalues for the given entity'''
68-
69-
# Create an empty dictionary to pass
70-
game_keyvalues = {}
71-
72-
# Get the path to the entity's keyvalue file
73-
inifile = _basepath.joinpath(entity, GAME_NAME + '.ini')
74-
75-
# Does the file exist?
76-
if not inifile.isfile():
77-
78-
# Return the empty dictionary
79-
return game_keyvalues
80-
81-
# Get the file's contents
82-
ini = ConfigObj(inifile)
83-
84-
# Loop through all items in the file
85-
for key in ini:
86-
87-
# Add the item to the dictionary
88-
game_keyvalues[key] = ini[key]
24+
type = 'keyvalues'
25+
unrepr = False
26+
instance = staticmethod(lambda value: value)
8927

90-
# Return the dictionary
91-
return game_keyvalues
28+
# Get the _EntityKeyValues instance
29+
EntityKeyValues = _EntityKeyValues()

0 commit comments

Comments
 (0)