-
Notifications
You must be signed in to change notification settings - Fork 37
Add TF2 specific player subclass. Add class names and id's to team data #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# ../players/engines/orangebox/cstrike.py | ||
|
||
"""Provides Team Fortress 2 specific Player based functionality.""" | ||
|
||
# ============================================================================= | ||
# >> IMPORTS | ||
# ============================================================================= | ||
# Source.Python Imports | ||
from . import Player as _Player | ||
from configobj import ConfigObj | ||
from core import GAME_NAME | ||
from paths import SP_DATA_PATH | ||
|
||
# ============================================================================= | ||
# >> CLASSES | ||
# ============================================================================= | ||
class Player(_Player): | ||
caching = True | ||
|
||
# Team | ||
_team_data = ConfigObj(SP_DATA_PATH / 'teams' / GAME_NAME + '.ini', unrepr=True) | ||
|
||
_teams_names = _team_data.get('names') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This mapping is already available as players.teams.teams_by_name and should really just be imported from there rather than queried again from the INI file. |
||
_class_names = _team_data.get('classes') | ||
|
||
@property | ||
def team_name(self): | ||
teams_by_number = dict(zip(self._teams_names.values(), self._teams_names.keys())) | ||
return teams_by_number[self.team] | ||
|
||
@team_name.setter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than having multiples |
||
def team_name(self, team_name): | ||
if team_name not in self._teams_names: | ||
raise ValueError(f"Invalid team_name: {team_name}") | ||
|
||
self.team = self._teams_names[team_name] | ||
|
||
@property | ||
def player_class_name(self): | ||
class_by_number = dict(zip(self._class_names.values(), self._class_names.keys())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redundant to rebuild that mapping every calls, and it should really just be globalized into the |
||
return class_by_number[self.player_class] | ||
|
||
@player_class_name.setter | ||
def player_class_name(self, class_name): | ||
if class_name not in self._class_names: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dictionary here is queried twice (once through v = d.get(k, None)
# If k wasn't in d, let's raise
if v is None:
raise
... This would ensure the dictionary is looked up only once rather than twice, etc. |
||
raise ValueError(f"Invalid class_name: {class_name}") | ||
|
||
# Does this need to be desired_player_class or should there b a setter for desired class? | ||
self.player_class = self._class_names[class_name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to parse that file again here, as it is already parsed into ../players/teams.py.