Skip to content

Commit d34384d

Browse files
committed
Added players.helpers.get_client_language function.
PlayerEntity.language now just uses the imported get_client_language function.
1 parent 7ff1f2a commit d34384d

File tree

7 files changed

+33
-53
lines changed

7 files changed

+33
-53
lines changed

addons/source-python/packages/source-python/players/classes/language/__init__.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@
1111

1212

1313
# =============================================================================
14-
# >> CLASSES
14+
# >> FUNCTIONS
1515
# =============================================================================
16-
class _LanguagePropertyBase(object):
17-
18-
"""Provides a property to get the player's language."""
19-
20-
@property
21-
def language(self):
22-
"""Return the player's language."""
23-
return engine_server.get_client_convar_value(self.index, 'cl_language')
16+
def get_client_language(index):
17+
"""Return the language of the given client."""
18+
return engine_server.get_client_convar_value(index, 'cl_language')

addons/source-python/packages/source-python/players/classes/language/cache.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
from listeners import client_disconnect_listener_manager
1414
from listeners import client_fully_connect_listener_manager
1515
from listeners import on_query_cvar_value_finished_listener_manager
16-
# Players
17-
from players.helpers import edict_from_index
1816

1917

2018
# =============================================================================
@@ -57,6 +55,7 @@ def client_disconnect(self, index):
5755
@staticmethod
5856
def client_fully_connect(index):
5957
"""Query the player's language when they are fully connected."""
58+
from players.helpers import edict_from_index
6059
engine_server.start_query_cvar_value(
6160
edict_from_index(index), 'cl_language')
6261

@@ -70,11 +69,9 @@ def client_fully_connect(index):
7069
_language_cache.client_disconnect)
7170

7271

73-
class _LanguagePropertyCache(object):
74-
75-
"""Provides a property to get the player's cached language."""
76-
77-
@property
78-
def language(self):
79-
"""Return the player's cached language."""
80-
return _language_cache[self.index]
72+
# =============================================================================
73+
# >> FUNCTIONS
74+
# =============================================================================
75+
def get_client_language(index):
76+
"""Return the language of the given client."""
77+
return _language_cache[index]

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# Constants
1616
from constants import MAX_TRACE_LENGTH
1717
# Engines
18-
from engines.server import engine_server
1918
from engines.trace import engine_trace
2019
from engines.trace import ContentMasks
2120
from engines.trace import GameTrace
@@ -29,11 +28,11 @@
2928
# Memory
3029
from memory import Pointer
3130
# Players
32-
from players.helpers import playerinfo_from_index
3331
from players.helpers import address_from_playerinfo
32+
from players.helpers import get_client_language
33+
from players.helpers import playerinfo_from_index
3434
from players.helpers import uniqueid_from_playerinfo
35-
from players.games import _game_classes
36-
from players.games import _game_weapons
35+
from players.games import _GameWeapons
3736
from players.weapons import _PlayerWeapons
3837

3938

@@ -47,7 +46,7 @@
4746
# =============================================================================
4847
# >> CLASSES
4948
# =============================================================================
50-
class PlayerEntity(BaseEntity, _game_classes, _game_weapons, _PlayerWeapons):
49+
class PlayerEntity(BaseEntity, _GameWeapons, _PlayerWeapons):
5150

5251
"""Class used to interact directly with players."""
5352

@@ -123,6 +122,11 @@ def set_team(self, value):
123122
get_team, set_team,
124123
doc="""Property to get/set the player's team.""")
125124

125+
@property
126+
def language(self):
127+
"""Return the player's language."""
128+
return get_client_language(self.index)
129+
126130
def get_trace_ray(self, mask=ContentMasks.ALL, trace_filter=None):
127131
"""Return the player's current trace data."""
128132
# Get the eye location of the player

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,17 @@
2626
# Get the game's module
2727
_game_module = import_module('players.games.{0}'.format(GAME_NAME))
2828

29+
# If the module doesn't exist, set the variable to None
2930
except ImportError:
30-
31-
# Set the variable to None
3231
_game_module = None
3332

34-
# Use try/except to store the game specific weapons
35-
try:
36-
_game_weapons = _game_module._GameWeapons
37-
38-
# If the module doesn't contain the class, use the base class
39-
except AttributeError:
40-
_game_weapons = _base_module._GameWeapons
33+
# Loop through each object to import
34+
for object_name in ('_GameWeapons', 'get_client_language'):
4135

42-
# Use try/except to store the game specific classes
43-
try:
44-
_game_classes = _game_module._GameClasses
36+
# Use try/except to get the game specific object
37+
try:
38+
globals()[object_name] = getattr(_game_module, object_name)
4539

46-
# If the module doesn't contain the class, use the base class
47-
except AttributeError:
48-
_game_classes = _base_module._GameClasses
40+
# If their is no game specific object, use the base object
41+
except AttributeError:
42+
globals()[object_name] = getattr(_base_module, object_name)

addons/source-python/packages/source-python/players/games/base.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
# =============================================================================
66
# >> IMPORTS
77
# =============================================================================
8-
# Source.Python Imports
9-
# Players
10-
from players.classes.language import _LanguagePropertyBase
8+
from players.classes.language import get_client_language
119

1210

1311
# =============================================================================
@@ -16,8 +14,3 @@
1614
class _GameWeapons(object):
1715

1816
"""Base class for game specific weapon functionality."""
19-
20-
21-
class _GameClasses(_LanguagePropertyBase):
22-
23-
"""Base class for game specific functionality."""

addons/source-python/packages/source-python/players/games/csgo.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# =============================================================================
88
# Source.Python Imports
99
# Players
10-
from players.classes.language.cache import _LanguagePropertyCache
10+
from players.classes.language.cache import get_client_language
1111
from players.weapons.projectiles import _HEGrenade
1212
from players.weapons.projectiles import _Flashbang
1313
from players.weapons.projectiles import _SmokeGrenade
@@ -23,8 +23,3 @@ class _GameWeapons(
2323
_HEGrenade, _Flashbang, _SmokeGrenade, _Decoy, _Incendiary, _C4):
2424

2525
"""CS:GO specific player weapon functionality."""
26-
27-
28-
class _GameClasses(_LanguagePropertyCache):
29-
30-
"""CS:GO specific player functionality."""

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from engines.server import engine_server
1111
# Players
1212
from players import PlayerGenerator
13+
from players.games import get_client_language
1314

1415

1516
# =============================================================================
@@ -77,6 +78,7 @@
7778
'edict_from_playerinfo',
7879
'edict_from_pointer',
7980
'edict_from_userid',
81+
'get_client_language',
8082
'index_from_basehandle',
8183
'index_from_edict',
8284
'index_from_inthandle',

0 commit comments

Comments
 (0)